Move height/width/view from layer to parent
@@ -1221,6 +1221,8 @@ class TopLevelMixin(mixins.ConfigMethodMixin):
"""
if isinstance(filter, Parameter):
filter = {"param": filter.name}
+ if "empty" in kwargs:
+ filter["empty"] = kwargs.pop("empty")
return self._add_transform(core.FilterTransform(filter=filter, **kwargs))
def transform_flatten(self, flatten, as_=Undefined):
@@ -2122,17 +2124,12 @@ class Chart(
copy.params.append(s.param)
return copy
- def add_selection(self, *selections):
- """Add one or more selections to the chart."""
- if not selections:
- return self
- copy = self.copy(deep=["selection"])
- if copy.selection is Undefined:
- copy.selection = {}
-
- for s in selections:
- copy.selection[s.name] = s.selection
- return copy
+ def add_selection(self, *params):
+ warnings.warn(
+ """'add_selection' is deprecated. Use 'add_parameter'.""",
+ DeprecationWarning,
+ )
+ return self.add_parameter(*params)
def interactive(self, name=None, bind_x=True, bind_y=True):
"""Make chart axes scales interactive
@@ -2496,6 +2493,13 @@ class LayerChart(TopLevelMixin, _EncodingMixin, core.TopLevelLayerSpec):
super(LayerChart, self).__init__(data=data, layer=list(layer), **kwargs)
self.data, self.layer = _combine_subchart_data(self.data, self.layer)
+ # Some properties are not allowed within layer; we'll move to parent.
+ bad_props = ("height", "width", "view")
+ combined_dict, self.layer = _remove_bad_props(self, self.layer, bad_props)
+
+ for prop in combined_dict:
+ self[prop] = combined_dict[prop]
+
def __iadd__(self, other):
_check_if_valid_subspec(other, "LayerChart")
_check_if_can_be_layered(other)
@@ -2669,6 +2673,42 @@ def _combine_subchart_data(data, subcharts):
return data, subcharts
+def _remove_bad_props(chart, subcharts, bad_props):
+ def remove_prop(subchart, prop):
+ if subchart[prop] is not Undefined:
+ subchart = subchart.copy()
+ subchart[prop] = Undefined
+ return subchart
+
+ output_dict = {}
+
+ if not subcharts:
+ # No subcharts = nothing to do.
+ return output_dict
+
+ for prop in bad_props:
+ if chart[prop] is Undefined:
+ # Top level does not have this prop.
+ # Check for consistent props within the subcharts.
+ values = [c[prop] for c in subcharts if c[prop] is not Undefined]
+ if len(values) == 0:
+ pass
+ elif all(v is values[0] for v in values[1:]):
+ output_dict[prop] = values[0]
+ else:
+ raise ValueError(f"There are inconsistent values {values} for {prop}")
+ else:
+ # Top level has this prop; subchart props must be either
+ # Undefined or identical to proceed.
+ if all(c[prop] is Undefined or c[prop] is chart[prop] for c in subcharts):
+ output_dict[prop] = chart[prop]
+ else:
+ raise ValueError(f"There are inconsistent values {values} for {prop}")
+ subcharts = [remove_prop(c, prop) for c in subcharts]
+
+ return output_dict, subcharts
+
+
@utils.use_signature(core.SequenceParams)
def sequence(start, stop=None, step=Undefined, as_=Undefined, **kwds):
"""Sequence generator."""
