Skip to content

Commit c4c509a

Browse files
committed
rename main.py to app.py
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent 1f1f0b0 commit c4c509a

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/power_grid_model_ds/_core/visualizer/main.py renamed to src/power_grid_model_ds/_core/visualizer/app.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,11 @@ def visualize(grid: Grid, debug: bool = False, port: int = 8050) -> None:
4444
- "grid": A layout that places the nodes in a grid matrix.
4545
- "cose": A layout that uses the CompoundSpring Embedder algorithm (force-directed layout)
4646
"""
47-
columns_store = _get_columns_store(grid)
48-
layout = _get_layout(grid.node)
49-
elements = parse_node_array(grid.node) + parse_branches(grid)
50-
cytoscape_html = get_cytoscape_html(layout, elements)
5147

5248
app = Dash(
5349
external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP, MDBOOTSTRAP, FONT_AWESOME, GOOGLE_FONTS]
5450
)
55-
app.layout = html.Div(
56-
[
57-
columns_store,
58-
HEADER_HTML,
59-
html.Hr(style={"border-color": "white", "margin": "0"}),
60-
cytoscape_html,
61-
SELECTION_OUTPUT_HTML,
62-
],
63-
)
51+
app.layout = get_app_layout(grid)
6452
app.run(debug=debug, port=port)
6553

6654

@@ -77,8 +65,26 @@ def _get_columns_store(grid: Grid) -> dcc.Store:
7765
)
7866

7967

80-
def _get_layout(nodes: NodeArray) -> str:
81-
"""Determine the layout"""
68+
def get_app_layout(grid: Grid) -> html.Div:
69+
"""Get the app layout."""
70+
columns_store = _get_columns_store(grid)
71+
graph_layout = _get_graph_layout(grid.node)
72+
elements = parse_node_array(grid.node) + parse_branches(grid)
73+
cytoscape_html = get_cytoscape_html(graph_layout, elements)
74+
75+
return html.Div(
76+
[
77+
columns_store,
78+
HEADER_HTML,
79+
html.Hr(style={"border-color": "white", "margin": "0"}),
80+
cytoscape_html,
81+
SELECTION_OUTPUT_HTML,
82+
],
83+
)
84+
85+
86+
def _get_graph_layout(nodes: NodeArray) -> str:
87+
"""Determine the graph layout"""
8288
if "x" in nodes.columns and "y" in nodes.columns:
8389
return "preset"
8490
return "breadthfirst"

src/power_grid_model_ds/visualizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55
try:
6-
from power_grid_model_ds._core.visualizer.main import visualize
6+
from power_grid_model_ds._core.visualizer.app import visualize
77
except ImportError as error:
88
raise ImportError(
99
"Missing dependencies for visualizer: install with 'pip install power-grid-model-ds[visualizer]'"

tests/integration/visualizer_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import dataclass
66

77
from power_grid_model_ds import Grid
8-
from power_grid_model_ds._core.visualizer.main import visualize
8+
from power_grid_model_ds._core.visualizer.app import visualize
99
from power_grid_model_ds.generators import RadialGridGenerator
1010
from tests.unit.visualizer.test_parsers import CoordinatedNodeArray
1111

tests/unit/visualizer/test_parsers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
65
import numpy as np
76
from numpy.typing import NDArray
87

0 commit comments

Comments
 (0)