Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for NdOverlay and Overlay in downsample1d #5856

Merged
merged 4 commits into from
Aug 16, 2023
Merged
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
10 changes: 10 additions & 0 deletions holoviews/operation/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions holoviews/tests/operation/test_downsample.py
Original file line number Diff line number Diff line change
@@ -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