diff --git a/scripts/gen_centered_graph.py b/scripts/gen_centered_graph.py index f39b755..40840b9 100644 --- a/scripts/gen_centered_graph.py +++ b/scripts/gen_centered_graph.py @@ -4,7 +4,7 @@ import copy import tempfile import os -# TODO: Properly render outgouing links + @ops_cache.cache def gen(headline_id, graph): reference_node = headline_id @@ -17,6 +17,7 @@ def gen(headline_id, graph): in_emacs_tree = { reference_node: set(), } + linked_from_internal = set() while new_nodes: new_nodes = False @@ -46,7 +47,11 @@ def gen(headline_id, graph): l for l in v["links"] if l.get('relation') != 'in' ] - + for l in v['links']: + lt = l['target'] + if lt.startswith("id:"): + lt = lt[3:] + linked_from_internal.add(lt) removed.add(k) new_nodes = True @@ -58,12 +63,17 @@ def gen(headline_id, graph): # One more round for the rest, not requiring "in" for k, v in g.items(): + backlinked = False for link in v["links"]: if link["target"].startswith("id:"): link["target"] = link["target"][3:] if link['target'] in in_emacs: centered_graph[k] = v + backlinked = True removed.add(k) + if not backlinked and (k in linked_from_internal): + centered_graph[k] = v + removed.add(k) g = centered_graph @@ -76,20 +86,22 @@ def gen(headline_id, graph): def draw_subgraph(node_id): f.write("subgraph cluster_{} {{\n".format(node_id.replace("-", "_"))) - f.write('URL="./{}.node.html"\n'.format(node_id)) + f.write(' URL="./{}.node.html"\n'.format(node_id)) - f.write("label=\"{}\"\n".format(g[node_id]['title'].replace("\"", "'"))) + f.write(" label=\"{}\"\n".format(g[node_id]['title'].replace("\"", "'"))) f.write("\n") # print("T: {}".format(in_emacs_tree), file=sys.stderr) for k in in_emacs_tree[node_id]: v = g[k] - print("_" + k.replace("-", "_") + "[label=\"" + v["title"].replace("\"", "'") + "\", URL=\"" + k + ".node.html\"];", file=f) if k in in_emacs_tree: draw_subgraph(k) + else: + print(" _" + k.replace("-", "_") + "[label=\"" + v["title"].replace("\"", "'") + "\", URL=\"" + k + ".node.html\"];", file=f) - f.write("\n}") + + f.write("\n}\n") draw_subgraph(reference_node) @@ -98,6 +110,10 @@ def gen(headline_id, graph): print("_" + k.replace("-", "_") + "[label=\"" + v["title"].replace("\"", "'") + "\", URL=\"" + k + ".node.html\"];", file=f) for k, v in g.items(): + link_src = '_' + k.replace("-", "_") + if k in in_emacs_tree: + link_src = 'cluster_{}'.format(k.replace("-", "_")) + for link in v["links"]: if link["target"].startswith("id:"): link["target"] = link["target"][3:] @@ -112,7 +128,7 @@ def gen(headline_id, graph): t = 'cluster_{}'.format(link['target'].replace("-", "_")) else: t = "_" + link["target"].replace("-", "_") - print("_" + k.replace("-", "_") + "->" + t, file=f) + print(link_src + "->" + t, file=f) f.write('}\n') f.flush()