Skip to content

Commit cf9f852

Browse files
committed
Rewrite code and apply some suggestions from review
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent 102ab2b commit cf9f852

File tree

10 files changed

+103
-108
lines changed

10 files changed

+103
-108
lines changed

src/power_grid_model_ds/_core/visualizer/callbacks/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from dash import Input, Output, State, callback
77
from dash.exceptions import PreventUpdate
88

9-
from power_grid_model_ds._core.visualizer.layout.cytoscape_styling import BRANCH_WIDTH, NODE_SIZE, STYLESHEET
9+
from power_grid_model_ds._core.visualizer.layout.cytoscape_styling import BRANCH_WIDTH, NODE_SIZE
10+
from power_grid_model_ds._core.visualizer.typing import STYLESHEET
1011

1112

1213
@callback(

src/power_grid_model_ds/_core/visualizer/callbacks/header.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import dash
66
from dash import Input, Output, callback
77

8-
from power_grid_model_ds._core.visualizer.layout.header import CONFIG_DIV, SEARCH_DIV
9-
from power_grid_model_ds._core.visualizer.layout.legenda import LEGENDA_HTML
8+
from power_grid_model_ds._core.visualizer.layout.header import CONFIG_DIV, LEGENDA_DIV, SEARCH_DIV
109

1110

1211
@callback(
@@ -21,10 +20,10 @@ def update_right_col(_btn1, _btn2, _btn3):
2120
"""Update the right column content based on the button clicked."""
2221
ctx = dash.callback_context
2322
if not ctx.triggered:
24-
return LEGENDA_HTML
23+
return LEGENDA_DIV
2524
button_id = ctx.triggered[0]["prop_id"].split(".")[0]
2625
button_map = {
27-
"btn-legend": LEGENDA_HTML,
26+
"btn-legend": LEGENDA_DIV,
2827
"btn-search": SEARCH_DIV,
2928
"btn-config": CONFIG_DIV,
3029
}

src/power_grid_model_ds/_core/visualizer/callbacks/search_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dash.exceptions import PreventUpdate
77

88
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
9-
from power_grid_model_ds._core.visualizer.layout.cytoscape_styling import STYLESHEET
9+
from power_grid_model_ds._core.visualizer.typing import STYLESHEET
1010

1111

1212
@callback(

src/power_grid_model_ds/_core/visualizer/layout/cytoscape_styling.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44

55
"""Contains selectors for the Cytoscape stylesheet."""
66

7-
from typing import Any
8-
97
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
108

11-
STYLESHEET = list[dict[str, Any]]
12-
13-
149
NODE_SIZE = 100
1510
BRANCH_WIDTH = 10
1611

src/power_grid_model_ds/_core/visualizer/layout/header.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@
55
import dash_bootstrap_components as dbc
66
from dash import html
77

8-
from power_grid_model_ds._core.visualizer.layout.cytoscape_config import LAYOUT_DROPDOWN_HTML, SCALE_INPUTS
9-
from power_grid_model_ds._core.visualizer.layout.legenda import LEGENDA_HTML
10-
from power_grid_model_ds._core.visualizer.layout.search_form import SEARCH_FORM_HTML
8+
from power_grid_model_ds._core.visualizer.layout.header_config import CONFIG_ELEMENTS
9+
from power_grid_model_ds._core.visualizer.layout.header_legenda import LEGENDA_ELEMENTS, LEGENDA_STYLE
10+
from power_grid_model_ds._core.visualizer.layout.header_search import SEARCH_ELEMENTS
11+
12+
_CONTENT_COLUMN_STYLE = {
13+
"display": "flex",
14+
"align-items": "center",
15+
"width": "100%",
16+
}
17+
18+
19+
CONFIG_DIV = html.Div(CONFIG_ELEMENTS, style=_CONTENT_COLUMN_STYLE | {"justify-content": "space-between"})
20+
SEARCH_DIV = html.Div(SEARCH_ELEMENTS, style=_CONTENT_COLUMN_STYLE | {"justify-content": "center"})
21+
LEGENDA_DIV = html.Div(LEGENDA_ELEMENTS, style=_CONTENT_COLUMN_STYLE | LEGENDA_STYLE)
1122

12-
SHOW_ARROWS_CHECKBOX = dbc.Checkbox(
13-
id="show-arrows",
14-
label="Show arrows",
15-
value=True,
16-
className="me-2",
17-
label_style={"color": "white"},
18-
style={"margin-top": "10px"},
19-
)
20-
CONFIG_DIV = html.Div(
21-
SCALE_INPUTS + LAYOUT_DROPDOWN_HTML + [SHOW_ARROWS_CHECKBOX],
22-
className="d-flex justify-content-end align-items-center",
23-
)
24-
SEARCH_DIV = html.Div(SEARCH_FORM_HTML)
2523

2624
HEADER_HTML = dbc.Row(
2725
[
@@ -40,12 +38,14 @@
4038
},
4139
),
4240
dbc.Col(
43-
html.Div([LEGENDA_HTML, SEARCH_DIV, CONFIG_DIV], id="right-col-content", className="text-end"),
41+
[LEGENDA_DIV, SEARCH_DIV, CONFIG_DIV],
42+
id="right-col-content",
4443
width=7,
4544
style={
4645
"display": "flex",
4746
"align-items": "center",
48-
"justify-content": "center",
47+
"justify-content": "space-between",
48+
# "width": "100%",
4949
},
5050
),
5151
],
@@ -55,7 +55,7 @@
5555
"padding": "1rem 0",
5656
"margin": 0,
5757
"height": "90px",
58+
"width": "100%",
5859
},
59-
className="g-0",
6060
align="center",
6161
)

src/power_grid_model_ds/_core/visualizer/layout/cytoscape_config.py renamed to src/power_grid_model_ds/_core/visualizer/layout/header_config.py

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

5+
import dash_bootstrap_components as dbc
56
from dash import dcc, html
67

78
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
@@ -32,23 +33,28 @@
3233
),
3334
]
3435

35-
SCALE_INPUTS = [
36-
html.Div(
37-
NODE_SCALE_HTML + EDGE_SCALE_HTML,
38-
style={"margin": "0 20px 0 10px"},
36+
_SCALING_DIV = html.Div(NODE_SCALE_HTML + EDGE_SCALE_HTML, style={"margin": "0 20px 0 10px"})
37+
38+
39+
_LAYOUT_DROPDOWN = html.Div(
40+
dcc.Dropdown(
41+
id="dropdown-update-layout",
42+
placeholder="Select layout",
43+
value="breadthfirst",
44+
clearable=False,
45+
options=[{"label": name.capitalize(), "value": name} for name in LAYOUT_OPTIONS],
46+
style={"width": "200px"},
3947
),
40-
]
48+
style={"margin": "0 20px 0 10px", "color": "black"},
49+
)
4150

42-
LAYOUT_DROPDOWN_HTML = [
43-
html.Div(
44-
dcc.Dropdown(
45-
id="dropdown-update-layout",
46-
placeholder="Select layout",
47-
value="breadthfirst",
48-
clearable=False,
49-
options=[{"label": name.capitalize(), "value": name} for name in LAYOUT_OPTIONS],
50-
style={"width": "200px"},
51-
),
52-
style={"margin": "0 20px 0 10px", "color": "black"},
53-
)
54-
]
51+
52+
_ARROWS_CHECKBOX = dbc.Checkbox(
53+
id="show-arrows",
54+
label="Show arrows",
55+
value=True,
56+
label_style={"color": "white"},
57+
style={"margin-top": "10px"},
58+
)
59+
60+
CONFIG_ELEMENTS = [_LAYOUT_DROPDOWN, _ARROWS_CHECKBOX, _SCALING_DIV]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
import dash_bootstrap_components as dbc
6+
from dash import html
7+
8+
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
9+
10+
_MARGIN = "0 10px"
11+
12+
LEGENDA_STYLE = {"margin": _MARGIN, "text-shadow": "0 0 5px #000", "justify-content": "center"}
13+
14+
_FONT_SIZE = "2.5em"
15+
16+
NODE_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["node"]}
17+
_SUBSTATION_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["substation_node"]}
18+
_LINE_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["line"]}
19+
_LINK_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["link"]}
20+
_TRANSFORMER_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["transformer"]}
21+
_OPEN_BRANCH_ICON_STYLE = {"font-size": _FONT_SIZE, "margin": _MARGIN, "color": CYTO_COLORS["open_branch"]}
22+
LEGENDA_ELEMENTS = [
23+
html.I(className="fas fa-circle", id="node-icon", style=NODE_ICON_STYLE),
24+
dbc.Tooltip("Node", target="node-icon", placement="bottom"),
25+
html.I(className="fas fa-diamond", id="substation-icon", style=_SUBSTATION_ICON_STYLE),
26+
dbc.Tooltip("Substation", target="substation-icon", placement="bottom"),
27+
html.I(className="fas fa-arrow-right-long", id="line-icon", style=_LINE_ICON_STYLE),
28+
dbc.Tooltip("Line", target="line-icon", placement="bottom"),
29+
html.I(className="fas fa-arrow-right-long", id="transformer-icon", style=_TRANSFORMER_ICON_STYLE),
30+
dbc.Tooltip("Transformer", target="transformer-icon", placement="bottom"),
31+
html.I(className="fas fa-arrow-right-long", id="link-icon", style=_LINK_ICON_STYLE),
32+
dbc.Tooltip("Link", target="link-icon", placement="bottom"),
33+
html.I(className="fas fa-ellipsis", id="open-branch-icon", style=_OPEN_BRANCH_ICON_STYLE),
34+
dbc.Tooltip("Open Branch", target="open-branch-icon", placement="bottom"),
35+
]

src/power_grid_model_ds/_core/visualizer/layout/search_form.py renamed to src/power_grid_model_ds/_core/visualizer/layout/header_search.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,15 @@
4444

4545

4646
# Arrange as a sentence
47-
SEARCH_FORM_HTML = html.Div(
48-
[
49-
html.Span("Search ", style=SPAN_TEXT_STYLE),
50-
GROUP_INPUT,
51-
html.Span(" with ", className="mx-2", style=SPAN_TEXT_STYLE),
52-
COLUMN_INPUT,
53-
OPERATOR_INPUT,
54-
VALUE_INPUT,
55-
],
56-
style={
57-
"display": "flex",
58-
"align-items": "center",
59-
"justify-content": "center", # Centers items horizontally
60-
"padding": "10px",
61-
"margin": "0 auto", # Centers the container itself
62-
"width": "100%", # Ensures the container takes full width
63-
},
64-
)
47+
SEARCH_ELEMENTS = [
48+
html.Div(
49+
[
50+
html.Span("Search ", style=SPAN_TEXT_STYLE),
51+
GROUP_INPUT,
52+
html.Span(" with ", style=SPAN_TEXT_STYLE),
53+
COLUMN_INPUT,
54+
OPERATOR_INPUT,
55+
VALUE_INPUT,
56+
]
57+
)
58+
]

src/power_grid_model_ds/_core/visualizer/layout/legenda.py

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
from typing import Any
6+
7+
STYLESHEET = list[dict[str, Any]]

0 commit comments

Comments
 (0)