Skip to content

Commit

Permalink
Added functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
susuhahnml committed Oct 27, 2023
1 parent d79d80b commit 72200bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 20 additions & 5 deletions clingraph/clingo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ def color(self, option, opacity=None):
hex_color = f"{hex_color}{o:02d}"
return String(hex_color)

def clinguin_fontname(self):
"""
Gets the font name used in clinguin
"""

return String("Helvetica Neue")



def __getattr__(self, name):
Expand Down Expand Up @@ -332,6 +338,17 @@ def _get_json(args, stdin):
</svg>
"""

def add_svg_interaction_to_string(s):
"""
Adds the svg interaction script to string representation of the svg image
Args:
s [str]: the svg string
"""
s = s.replace("#111111","currentcolor")
s = s[:-8]
s+= SVG_SCRIPT
return s

def add_svg_interaction(paths):
"""
Expand All @@ -347,12 +364,10 @@ def add_svg_interaction(paths):
continue
for path in path_dic.values():
with open(path, 'r', encoding='UTF-8') as f:
lines = f.readlines()
lines = [s.replace("#111111","currentcolor") for s in lines]
lines[-1] = ""
lines+=[s+"\n" for s in SVG_SCRIPT.split("\n")]
s = f.read()
s = add_svg_interaction_to_string(s)
with open(path, 'w', encoding='UTF-8') as f:
f.writelines(lines)
f.write(s)

ADD_IDS_PRG = """
#defined edge/2.
Expand Down
2 changes: 2 additions & 0 deletions examples/family_tree/viz.lp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ related(X,Y):-parent(X,Y).
related(Y,X):-parent(X,Y).
related(X,X):-person(X).

attr(graph,default,fontname,@clinguin_fontname):-node(X).
attr(graph_nodes,default,fontname,@clinguin_fontname):-node(X).
node(X):-person(X).
attr(node,X,label,@stringify(X,true)):-person(X).
attr(node,X,style,"filled"):-node(X).
Expand Down

0 comments on commit 72200bf

Please sign in to comment.