Repository navigation
Expand file tree
/
Copy pathlayout_options.py
More file actions
69 lines (62 loc) · 2.07 KB
/
Copy pathlayout_options.py
File metadata and controls
69 lines (62 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Demonstrating layout options: constructor defaults, per-call options,
and element-specific options."""
import json
from pyelk import ELK
# Constructor-level defaults apply to every layout call
elk = ELK(default_layout_options={
"elk.algorithm": "layered",
"elk.direction": "RIGHT",
"elk.spacing.nodeNode": "30",
})
graph = {
"id": "root",
"children": [
{"id": "n1", "width": 30, "height": 30},
{"id": "n2", "width": 30, "height": 30},
{"id": "n3", "width": 30, "height": 30},
],
"edges": [
{"id": "e1", "sources": ["n1"], "targets": ["n2"]},
{"id": "e2", "sources": ["n2"], "targets": ["n3"]},
],
}
# Layout with constructor defaults (RIGHT direction, 30px spacing)
result = elk.layout(graph)
print("With constructor defaults (RIGHT, spacing=30):")
for c in result["children"]:
print(f" {c['id']}: ({c['x']:.1f}, {c['y']:.1f})")
# Per-call options override constructor defaults
graph2 = {
"id": "root",
"children": [
{"id": "n1", "width": 30, "height": 30},
{"id": "n2", "width": 30, "height": 30},
{"id": "n3", "width": 30, "height": 30},
],
"edges": [
{"id": "e1", "sources": ["n1"], "targets": ["n2"]},
{"id": "e2", "sources": ["n2"], "targets": ["n3"]},
],
}
result2 = elk.layout(graph2, layout_options={"elk.direction": "DOWN"})
print("\nWith per-call override (DOWN):")
for c in result2["children"]:
print(f" {c['id']}: ({c['x']:.1f}, {c['y']:.1f})")
# Element-specific options override everything
graph3 = {
"id": "root",
"layoutOptions": {"elk.direction": "DOWN"},
"children": [
{"id": "n1", "width": 30, "height": 30},
{"id": "n2", "width": 30, "height": 30},
{"id": "n3", "width": 30, "height": 30},
],
"edges": [
{"id": "e1", "sources": ["n1"], "targets": ["n2"]},
{"id": "e2", "sources": ["n2"], "targets": ["n3"]},
],
}
result3 = elk.layout(graph3)
print("\nWith element-specific layoutOptions (DOWN):")
for c in result3["children"]:
print(f" {c['id']}: ({c['x']:.1f}, {c['y']:.1f})")