Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lumen/tests/views/test_hvplot_datashade.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,40 @@ def test_hvplot_view_omits_unset_datashade(categorical_pipeline, categorical_df)
assert "color_key" not in recorded


def test_widget_params_declared():
"""The AI agent's schema is derived from these params, so they must exist."""
for name in ("widget_type", "widget_location"):
assert name in hvPlotBaseView.param


def test_hvplot_view_forwards_widget_params(categorical_pipeline, categorical_df):
view = hvPlotView(
pipeline=categorical_pipeline,
kind="scatter",
x="x",
y="y",
groupby="ancestry",
widget_type="scrubber",
widget_location="bottom",
)

recorded = record_hvplot_call(view, categorical_df)

assert recorded["groupby"] == ["ancestry"]
assert recorded["widget_type"] == "scrubber"
assert recorded["widget_location"] == "bottom"


def test_hvplot_view_omits_unset_widget_params(categorical_pipeline, categorical_df):
"""Unset widget params must not appear, keeping existing plots unchanged."""
view = hvPlotView(pipeline=categorical_pipeline, kind="scatter", x="x", y="y")

recorded = record_hvplot_call(view, categorical_df)

assert "widget_type" not in recorded
assert "widget_location" not in recorded


def test_hvplot_view_keeps_dict_cmap_kwarg(categorical_pipeline, categorical_df):
"""Specs predating color_key passed the mapping as cmap; hvPlot still maps a
dict cmap onto color_key, so those must keep working."""
Expand Down
13 changes: 13 additions & 0 deletions lumen/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,15 @@ class hvPlotBaseView(View):

groupby = param.ListSelector(doc="The column(s) to group by.")

widget_type = param.String(default=None, doc="""
Whether to display the ``groupby`` widgets as a scrubber/player or as
static widgets. If not set, defers to hvPlot's default.""")

widget_location = param.ClassSelector(default=None, class_=(str, list, tuple), doc="""
The location of the ``groupby`` widgets relative to the plot, e.g.
'bottom', 'left' or ('left', 'top'). If not set, defers to hvPlot's
default.""")

z = param.Selector(doc="""
Column of z-values for gridded plot kinds (image, quadmesh, heatmap, contourf).
Internally mapped to hvPlot's C= for kind='heatmap' and z= for other kinds.""")
Expand Down Expand Up @@ -1309,6 +1318,10 @@ def get_plot(self, df):
if self.aggregator is not None:
self._check_aggregator(processed)
processed['aggregator'] = self.aggregator
if self.widget_type is not None:
processed['widget_type'] = self.widget_type
if self.widget_location is not None:
processed['widget_location'] = self.widget_location

kind = self.kind
plot_source = df
Expand Down