Skip to content

Commit

Permalink
POC for data_frame parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Dec 5, 2024
1 parent afdb96b commit 675502f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
11 changes: 6 additions & 5 deletions vizro-core/src/vizro/actions/_actions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,14 @@ def _get_modified_page_figures(

outputs: dict[ModelID, Any] = {}

control_targets = []
figure_targets = []
control_targets = set()
figure_targets = set()
for target in targets:
if isinstance(model_manager[target], Filter):
control_targets.append(target)
if isinstance((filter := model_manager[target]), Filter):
control_targets.add(target)
figure_targets |= set(filter.targets)
else:
figure_targets.append(target)
figure_targets.add(target)

# TODO-NEXT: Add fetching unfiltered data for the Filter.targets as well, once dynamic filters become "targetable"
# from other actions too. For example, in future, if Parameter is targeting only a single Filter.
Expand Down
21 changes: 18 additions & 3 deletions vizro-core/src/vizro/actions/_parameter_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dash import ctx

from vizro.actions._actions_utils import _get_modified_page_figures
from vizro.managers._model_manager import ModelID
from vizro.managers._model_manager import ModelID, model_manager
from vizro.models.types import capture


Expand All @@ -22,11 +22,26 @@ def _parameter(targets: list[str], **inputs: dict[str, Any]) -> dict[ModelID, An
Dict mapping target component ids to modified charts/components e.g. {'my_scatter': Figure({})}
"""
target_ids: list[ModelID] = [target.split(".")[0] for target in targets] # type: ignore[misc]
# figure_targets: list[ModelID] = [target.split(".") for target in targets] # type: ignore[misc]

# need to provide current page or just get all Filters from whole dashboard
figure_targets = targets
filters = [
filter for filter in cast(Iterable[Filter], model_manager._get_models(Filter, page=page)) if filter._dynamic
]

filter_targets = set()

for figure_target in figure_targets:
figure_target_id, figure_target_argument = figure_target.split(".", 1)
if figure_target_argument.startswith("data_frame"):
for filter in filters:
if figure_target_id in filter.targets:
filter_targets.add(filter.id)

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=target_ids,
targets=figure_targets + list(filter_targets),
)

0 comments on commit 675502f

Please sign in to comment.