Skip to content

Commit fb3aee2

Browse files
committed
search form on one sentence
1 parent 0520977 commit fb3aee2

File tree

3 files changed

+53
-55
lines changed

3 files changed

+53
-55
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dash import Input, Output, State, callback
22

3+
from power_grid_model_ds._core.visualizer.layout.colors import CYTO_COLORS
34
from power_grid_model_ds._core.visualizer.layout.cytoscape_styling import DEFAULT_STYLESHEET
45

56

@@ -15,17 +16,23 @@ def search_element(group, column, value):
1516
return DEFAULT_STYLESHEET
1617

1718
# Determine if we're working with a node or an edge type
18-
is_node = group == "node"
19-
style_property = "background-color" if is_node else "line-color"
19+
if group == "node":
20+
style = {
21+
"background-color": CYTO_COLORS["highlighted"],
22+
"text-background-color": CYTO_COLORS["highlighted"],
23+
}
24+
else:
25+
style = {"line-color": CYTO_COLORS["highlighted"]}
2026

2127
# Create selectors that match both the group type and the specific value
2228
new_style = {
2329
"selector": f'[{column} = {str(value)}], [{column} = "{value}"]',
24-
"style": {style_property: "red"},
30+
"style": style,
2531
}
2632
return DEFAULT_STYLESHEET + [new_style]
2733

2834

35+
2936
@callback(
3037
Output("search-form-column-input", "options"),
3138
Output("search-form-column-input", "value"),
@@ -42,15 +49,3 @@ def update_column_options(selected_group, store_data):
4249
default_value = columns[0] if columns else "id"
4350

4451
return columns, default_value
45-
46-
47-
@callback(
48-
Output("collapse", "is_open"),
49-
[Input("collapse-button", "n_clicks")],
50-
[State("collapse", "is_open")],
51-
)
52-
def toggle_collapse(n, is_open):
53-
"""Toggle the collapse button."""
54-
if n:
55-
return not is_open
56-
return is_open
Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
import dash_bootstrap_components as dbc
2-
from dash import dcc, html
3-
4-
_FORM_ELEMENT_STYLE = {
5-
"display": "block",
6-
"width": "200px",
7-
# "margin": "0 20px 20px 20px",
8-
"verticalAlign": "middle",
9-
"justifyContent": "center",
10-
}
2+
from dash import html
113

4+
# Create your form components
5+
group_input = dbc.Select(
6+
id="search-form-group-input",
7+
options=[
8+
{"label": "node", "value": "node"},
9+
{"label": "line", "value": "line"},
10+
{"label": "link", "value": "link"},
11+
{"label": "transformer", "value": "transformer"},
12+
{"label": "branch", "value": "branch"},
13+
],
14+
value="node", # Default value
15+
style={"width": "150px", "display": "inline-block"}
16+
)
1217

13-
SEARCH_FORM_HTML = html.Div(
14-
[
15-
html.Div(
16-
dcc.RadioItems(["node", "line", "link", "transformer", "branch"], "node", id="search-form-group-input"),
17-
style=_FORM_ELEMENT_STYLE,
18-
),
19-
html.Div(dcc.Dropdown(["id"], "id", id="search-form-column-input"), style=_FORM_ELEMENT_STYLE),
20-
html.Div(
21-
dcc.Input(placeholder="Enter value to mark", id="search-form-value-input"),
22-
style=_FORM_ELEMENT_STYLE,
23-
),
24-
]
18+
column_input = dbc.Select(
19+
id="search-form-column-input",
20+
options=[{"label": "id", "value": "id"}],
21+
value="id", # Default value
22+
style={"width": "150px", "display": "inline-block"}
2523
)
2624

27-
SEARCH_FORM_TOGGLE = html.Div(
28-
dbc.Button(
29-
"Search",
30-
id="collapse-button",
31-
className="mb-3",
32-
color="primary",
33-
n_clicks=0,
34-
),
35-
style={"margin": "20px"},
25+
value_input = dbc.Input(
26+
id="search-form-value-input",
27+
placeholder="Enter value",
28+
type="text",
29+
style={"width": "150px", "display": "inline-block"}
3630
)
3731

38-
HEADER_HTML = html.Div(
32+
# Arrange as a sentence
33+
SEARCH_FORM_HTML = html.Div(
3934
[
40-
SEARCH_FORM_TOGGLE,
41-
dbc.Collapse(
42-
SEARCH_FORM_HTML,
43-
id="collapse",
44-
is_open=False,
45-
),
46-
]
35+
html.Span("Search ", className="mr-2", style={"margin-right": "8px"}),
36+
group_input,
37+
html.Span(" with ", className="mx-2", style={"margin": "0 8px"}),
38+
column_input,
39+
html.Span(" == ", className="mx-2", style={"margin": "0 8px"}),
40+
value_input,
41+
],
42+
style={
43+
"display": "flex",
44+
"align-items": "center",
45+
"justify-content": "center", # Centers items horizontally
46+
"padding": "10px",
47+
"margin": "0 auto", # Centers the container itself
48+
"width": "100%" # Ensures the container takes full width
49+
}
4750
)

src/power_grid_model_ds/_core/visualizer/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
search_form,
88
)
99
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 HEADER_HTML
10+
from power_grid_model_ds._core.visualizer.layout.search_form import SEARCH_FORM_HTML
1111
from power_grid_model_ds._core.visualizer.layout.selection_output import SELECTION_OUTPUT_HTML
1212
from power_grid_model_ds._core.visualizer.parsers import parse_branches, parse_node_array
1313
from power_grid_model_ds.arrays import NodeArray
@@ -43,7 +43,7 @@ def visualize(grid: Grid, layout: LayoutOptions = "", debug: bool = False):
4343
app.layout = html.Div(
4444
[
4545
columns_store,
46-
HEADER_HTML,
46+
SEARCH_FORM_HTML,
4747
cytoscape_html,
4848
SELECTION_OUTPUT_HTML,
4949
]

0 commit comments

Comments
 (0)