Created README for the project with development plan for implementing graph.py using Graphviz library: - new_graph.py will replace graph.py Changed text order in styrman-blocks.yml for correct ordering of people in the tree at 'label: 8. sukupolvi, Antti Jokisen lapset'.
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import graphviz
|
|
|
|
class Graph:
|
|
def __init__(self):
|
|
self.dot = None
|
|
self.edges = []
|
|
self.node_counter = 0
|
|
|
|
def create_graph(self, config, data):
|
|
# TODO: process config, use for graph init
|
|
self.dot = graphviz.Graph()
|
|
|
|
blocks = data.get('blocks', [])
|
|
for block in blocks:
|
|
self.node_counter += 1
|
|
|
|
# Create node id
|
|
node_id = f'f{self.node_counter}'
|
|
links = block.get('links', [])
|
|
if len(links) > 0:
|
|
node_id = f'{links[0]}'
|
|
|
|
# Create text table for node
|
|
texts = []
|
|
for text in block.get('texts', []):
|
|
person = text.get('text', '')
|
|
link = text.get('links', [])
|
|
if len(link) > 0:
|
|
person = f'<{link[0]}> {person}'
|
|
self.edges.append((link[0], f'{node_id}:{link[0]}'))
|
|
texts.append(person)
|
|
|
|
# Add node
|
|
table = "|".join(texts)
|
|
self.dot.node(node_id, fr'{table}')
|
|
|
|
# Add edges
|
|
self.dot.edges(self.edges)
|
|
|
|
def __str__(self):
|
|
return self.dot.source |