Skip to content

Commit b19ffa8

Browse files
committed
Lots of styling
1 parent 78fd55f commit b19ffa8

File tree

6 files changed

+80
-21
lines changed

6 files changed

+80
-21
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
BACKGROUND_COLOR = "#707070"
21

2+
YELLOW = "#facc37"
33
CYTO_COLORS = {
4-
"line": "#facc37",
4+
"line": YELLOW,
55
"link": "green",
66
"transformer": "#4290f5",
7-
"node": "#facc37",
7+
"node": YELLOW,
88
"selected": "#e28743",
99
"selected_transformer": "#0349a3",
1010
"substation_node": "purple",
1111
"open_branch": "#c9c9c9",
1212
"highlighted": "#a10000",
1313
}
14+
BACKGROUND_COLOR = "#555555"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
LayoutOptions = Literal["", "random", "circle", "concentric", "grid", "cose", "breadthfirst", "preset"]
1010

1111
_CYTO_INNER_STYLE = {"width": "100%", "height": "100%", "background-color": BACKGROUND_COLOR}
12-
_CYTO_OUTER_STYLE = {"height": "80vh", "border": "thin lightgrey solid", "margin": "0 5px 0 5px"}
12+
_CYTO_OUTER_STYLE = {"height": "75vh"}
1313

1414

1515
def get_cytoscape_html(layout: LayoutOptions, elements: list[dict[str, Any]]) -> html.Div:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import dash_bootstrap_components as dbc
2+
from dash import html
3+
4+
from power_grid_model_ds._core.visualizer.layout.colors import BACKGROUND_COLOR
5+
from power_grid_model_ds._core.visualizer.layout.legenda import LEGENDA_HTML
6+
from power_grid_model_ds._core.visualizer.layout.search_form import SEARCH_FORM_HTML
7+
8+
9+
HEADER_HTML = dbc.Row(
10+
[
11+
dbc.Col(LEGENDA_HTML, className="d-flex align-items-center", style={"margin": "0 10px"}),
12+
dbc.Col(
13+
dbc.Card(SEARCH_FORM_HTML, style={"background-color": "#555555", "color": "white", "border": "none", "border-radius": 0}),
14+
className="d-flex justify-content-center align-items-center"
15+
),
16+
dbc.Col(
17+
# Right column - empty or for future controls
18+
html.Div(),
19+
className="d-flex justify-content-end align-items-center"
20+
),
21+
],
22+
style={"background-color": BACKGROUND_COLOR},
23+
24+
25+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from dash import html
2+
3+
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
4+
5+
_TEST_SHADOW = "0 0 5px #000"
6+
7+
_NODE_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["node"], "text-shadow": _TEST_SHADOW}
8+
_SUBSTATION_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["substation_node"], "text-shadow": _TEST_SHADOW}
9+
_LINE_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["line"], "text-shadow": _TEST_SHADOW}
10+
_LINK_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["link"], "text-shadow": _TEST_SHADOW}
11+
_TRANSFORMER_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["transformer"], "text-shadow": _TEST_SHADOW}
12+
_OPEN_BRANCH_ICON_STYLE = {"font-size": "2.5em", "margin": "0 10px", "color": CYTO_COLORS["open_branch"], "text-shadow": _TEST_SHADOW}
13+
LEGENDA_HTML = html.Div(
14+
[
15+
html.I(className="fas fa-circle", style=_NODE_ICON_STYLE),
16+
html.I(className="fas fa-diamond", style=_SUBSTATION_ICON_STYLE),
17+
html.I(className="fas fa-arrow-right-long", style=_LINE_ICON_STYLE),
18+
html.I(className="fas fa-arrow-right-long", style=_LINK_ICON_STYLE),
19+
html.I(className="fas fa-arrow-right-long", style=_TRANSFORMER_ICON_STYLE),
20+
html.I(className="fas fas fa-ellipsis", style=_OPEN_BRANCH_ICON_STYLE),
21+
],
22+
)
23+
24+
25+
# <i class="fas fa-ellipsis"></i>
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import dash_bootstrap_components as dbc
22
from dash import html
33

4+
_SPAN_TEXT_STYLE = {"margin": "8px", "font-weight": "bold"}
5+
_INPUT_STYLE = {"width": "150px", "display": "inline-block"}
46
# Create your form components
5-
group_input = dbc.Select(
7+
GROUP_INPUT = dbc.Select(
68
id="search-form-group-input",
79
options=[
810
{"label": "node", "value": "node"},
@@ -12,24 +14,24 @@
1214
{"label": "branch", "value": "branch"},
1315
],
1416
value="node", # Default value
15-
style={"width": "150px", "display": "inline-block"}
17+
style=_INPUT_STYLE
1618
)
1719

18-
column_input = dbc.Select(
20+
COLUMN_INPUT = dbc.Select(
1921
id="search-form-column-input",
2022
options=[{"label": "id", "value": "id"}],
2123
value="id", # Default value
22-
style={"width": "150px", "display": "inline-block"}
24+
style=_INPUT_STYLE
2325
)
2426

25-
value_input = dbc.Input(
27+
VALUE_INPUT = dbc.Input(
2628
id="search-form-value-input",
2729
placeholder="Enter value",
2830
type="text",
29-
style={"width": "150px", "display": "inline-block"}
31+
style=_INPUT_STYLE
3032
)
3133

32-
operator_input = dbc.Select(
34+
OPERATOR_INPUT = dbc.Select(
3335
id="search-form-operator-input",
3436
options=[
3537
{"label": "=", "value": "="},
@@ -45,12 +47,12 @@
4547
# Arrange as a sentence
4648
SEARCH_FORM_HTML = html.Div(
4749
[
48-
html.Span("Search ", className="mr-2", style={"margin-right": "8px"}),
49-
group_input,
50-
html.Span(" with ", className="mx-2", style={"margin": "0 8px"}),
51-
column_input,
52-
operator_input,
53-
value_input,
50+
html.Span("Search ", className="mr-2", style=_SPAN_TEXT_STYLE),
51+
GROUP_INPUT,
52+
html.Span(" with ", className="mx-2", style=_SPAN_TEXT_STYLE),
53+
COLUMN_INPUT,
54+
OPERATOR_INPUT,
55+
VALUE_INPUT,
5456
],
5557
style={
5658
"display": "flex",
@@ -61,3 +63,4 @@
6163
"width": "100%" # Ensures the container takes full width
6264
}
6365
)
66+

src/power_grid_model_ds/_core/visualizer/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import dash_bootstrap_components as dbc
22
from dash import Dash, dcc, html
3+
from dash_bootstrap_components.icons import FONT_AWESOME
34

45
from power_grid_model_ds import Grid
56
from power_grid_model_ds._core.visualizer.callbacks import ( # noqa: F401 # pylint: disable=unused-import
67
element_selection,
78
search_form,
89
)
910
from power_grid_model_ds._core.visualizer.layout.cytoscape import LayoutOptions, get_cytoscape_html
10-
from power_grid_model_ds._core.visualizer.layout.search_form import SEARCH_FORM_HTML
11+
from power_grid_model_ds._core.visualizer.layout.header import HEADER_HTML
1112
from power_grid_model_ds._core.visualizer.layout.selection_output import SELECTION_OUTPUT_HTML
1213
from power_grid_model_ds._core.visualizer.parsers import parse_branches, parse_node_array
1314
from power_grid_model_ds.arrays import NodeArray
1415

16+
GOOGLE_FONTS = "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
17+
MDBOOTSTRAP = "https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/8.2.0/mdb.min.css"
18+
1519

1620
def visualize(grid: Grid, layout: LayoutOptions = "", debug: bool = False):
1721
"""Visualize the Grid.
@@ -39,14 +43,15 @@ def visualize(grid: Grid, layout: LayoutOptions = "", debug: bool = False):
3943
elements = parse_node_array(grid.node) + parse_branches(grid)
4044
cytoscape_html = get_cytoscape_html(layout, elements)
4145

42-
app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
46+
app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP, MDBOOTSTRAP, FONT_AWESOME, GOOGLE_FONTS])
4347
app.layout = html.Div(
4448
[
4549
columns_store,
46-
SEARCH_FORM_HTML,
50+
HEADER_HTML,
4751
cytoscape_html,
4852
SELECTION_OUTPUT_HTML,
49-
]
53+
],
54+
5055
)
5156
app.run(debug=debug)
5257

0 commit comments

Comments
 (0)