diff --git a/mknodes.py b/mknodes.py index e3d4d71..712e478 100755 --- a/mknodes.py +++ b/mknodes.py @@ -2,20 +2,15 @@ """ This script creates the data.js file containing the list of nodes end edges for -the vis.js graph. +the vis.js graph. Just place data.js in the same folder with index.html. """ import json -import networkx -import matplotlib.pyplot as plt from pathlib import Path - -G = networkx.nx.Graph() - - data = '../dokk/data' -edge_properties = [ 'comics_cartoon', 'comics_author', 'ttrpg_character' ] +edge_properties = [ 'comics_cartoon', 'comics_author', 'ttrpg_character', + 'community_project' ] nodes = [] edges = [] @@ -24,8 +19,6 @@ for path in Path(data).glob('**/*.json',): with open(path, 'r') as f: n = json.loads(f.read()) - G.add_node(n['node_id']) - nodes.append({ 'title': n['node_name'] + ('\n' + n['node_description'] if 'node_description' in n else ''), #'color': { 'background': '', 'border': ''}, @@ -41,8 +34,6 @@ for path in Path(data).glob('**/*.json',): n[p] = [ n[p] ] for target in n[p]: - G.add_edge(n['node_id'], target) - edges.append({ 'title': p, 'from': n['node_id'], @@ -50,17 +41,5 @@ for path in Path(data).glob('**/*.json',): 'to': target, }) -""" -pos = networkx.nx.spring_layout(G, k=1, iterations=200, scale=1000) - -for n in nodes: - n['x'] = pos[n['id']][0] - n['y'] = pos[n['id']][1] - -networkx.nx.set_node_attributes(G, pos, 'pos') -networkx.nx.draw(G, pos=pos) -plt.show() -""" - with open('data.js', 'w') as f: f.write('var nodes={};\nvar edges={}'.format(json.dumps(nodes), json.dumps(edges)))