GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dash-flows/examples/12_elk_layouts.py at main · pip-install-python/dash-flows

Expand file tree

/

12_elk_layouts.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
158 lines (143 loc) · 5.55 KB
/

12_elk_layouts.py

Copy path

File metadata and controls

158 lines (143 loc) · 5.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
Example 12: ELK Automatic Layouts
=================================
This example demonstrates automatic graph layouts using ELK:
- Layered (hierarchical) layout
- Force-directed layout
- Radial layout
- Different layout directions
"""
import dash
from dash import html, Input, Output, State, callback
import dash_flows
import dash_mantine_components as dmc
import json
app = dash.Dash(__name__)
# Create a more complex graph to show layout differences
initial_nodes = [
{"id": "1", "type": "input", "data": {"label": "Start"}, "position": {"x": 0, "y": 0}},
{"id": "2", "type": "default", "data": {"label": "Step A"}, "position": {"x": 0, "y": 0}},
{"id": "3", "type": "default", "data": {"label": "Step B"}, "position": {"x": 0, "y": 0}},
{"id": "4", "type": "default", "data": {"label": "Step C"}, "position": {"x": 0, "y": 0}},
{"id": "5", "type": "default", "data": {"label": "Step D"}, "position": {"x": 0, "y": 0}},
{"id": "6", "type": "default", "data": {"label": "Step E"}, "position": {"x": 0, "y": 0}},
{"id": "7", "type": "default", "data": {"label": "Step F"}, "position": {"x": 0, "y": 0}},
{"id": "8", "type": "output", "data": {"label": "End"}, "position": {"x": 0, "y": 0}},
]
initial_edges = [
{"id": "e1-2", "source": "1", "target": "2"},
{"id": "e1-3", "source": "1", "target": "3"},
{"id": "e2-4", "source": "2", "target": "4"},
{"id": "e2-5", "source": "2", "target": "5"},
{"id": "e3-5", "source": "3", "target": "5"},
{"id": "e3-6", "source": "3", "target": "6"},
{"id": "e4-7", "source": "4", "target": "7"},
{"id": "e5-7", "source": "5", "target": "7"},
{"id": "e6-7", "source": "6", "target": "7"},
{"id": "e7-8", "source": "7", "target": "8"},
]
layout_presets = {
"layered-down": {
"elk.algorithm": "layered",
"elk.direction": "DOWN",
"elk.spacing.nodeNode": 50,
"elk.layered.spacing.nodeNodeBetweenLayers": 80,
},
"layered-right": {
"elk.algorithm": "layered",
"elk.direction": "RIGHT",
"elk.spacing.nodeNode": 50,
"elk.layered.spacing.nodeNodeBetweenLayers": 120,
},
"layered-up": {
"elk.algorithm": "layered",
"elk.direction": "UP",
"elk.spacing.nodeNode": 50,
},
"layered-left": {
"elk.algorithm": "layered",
"elk.direction": "LEFT",
"elk.spacing.nodeNode": 50,
},
"force": {
"elk.algorithm": "org.eclipse.elk.force",
"elk.force.iterations": 300,
"elk.spacing.nodeNode": 80,
},
"radial": {
"elk.algorithm": "org.eclipse.elk.radial",
"elk.radial.radius": 150,
},
"stress": {
"elk.algorithm": "org.eclipse.elk.stress",
"elk.spacing.nodeNode": 100,
},
}
app.layout = dmc.MantineProvider([
html.H1("ELK Automatic Layouts Example"),
html.P("Apply different automatic layout algorithms to arrange nodes."),
dmc.Group([
dmc.Select(
id="layout-select",
label="Select Layout Algorithm",
data=[
{"value": "layered-down", "label": "Layered (Top to Bottom)"},
{"value": "layered-right", "label": "Layered (Left to Right)"},
{"value": "layered-up", "label": "Layered (Bottom to Top)"},
{"value": "layered-left", "label": "Layered (Right to Left)"},
{"value": "force", "label": "Force-Directed"},
{"value": "radial", "label": "Radial"},
{"value": "stress", "label": "Stress"},
],
value="layered-down",
style={"width": 250},
),
dmc.Button("Apply Layout", id="apply-layout-btn", variant="filled"),
dmc.Button("Reset Positions", id="reset-btn", variant="outline"),
], style={"marginBottom": 20}),
dash_flows.DashFlows(
id="elk-flow",
nodes=initial_nodes,
edges=initial_edges,
style={"height": "500px", "border": "1px solid #ddd"},
fitView=True,
showControls=True,
showMiniMap=True,
layoutOptions=json.dumps(layout_presets["layered-down"]),
),
dmc.Space(h=20),
dmc.Paper([
dmc.Text("Current Layout Options:", fw=600),
html.Pre(id="layout-options-display", style={"fontSize": "11px"}),
], p="md", withBorder=True),
dmc.Space(h=20),
dmc.Alert([
dmc.Text("About ELK Layouts:", fw=600),
dmc.List([
dmc.ListItem([dmc.Text("Layered", fw=600), ": Best for hierarchical/directed graphs. Supports multiple directions."]),
dmc.ListItem([dmc.Text("Force-Directed", fw=600), ": Simulates physical forces for organic layouts."]),
dmc.ListItem([dmc.Text("Radial", fw=600), ": Arranges nodes in concentric circles from a root."]),
dmc.ListItem([dmc.Text("Stress", fw=600), ": Minimizes stress in edge lengths for balanced layouts."]),
], size="sm"),
], color="gray", variant="light"),
])
@callback(
Output("elk-flow", "layoutOptions"),
Output("layout-options-display", "children"),
Input("apply-layout-btn", "n_clicks"),
State("layout-select", "value"),
prevent_initial_call=True,
)
def apply_layout(n_clicks, layout_type):
options = layout_presets.get(layout_type, layout_presets["layered-down"])
return json.dumps(options), json.dumps(options, indent=2)
@callback(
Output("elk-flow", "nodes"),
Input("reset-btn", "n_clicks"),
prevent_initial_call=True,
)
def reset_positions(n_clicks):
# Reset to initial scattered positions
return initial_nodes
if __name__ == "__main__":
app.run(debug=True, port=8063)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.