Changed link connection to middle node in block
Hidden node was removed from a block to reduce empty space. Link from previous level is connected to the node in the middle (or the first of two middle nodes when even number of nodes). Added ranksep in config to increase vertical space.
This commit is contained in:
parent
93e2554457
commit
bf788ca544
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -109,26 +110,32 @@ class Graph:
|
|||||||
"label": block.get("label", ""),
|
"label": block.get("label", ""),
|
||||||
"texts": []
|
"texts": []
|
||||||
}
|
}
|
||||||
hidden_node_id = get_id()
|
|
||||||
self.nodes.append({"id": hidden_node_id, "text": "", "hidden": True})
|
|
||||||
new_block["texts"].append(hidden_node_id)
|
|
||||||
|
|
||||||
links = block.get("links", [])
|
#prev_node_id = ""
|
||||||
for link in links:
|
texts_in_block = block.get("texts", [])
|
||||||
|
for i, text in enumerate(texts_in_block):
|
||||||
|
node_id = get_id()
|
||||||
|
|
||||||
|
# Link to middle node
|
||||||
|
if i == math.ceil(len(texts_in_block) / 2) - 1:
|
||||||
|
for link in block.get("links", []):
|
||||||
if link in linker:
|
if link in linker:
|
||||||
self.links.append({"from": linker[link], "to": hidden_node_id, "head": block_id, "hidden": False})
|
self.links.append({"from": linker[link], "to": node_id, "head": block_id, "hidden": False})
|
||||||
del linker[link]
|
del linker[link]
|
||||||
|
|
||||||
for text in block.get("texts", []):
|
|
||||||
node_id = get_id()
|
|
||||||
self.nodes.append({"id": node_id, "text": text.get("text", ""), "hidden": False})
|
self.nodes.append({"id": node_id, "text": text.get("text", ""), "hidden": False})
|
||||||
self.links.append({"from": hidden_node_id, "to": node_id, "head": "", "hidden": True})
|
|
||||||
|
# Chain nodes in block
|
||||||
|
#if prev_node_id:
|
||||||
|
# self.links.append({"from": prev_node_id, "to": node_id, "head": "", "hidden": True})
|
||||||
|
|
||||||
new_block["texts"].append(node_id)
|
new_block["texts"].append(node_id)
|
||||||
|
|
||||||
links = text.get("links", [])
|
for link in text.get("links", []):
|
||||||
for link in links:
|
|
||||||
linker[link] = node_id
|
linker[link] = node_id
|
||||||
|
|
||||||
|
#prev_node_id = node_id
|
||||||
|
|
||||||
self.blocks.append(new_block)
|
self.blocks.append(new_block)
|
||||||
|
|
||||||
def build_dot(self):
|
def build_dot(self):
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
dot:
|
dot:
|
||||||
graph: |
|
graph: |
|
||||||
graph [splines=ortho, nodesep=0.2]
|
graph [splines=ortho, nodesep=0.2, ranksep="0.5 equally"]
|
||||||
//node [color=white]
|
//node [color=white]
|
||||||
//edge [headport=n, tailport=s]
|
//edge [headport=n, tailport=s]
|
||||||
compound=true
|
compound=true
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 138 KiB |
Loading…
x
Reference in New Issue
Block a user