Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-qb committed Nov 18, 2024
1 parent a89b8bf commit 48e6716
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
4 changes: 1 addition & 3 deletions vizro-core/src/vizro/actions/_on_page_load_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ def _on_page_load(targets: list[ModelID], **inputs: dict[str, Any]) -> dict[Mode
Dict mapping target chart ids to modified figures e.g. {'my_scatter': Figure({})}
"""
return_obj = _get_modified_page_figures(
return _get_modified_page_figures(
ctds_filter=ctx.args_grouping["external"]["filters"],
ctds_filter_interaction=ctx.args_grouping["external"]["filter_interaction"],
ctds_parameter=ctx.args_grouping["external"]["parameters"],
targets=targets,
)

return return_obj
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_components/form/dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def _build_static(self, new_options=None, **kwargs):
def _build_dynamic_placeholder(self):
# Setting self.value is kind of Dropdown pre_build method. It sets self.value only the first time if it's None.
# We cannot create pre_build for the Dropdown because it has to be called after vm.Filter.pre_build, but nothing
# guarantees that. We can call Filter.selector.pre_build() from the Filter.pre_build() method it we decide that.
# guarantees that. We can call Filter.selector.pre_build() from the Filter.pre_build() method if we decide that.
if self.value is None:
self.value = get_options_and_default(self.options, self.multi)[1]

# Replace this with the Universal Vizro Placeholder component.
# TODO-NEXT: Replace this with the "universal Vizro placeholder" component.
return html.Div(
children=[
dbc.Label(self.title, html_for=self.id) if self.title else None,
Expand Down
24 changes: 9 additions & 15 deletions vizro-core/src/vizro/models/_controls/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"categorical": SELECTORS["numerical"] + SELECTORS["temporal"],
}

# TODO: Remove this check when support dynamic mode for DatePicker selector.
# TODO: Remove DYNAMIC_SELECTORS along with its validation check when support dynamic mode for the DatePicker selector.
# Tuple of filter selectors that support dynamic mode
DYNAMIC_SELECTORS = (Dropdown, Checklist, RadioItems, Slider, RangeSlider)

Expand Down Expand Up @@ -173,14 +173,11 @@ def pre_build(self):
f"'{self.column}'."
)

# Selector can't be dynamic if:
# 1. Selector doesn't support the dynamic mode
# 2. Selector is categorical and "options" prop is defined
# 3. Selector is numerical and "min" and "max" props are defined
# Selector can be dynamic if selector support the dynamic mode and "options", "min" and "max" are not provided.
if isinstance(self.selector, DYNAMIC_SELECTORS) and (
hasattr(self.selector, "options")
and not getattr(self.selector, "options")
or all(hasattr(self.selector, attr) and getattr(self.selector, attr) is None for attr in ["min", "max"])
not getattr(self.selector, "options", None)
and getattr(self.selector, "min", None) is None
and getattr(self.selector, "max", None) is None
):
for target_id in self.targets:
data_source_name = model_manager[target_id]["data_frame"]
Expand Down Expand Up @@ -218,7 +215,6 @@ def pre_build(self):

@_log_call
def build(self):
# TODO: Align inner and outer ids to be handled in the same way as for other figure components.
selector_build_obj = self.selector.build()
return dcc.Loading(id=self.id, children=selector_build_obj) if self._dynamic else selector_build_obj

Expand Down Expand Up @@ -277,12 +273,10 @@ def _get_min_max(targeted_data: pd.DataFrame, current_value=None) -> tuple[float
_max = targeted_data.max(axis=None).item()

if current_value:
if isinstance(current_value, list):
_min = min(_min, current_value[0])
_max = max(_max, current_value[1])
else:
_min = min(_min, current_value)
_max = max(_max, current_value)
# The current_value is a list of two elements when a range selector is used. Otherwise it is a single value.
_is_range_selector = isinstance(current_value, list)
_min = min(_min, current_value[0] if _is_range_selector else current_value)
_max = max(_max, current_value[1] if _is_range_selector else current_value)

return _min, _max

Expand Down

0 comments on commit 48e6716

Please sign in to comment.