New version of graph.py started
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'.
This commit is contained in:
parent
2966922c61
commit
8b79020fbf
24
README.md
Normal file
24
README.md
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
# Puudot
|
||||
|
||||
## Development
|
||||
|
||||
Start implementing graph.py with Graphviz Python library.
|
||||
|
||||
New architecture for creating dot. No clusters; one node contains one row table with each column for a person.
|
||||
~~~
|
||||
dot.node('<this node id>', fr'{(<node id>) <text>}|...')
|
||||
dot.edge('<this node id>:<other node id>', '<other node id>')
|
||||
~~~
|
||||
|
||||
algorithm:
|
||||
~~~
|
||||
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
|
||||
~~~
|
||||
41
code/new_graph.py
Normal file
41
code/new_graph.py
Normal file
@ -0,0 +1,41 @@
|
||||
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
|
||||
@ -1660,6 +1660,11 @@ blocks:
|
||||
label: 8. sukupolvi, Antti Jokisen lapset
|
||||
links: [54]
|
||||
texts:
|
||||
- text: |
|
||||
Tapio Juhani
|
||||
Jokinen
|
||||
s.20.04.1975
|
||||
k.
|
||||
- text: |
|
||||
Sanna Maaria
|
||||
Jokinen
|
||||
@ -1670,11 +1675,6 @@ blocks:
|
||||
Jääskeläinen
|
||||
s.
|
||||
k.
|
||||
- text: |
|
||||
Tapio Juhani
|
||||
Jokinen
|
||||
s.20.04.1975
|
||||
k.
|
||||
- layer: 8
|
||||
label: 8. sukupolvi, Maija-Liisa Jokisen lapset
|
||||
links: [55]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user