Skip to content

Commit 472f7a8

Browse files
committed
Solving conflicts
2 parents 8ca5382 + cfdf4fc commit 472f7a8

File tree

9 files changed

+92
-69
lines changed

9 files changed

+92
-69
lines changed

vizro-core/examples/scratch_dev/app.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Dev app to try things out."""
2+
23
import time
34
import yaml
45

@@ -27,24 +28,35 @@
2728
def load_from_file(filter_column=None, parametrized_species=None):
2829
# Load the full iris dataset
2930
df = px.data.iris()
30-
df['date_column'] = pd.date_range(start=pd.to_datetime("2024-01-01"), periods=len(df), freq='D')
31+
df["date_column"] = pd.date_range(start=pd.to_datetime("2024-01-01"), periods=len(df), freq="D")
3132

3233
if parametrized_species:
3334
return df[df["species"].isin(parametrized_species)]
3435

35-
with open('data.yaml', 'r') as file:
36+
with open("data.yaml", "r") as file:
3637
data = yaml.safe_load(file)
3738
data = data or {}
3839

3940
filter_column = filter_column or FILTER_COLUMN
4041
if filter_column == "species":
41-
final_df = pd.concat(objs=[
42-
df[df[filter_column] == 'setosa'].head(data.get("setosa", 0)),
43-
df[df[filter_column] == 'versicolor'].head(data.get("versicolor", 0)),
44-
df[df[filter_column] == 'virginica'].head(data.get("virginica", 0)),
45-
], ignore_index=True)
42+
final_df = pd.concat(
43+
objs=[
44+
df[df[filter_column] == "setosa"].head(data.get("setosa", 0)),
45+
df[df[filter_column] == "versicolor"].head(data.get("versicolor", 0)),
46+
df[df[filter_column] == "virginica"].head(data.get("virginica", 0)),
47+
],
48+
ignore_index=True,
49+
)
4650
elif filter_column == "sepal_length":
47-
final_df = df[df[filter_column].between(data.get("min"), data.get("max",), inclusive="both")]
51+
final_df = df[
52+
df[filter_column].between(
53+
data.get("min"),
54+
data.get(
55+
"max",
56+
),
57+
inclusive="both",
58+
)
59+
]
4860
elif filter_column == "date_column":
4961
date_min = pd.to_datetime(data.get("date_min"))
5062
date_max = pd.to_datetime(data.get("date_max"))
@@ -82,16 +94,18 @@ def load_from_file(filter_column=None, parametrized_species=None):
8294
vm.Graph(
8395
id="p1-G-2",
8496
figure=px.scatter(data_frame=px.data.iris(), **SCATTER_CHART_CONF),
85-
)
97+
),
8698
],
8799
controls=[
88100
vm.Filter(id="p1-F-1", column="species", targets=["p1-G-1"], selector=vm.Dropdown(title="Dynamic filter")),
89101
vm.Filter(id="p1-F-2", column="species", targets=["p1-G-2"], selector=vm.Dropdown(title="Static filter")),
90102
vm.Parameter(
91103
targets=["p1-G-1.x", "p1-G-2.x"],
92-
selector=vm.RadioItems(options=["species", "sepal_width"], value="species", title="Simple X-axis parameter")
93-
)
94-
]
104+
selector=vm.RadioItems(
105+
options=["species", "sepal_width"], value="species", title="Simple X-axis parameter"
106+
),
107+
),
108+
],
95109
)
96110

97111

@@ -110,9 +124,11 @@ def load_from_file(filter_column=None, parametrized_species=None):
110124
vm.Filter(id="p2-F-4", column="species", selector=vm.RadioItems()),
111125
vm.Parameter(
112126
targets=["p2-G-1.x"],
113-
selector=vm.RadioItems(options=["species", "sepal_width"], value="species", title="Simple X-axis parameter")
114-
)
115-
]
127+
selector=vm.RadioItems(
128+
options=["species", "sepal_width"], value="species", title="Simple X-axis parameter"
129+
),
130+
),
131+
],
116132
)
117133

118134

@@ -129,9 +145,11 @@ def load_from_file(filter_column=None, parametrized_species=None):
129145
vm.Filter(id="p3-F-2", column="sepal_length", selector=vm.RangeSlider()),
130146
vm.Parameter(
131147
targets=["p3-G-1.x"],
132-
selector=vm.RadioItems(options=["species", "sepal_width"], value="species", title="Simple X-axis parameter")
133-
)
134-
]
148+
selector=vm.RadioItems(
149+
options=["species", "sepal_width"], value="species", title="Simple X-axis parameter"
150+
),
151+
),
152+
],
135153
)
136154

137155
page_4 = vm.Page(
@@ -147,9 +165,11 @@ def load_from_file(filter_column=None, parametrized_species=None):
147165
vm.Filter(id="p4-F-2", column="date_column", selector=vm.DatePicker()),
148166
vm.Parameter(
149167
targets=["p4-G-1.x"],
150-
selector=vm.RadioItems(options=["species", "sepal_width"], value="species", title="Simple X-axis parameter")
151-
)
152-
]
168+
selector=vm.RadioItems(
169+
options=["species", "sepal_width"], value="species", title="Simple X-axis parameter"
170+
),
171+
),
172+
],
153173
)
154174

155175
page_5 = vm.Page(
@@ -170,73 +190,66 @@ def load_from_file(filter_column=None, parametrized_species=None):
170190
# "p5-F-1.",
171191
],
172192
selector=vm.Dropdown(
173-
options=["setosa", "versicolor", "virginica"],
174-
multi=True,
175-
title="Parametrized species"
176-
)
193+
options=["setosa", "versicolor", "virginica"], multi=True, title="Parametrized species"
194+
),
177195
),
178196
vm.Parameter(
179197
targets=[
180198
"p5-G-1.x",
181199
# TODO: Uncomment the following target and see the magic :D
182200
# "p5-F-1.",
183201
],
184-
selector=vm.RadioItems(options=["species", "sepal_width"], value="species", title="Simple X-axis parameter")
202+
selector=vm.RadioItems(
203+
options=["species", "sepal_width"], value="species", title="Simple X-axis parameter"
204+
),
185205
),
186-
]
206+
],
187207
)
188208

189209

190210
page_6 = vm.Page(
191211
title="Page to test things out",
192212
components=[
193-
vm.Graph(
194-
id="graph_dynamic",
195-
figure=px.bar(data_frame="load_from_file", **BAR_CHART_CONF)
196-
),
213+
vm.Graph(id="graph_dynamic", figure=px.bar(data_frame="load_from_file", **BAR_CHART_CONF)),
197214
vm.Graph(
198215
id="graph_static",
199216
figure=px.scatter(data_frame=px.data.iris(), **SCATTER_CHART_CONF),
200-
)
217+
),
201218
],
202219
controls=[
203220
vm.Filter(
204221
id="filter_container_id",
205222
column=FILTER_COLUMN,
206223
targets=["graph_dynamic"],
207224
# targets=["graph_static"],
208-
209225
# selector=vm.Dropdown(id="filter_id"),
210226
# selector=vm.Dropdown(id="filter_id", value=["setosa"]),
211-
212227
# selector=vm.Checklist(id="filter_id"),
213228
# selector=vm.Checklist(id="filter_id", value=["setosa"]),
214-
215229
# TODO-BUG: vm.Dropdown(multi=False) Doesn't work if value is cleared. The persistence storage become
216230
# "null" and our placeholder component dmc.DateRangePicker can't process null value. It expects a value or
217231
# a list of values.
218232
# SOLUTION -> Create the "Universal Vizro placeholder component".
219233
# TEMPORARY SOLUTION -> set clearable=False for the dynamic Dropdown(multi=False)
220234
# selector=vm.Dropdown(id="filter_id", multi=False), ->
221235
# selector=vm.Dropdown(id="filter_id", multi=False, value="setosa"),
222-
223236
# selector=vm.RadioItems(id="filter_id"),
224237
# selector=vm.RadioItems(id="filter_id", value="setosa"),
225-
226238
# selector=vm.Slider(id="filter_id"),
227239
# selector=vm.Slider(id="filter_id", value=5),
228-
229240
# selector=vm.RangeSlider(id="filter_id"),
230241
# selector=vm.RangeSlider(id="filter_id", value=[5, 7]),
231-
),
242+
),
232243
vm.Parameter(
233244
id="parameter_x",
234-
targets=["graph_dynamic.x",],
245+
targets=[
246+
"graph_dynamic.x",
247+
],
235248
selector=vm.Dropdown(
236249
options=["species", "sepal_width"],
237250
value="species",
238251
multi=False,
239-
)
252+
),
240253
),
241254
],
242255
)

vizro-core/src/vizro/actions/_actions_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from vizro.models.types import MultiValueType, SelectorType, SingleValueType
1515

1616
if TYPE_CHECKING:
17-
from vizro.models import Action, VizroBaseModel, Filter
17+
from vizro.models import Action, VizroBaseModel
1818

1919
ValidatedNoneValueType = Union[SingleValueType, MultiValueType, None, list[None]]
2020

@@ -162,6 +162,7 @@ def _update_nested_figure_properties(
162162
current_property[keys[-1]] = value
163163
return figure_config
164164

165+
165166
def _get_parametrized_config(
166167
ctds_parameter: list[CallbackTriggerDict], target: ModelID, data_frame: bool
167168
) -> dict[str, Any]:

vizro-core/src/vizro/actions/_on_page_load_action.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from vizro.actions._actions_utils import _get_modified_page_figures
88
from vizro.managers._model_manager import ModelID
99
from vizro.models.types import capture
10-
from vizro.managers import model_manager, data_manager
1110

1211

1312
@capture("action")

vizro-core/src/vizro/models/_components/form/dropdown.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,8 @@ def _build_dynamic_placeholder(self):
123123
children=[
124124
dbc.Label(self.title, html_for=self.id) if self.title else None,
125125
dmc.DateRangePicker(
126-
id=self.id,
127-
value=self.value,
128-
persistence=True,
129-
persistence_type="session",
130-
style={'opacity': 0}
131-
)
126+
id=self.id, value=self.value, persistence=True, persistence_type="session", style={"opacity": 0}
127+
),
132128
]
133129
)
134130

vizro-core/src/vizro/models/_components/form/range_slider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _build_static(self, current_value=None, new_min=None, new_max=None, **kwargs
124124
persistence_type="session",
125125
className="slider-text-input-field",
126126
),
127-
dcc.Store(id=f"{self.id}_input_store", storage_type="session")
127+
dcc.Store(id=f"{self.id}_input_store", storage_type="session"),
128128
],
129129
className="slider-text-input-container",
130130
),
@@ -152,4 +152,4 @@ def _build_dynamic_placeholder(self):
152152
def build(self):
153153
# We don't have to implement _build_dynamic_placeholder, _build_static here. It's possible to: if dynamic and
154154
# self.value is None -> set self.value + return standard build (static), but let's align it with the Dropdown.
155-
return self._build_dynamic_placeholder() if self._dynamic else self._build_static()
155+
return self._build_dynamic_placeholder() if self._dynamic else self._build_static()

vizro-core/src/vizro/models/_components/form/slider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def _build_static(self, current_value=None, new_min=None, new_max=None, **kwargs
106106
persistence_type="session",
107107
className="slider-text-input-field",
108108
),
109-
dcc.Store(id=f"{self.id}_input_store", storage_type="session")
109+
dcc.Store(id=f"{self.id}_input_store", storage_type="session"),
110110
],
111111
className="slider-text-input-container",
112112
),

vizro-core/src/vizro/models/_controls/filter.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3-
from dash import dcc, html
4-
53
from typing import Any, Literal, Union
64

75
import numpy as np
86
import pandas as pd
7+
from dash import dcc
98
from pandas.api.types import is_datetime64_any_dtype, is_numeric_dtype
109

1110
from vizro.managers._data_manager import DataSourceName
@@ -18,6 +17,7 @@
1817
from vizro._constants import FILTER_ACTION_PREFIX
1918
from vizro.actions import _filter
2019
from vizro.managers import data_manager, model_manager
20+
from vizro.managers._data_manager import _DynamicData
2121
from vizro.managers._model_manager import ModelID
2222
from vizro.models import Action, VizroBaseModel
2323
from vizro.models._components.form import (
@@ -30,8 +30,6 @@
3030
)
3131
from vizro.models._models_utils import _log_call
3232
from vizro.models.types import MultiValueType, SelectorType
33-
from vizro.models._components.form._form_utils import get_options_and_default
34-
from vizro.managers._data_manager import _DynamicData
3533

3634
# Ideally we might define these as NumericalSelectorType = Union[RangeSlider, Slider] etc., but that will not work
3735
# with isinstance checks.

vizro-core/src/vizro/static/js/models/range_slider.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,33 @@ function update_range_slider_values(
2828
}
2929
return [start, end, [start, end], [start, end]];
3030

31-
// slider component is the trigger
31+
// slider component is the trigger
3232
} else if (trigger_id === self_data["id"]) {
3333
return [slider[0], slider[1], slider, slider];
3434

35-
// on_page_load is the trigger
35+
// on_page_load is the trigger
3636
} else {
3737
if (input_store === null) {
38-
return [dash_clientside.no_update, dash_clientside.no_update, dash_clientside.no_update, slider];
39-
}
40-
else {
41-
if (slider[0] === start && input_store[0] === start && slider[1] === end && input_store[1] === end){
38+
return [
39+
dash_clientside.no_update,
40+
dash_clientside.no_update,
41+
dash_clientside.no_update,
42+
slider,
43+
];
44+
} else {
45+
if (
46+
slider[0] === start &&
47+
input_store[0] === start &&
48+
slider[1] === end &&
49+
input_store[1] === end
50+
) {
4251
// To prevent filter_action to be triggered after on_page_load
43-
return [dash_clientside.no_update, dash_clientside.no_update, dash_clientside.no_update, dash_clientside.no_update];
52+
return [
53+
dash_clientside.no_update,
54+
dash_clientside.no_update,
55+
dash_clientside.no_update,
56+
dash_clientside.no_update,
57+
];
4458
}
4559
return [input_store[0], input_store[1], input_store, input_store];
4660
}

vizro-core/src/vizro/static/js/models/slider.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ function update_slider_values(start, slider, input_store, self_data) {
1414
}
1515
return [start, start, start];
1616

17-
// slider component is the trigger
17+
// slider component is the trigger
1818
} else if (trigger_id === self_data["id"]) {
1919
return [slider, slider, slider];
2020

21-
// on_page_load is the trigger
21+
// on_page_load is the trigger
2222
} else {
2323
if (input_store === null) {
2424
return [dash_clientside.no_update, dash_clientside.no_update, slider];
25-
}
26-
else {
25+
} else {
2726
if (slider === start && start === input_store) {
2827
// To prevent filter_action to be triggered after on_page_load
29-
return [dash_clientside.no_update, dash_clientside.no_update, dash_clientside.no_update];
28+
return [
29+
dash_clientside.no_update,
30+
dash_clientside.no_update,
31+
dash_clientside.no_update,
32+
];
3033
}
3134
return [input_store, input_store, input_store];
3235
}
3336
}
3437
}
3538

36-
3739
window.dash_clientside = {
3840
...window.dash_clientside,
3941
slider: { update_slider_values: update_slider_values },

0 commit comments

Comments
 (0)