From 72200bf3b24e46b56ab7819e090ab1bcd516b807 Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Fri, 27 Oct 2023 17:56:43 -0600 Subject: [PATCH] Added functionality --- clingraph/clingo_utils.py | 25 ++++++++++++++++++++----- examples/family_tree/viz.lp | 2 ++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/clingraph/clingo_utils.py b/clingraph/clingo_utils.py index 01096bc..db85e98 100644 --- a/clingraph/clingo_utils.py +++ b/clingraph/clingo_utils.py @@ -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): @@ -332,6 +338,17 @@ def _get_json(args, stdin): """ +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): """ @@ -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. diff --git a/examples/family_tree/viz.lp b/examples/family_tree/viz.lp index 2240599..7efbd47 100644 --- a/examples/family_tree/viz.lp +++ b/examples/family_tree/viz.lp @@ -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).