Compare commits

..

No commits in common. "dev/newgraph" and "main" have entirely different histories.

8 changed files with 1573 additions and 7905 deletions

View File

@ -10,19 +10,7 @@ First created in new_graph.py, but will replace graph.py.
Based on current cluster architecture. Based on current cluster architecture.
algorithm: ### RecordGraph
~~~
for block in blocks
create node
if block has link, set link as id
else create id
add texts to node
for text in block save links
create edges from links
~~~
### RecordGraph (experimental)
New architecture for creating dot. No clusters; one node (record) contains one row table with each column for a person. New architecture for creating dot. No clusters; one node (record) contains one row table with each column for a person.
~~~ ~~~

View File

@ -1,48 +1,10 @@
import graphviz import graphviz
import uuid
def get_id():
return "id" + str(uuid.uuid4().hex)
# One cluster of nodes per block # One cluster of nodes per block
class Graph(): class Graph():
def __init__(self): def __init__(self):
self.dot = None self.dot = None
self.links = {}
def create_graph(self, config, data):
self.dot = graphviz.Graph('testgraph', graph_attr={'center': 'true', 'compound': 'true', 'nodesep': '0.2', 'ranksep': '0.5 equally'}, node_attr={'shape': 'plaintext'})
self.dot.format = 'svg'
blocks = data.get('blocks', [])
for block in blocks:
texts = block.get('texts', [])
center_node = int(len(texts) / 2)
cluster_id = 'cluster_' + get_id()
with self.dot.subgraph(name=cluster_id) as cluster:
prev_node_id = ""
for text in texts:
node_id = get_id()
cluster.node(node_id, label=text.get('text', ''))
if prev_node_id:
cluster.edge(prev_node_id, node_id, style='invis', rank='same')
prev_node_id = node_id
for link in text.get('links', []):
self.links[link] = node_id
if center_node == 0:
for link in block.get('links', []):
if link in self.links:
self.dot.edge(self.links[link], node_id, lhead=cluster_id)
del self.links[link]
center_node -= 1
def export_graph(self, out_dir):
self.dot.render(directory=out_dir)
def __str__(self):
return self.dot.source
# One node per block # One node per block

View File

@ -22,7 +22,7 @@ def main():
graph.build_dot() graph.build_dot()
# Test new dot generation # Test new dot generation
new_graph = ng.Graph() new_graph = ng.RecordGraph()
new_graph.create_graph(config, data) new_graph.create_graph(config, data)
#print(new_graph) #print(new_graph)
new_graph.export_graph(DATA_DIR) new_graph.export_graph(DATA_DIR)

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 272 KiB

After

Width:  |  Height:  |  Size: 272 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 289 KiB