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

feat: Server side HoverTool for rasterized/datashaded plots with selector #6422

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Oct 25, 2024

Previously, we sent all hover data to the front end, which could lead to significant overhead on larger plots. With this PR, the data is pushed server-side to the hover tool with a custom data model.

Currently working on datashade(agg=by, sel=min) and datashade(agg=by, sel=min).

Example script
import itertools

import datashader as ds
import numpy as np
import pandas as pd
import panel as pn

import holoviews as hv
from holoviews.operation.datashader import datashade, dynspread as _dynspread, rasterize

hv.extension("bokeh")

num = 10000
seed = np.random.default_rng(1)


dists = {
    cat: pd.DataFrame(
        {
            "x": seed.normal(x, s, num),
            "y": seed.normal(y, s, num),
            "s": s,
            "val": val,
            "cat": cat,
        }
    )
    for x, y, s, val, cat in [
        (2, 2, 0.03, 0, "d1"),
        (2, -2, 0.10, 1, "d2"),
        (-2, -2, 0.50, 2, "d3"),
        (-2, 2, 1.00, 3, "d4"),
        (0, 0, 3.00, 4, "d5"),
    ]
}

df = pd.concat(dists, ignore_index=True)
df["y"] += 100  # Offset to distinguish x from y
points = hv.Points(df)


def dynspread(plot, aggregator, selector):
    return _dynspread(datashade(plot, aggregator=aggregator, selector=selector))


ops = (rasterize, datashade, dynspread)
aggs = (ds.min("s"), ds.by("cat"))
sels = (None, ds.min("s"))
combinations = itertools.product(ops, aggs, sels)
plots = []
for op, agg, sel in combinations:
    title = f"{op.__name__}(agg={type(agg).__name__}, sel={type(sel).__name__ if sel else None})"
    try:
        plot = op(points, aggregator=agg, selector=sel).opts(
            tools=["hover"], title=title, width=400, height=400
        )
    except Exception as e:
        print(e)
        plot = hv.Curve([]).opts(title=title, width=400, height=400)
    plots.append(plot)

pn.panel(hv.Layout(plots).cols(4).opts(shared_axes=False)).servable()

image

@hoxbro hoxbro added the type: enhancement Minor feature or improvement to an existing feature label Oct 25, 2024
Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 36 lines in your changes missing coverage. Please review.

Project coverage is 88.48%. Comparing base (ee19136) to head (9b5342b).

Files with missing lines Patch % Lines
holoviews/tests/ui/bokeh/test_hover.py 51.28% 19 Missing ⚠️
holoviews/operation/datashader.py 88.88% 9 Missing ⚠️
holoviews/plotting/bokeh/raster.py 87.50% 7 Missing ⚠️
holoviews/element/raster.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6422      +/-   ##
==========================================
- Coverage   88.50%   88.48%   -0.03%     
==========================================
  Files         323      323              
  Lines       68631    68806     +175     
==========================================
+ Hits        60741    60880     +139     
- Misses       7890     7926      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro hoxbro changed the title enh: Update hovertool server side for rasterized plots enh: Make HoverTool update server side for rasterized/datashaded plots Oct 28, 2024
@hoxbro hoxbro changed the title enh: Make HoverTool update server side for rasterized/datashaded plots feat: Make HoverTool update server side for rasterized/datashaded plots Nov 5, 2024
@hoxbro hoxbro changed the title feat: Make HoverTool update server side for rasterized/datashaded plots feat: Server side HoverTool for rasterized/datashaded plots Nov 5, 2024
@hoxbro hoxbro changed the title feat: Server side HoverTool for rasterized/datashaded plots feat: Server side HoverTool for rasterized/datashaded plots with selector Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant