diff --git a/holoviews/operation/downsample.py b/holoviews/operation/downsample.py index aa6391d4e2..1ed44d5aa2 100644 --- a/holoviews/operation/downsample.py +++ b/holoviews/operation/downsample.py @@ -29,11 +29,13 @@ """ import math +from functools import partial import numpy as np import param from .resample import ResampleOperation1D +from ..core import NdOverlay, Overlay from ..element.chart import Area @@ -165,6 +167,14 @@ class downsample1d(ResampleOperation1D): algorithm = param.Selector(default='lttb', objects=['lttb', 'nth']) def _process(self, element, key=None): + if isinstance(element, (Overlay, NdOverlay)): + _process = partial(self._process, key=key) + if isinstance(element, Overlay): + elements = [v.map(_process) for v in element] + else: + elements = {k: v.map(_process) for k, v in element.items()} + return element.clone(elements) + if self.p.x_range: element = element[slice(*self.p.x_range)] if len(element) <= self.p.width: diff --git a/holoviews/tests/operation/test_downsample.py b/holoviews/tests/operation/test_downsample.py new file mode 100644 index 0000000000..d82813b1d0 --- /dev/null +++ b/holoviews/tests/operation/test_downsample.py @@ -0,0 +1,20 @@ +import pytest + +import holoviews as hv +from holoviews.operation.downsample import downsample1d + + +@pytest.mark.parametrize("plottype", ["overlay", "ndoverlay"]) +def test_downsample1d_multi(plottype): + N = 1000 + assert N > downsample1d.width + + if plottype == "overlay": + figure = hv.Overlay([hv.Curve(range(N)), hv.Curve(range(N))]) + elif plottype == "ndoverlay": + figure = hv.NdOverlay({"A": hv.Curve(range(N)), "B": hv.Curve(range(N))}) + + figure_values = downsample1d(figure, dynamic=False).data.values() + for n in figure_values: + for value in n.data.values(): + assert value.size == downsample1d.width