Skip to content

Linked hover: look up the bin by arithmetic instead of one object per cell #38

Closed

Description

@jvdd

Problem

The server sends one [lo, step, n] triple per binned axis (x_edges, y_edges). The client expands the triples back into one bound object per bin or per cell (_hoverBoundsFromEdges in flexviz/adapters/js/plotly/traces.js) and stores them twice: as trace.customdata and in hoverCellsByTraceUid through _rebuildHoverCells. A 1000 x 1000 histogram2d builds a million objects on every update. The linked-hover matchers in plotly/hover.js then scan those cells linearly to find the one that contains a point. The scan predates this branch; the object expansion is the part the triple makes unnecessary.

Proposal

  1. Keep the triples per trace uid instead of the expanded cells.
  2. Resolve a coordinate to a bin index with floor((v - lo) / step), clamped to [0, n - 1], and derive the bounds of that one bin. Server and client already bin with this arithmetic.
  3. Drop trace.customdata for binned traces once nothing reads it; pt.customdata has one reader in hover.js, which can derive the bounds from pt.x / pt.y and the triple.

Done when

  • No per-bin or per-cell object is built on the client for histogram, histogram2d or geo traces.
  • tests/test_browser.py::TestBinEdgeTripleBrowser still passes.
  • Hover on a 1000 x 1000 histogram2d costs O(1) per event.

Activity

  1. jvdd commented on Sep 29, 2026

    @jvdd
    ContributorAuthor

    #119 closes this issue for hover. Geo is the exception in the "done when" list, and it stays as it is:

    • Hover builds no object per bin or cell any more, for histogram and histogram2d. The client keeps the [lo, step, n] triples and finds a bin by arithmetic (binAt).
    • Geo still builds one GeoJSON rectangle per non-empty cell (_geoRectanglesFromEdges). The choroplethmap needs these rectangles to draw the cells, so they are not a hover cost. Geo is not a linked-hover target.
    • A follow-up for geo makes sense only if a measurement shows that the rectangles are slow.
  2. jvdd commented on Sep 29, 2026

    @jvdd
    ContributorAuthor

    Fixed by #119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions