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

Make legend and hover information available outside dashboard.py #126

Open
4 of 6 tasks
jbednar opened this issue Mar 28, 2016 · 10 comments
Open
4 of 6 tasks

Make legend and hover information available outside dashboard.py #126

jbednar opened this issue Mar 28, 2016 · 10 comments
Assignees
Labels

Comments

@jbednar
Copy link
Member

jbednar commented Mar 28, 2016

The new legend support in dashboard.py is great, and once version 0.2 has been released, we should quickly move to putting some of the new code into the datashader library itself, both to reduce the size of dashboard.py (which has now grown much larger than it was initially) and to make that functionality available elsewhere (such as InteractiveImage).

Tasks:

  • Move downsampling function into datashader
  • Adapt the legend support into a general-purpose function or class for building legends
  • Adapt the hover support into a general-purpose function or class for showing hover information
  • Add hover and legend support to (a subclass of) InteractiveImage
  • Add legend and hover info to example notebooks
  • Use the legend support to show a color bar underneath the histograms in nyc_taxi.ipynb, to show how the histogram values map to color values.

We should also probably move InteractiveImage into Bokeh itself, if possible (issue #97), once we've made a legend- and hover-capable version, at which point we can know what the interface should be.

@jbednar
Copy link
Member Author

jbednar commented Oct 3, 2016

Making legends and hovers available in InteractiveImage is crucial for doing real work in datashader, but we still haven't been able to support that. Adding legends was previously on hold while waiting for Bokeh's new colorbar support to be merged, but that's now available in the latest Bokeh release, so it's ready to go at the plotting library end.

At the datashader end, the reason it is tricky is that we allow arbitrary transforms of the data in the pipeline, and there is not currently any way for the pipeline to communicate what these transforms were to the plotting library. InteractiveImage currently requires a callback that supplies only a bare image in response to a zoom or pan event, whereas we'll need to return metadata about what's in that image so that we can provide a suitable legend for that zoom level or pan area.

Proposed approach:

  1. Set up a registry of inverse transforms for the standard normalization functions. The how argument of tf.shade specifies how the data will be normalized and transformed into a colormap range, but this operation is currently only one way, from data to normalized magnitude. For a colormap we need to know the mapping from normalized magnitude (i.e., position in the colormap) to the original data value. The inverse mapping is unknown in general, since we accept any arbitrary function for how, but at least for the ones we supply, we can define inverse transforms (e.g. raising to power w for a log base w transform) and store those in a lookup table. The inverse transform for the default eq_hist transform will be a big job to implement, but it is an invertible mapping if enough metadata is stored about the forward direction, and so it should be possible.
  2. Write a function that provides the original data value for a list of normalized magnitudes (which have a one-to-one mapping with colors in the colormap), using these inverse transforms.
  3. Write a function to choose a suitable set of normalized magnitudes for function 2, perhaps with some options. E.g. one could choose all 256 evenly-spaced values in the colormap, or some regular sampling of them as appropriate for a colorbar of a certain width in the plot, or perhaps choose values at the boundaries of color ranges in the palette.
  4. Make a new version of InteractiveImage that accepts a richer datastructure than just an Image, with the legend (and eventually hover) information as well. This might be some container containing an image, some tuple of image and a dictionary, or maybe we could put the metadata into attributes on tf.Image.

The plan is to implement whatever version of these options can be done quickly and easily, then expand to cover the more difficult cases gradually.

@jbednar
Copy link
Member Author

jbednar commented Mar 22, 2017

We're gearing up to work on these issues again fairly soon, and hope to set up an interface to provide the data needed for hovers and legends in a general way, hopefully as something HoloViews can process automatically. Hopefully we can get to it without letting the year tick over again!

@philippjfr
Copy link
Member

philippjfr commented Mar 23, 2017

We just merged a PR (holoviz/holoviews#1223) in holoviews, which will let you generate interactive hover information from datashader aggregates in the notebook. Here's a toy example, which overlays the plot with a coarser aggregate to provide the hover information:

hover

@tommycarstensen
Copy link

@philippjfr Does the hover tool also work with Bokeh? Thanks.

@jbednar
Copy link
Member Author

jbednar commented Apr 26, 2017

The hover tool as shown above works only with HoloViews's bokeh backend.

@wmayner
Copy link

wmayner commented Jan 28, 2020

@philippjfr Is it possible to use your workaround to show just a tooltip for the nearest point? (Relevant when zooming in to a datashaded plot).

@jbednar
Copy link
Member Author

jbednar commented Feb 8, 2021

Legend support is now in holoviz/holoviews#4806

@bbudescu
Copy link

Can this also be applied to get legend entries for rasterized hv.Curves?

@jbednar
Copy link
Member Author

jbednar commented Jul 21, 2022

I guess try it and see! :-)

@bbudescu
Copy link

:))). Well, I did try and I couldn't get it to work. That's why I got here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants