observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.27k stars 174 forks source link

ENH: have default tooltip for stacked geometries also show total, stacked value. #1975

Closed fgregg closed 8 months ago

fgregg commented 8 months ago

In this chart, hovering over a geometry gives the value for the that group. It would be excellent if it also gave the total, stacked value.

https://observablehq.com/@fgregg/chicago-shelter-eviction-rates#cell-229

Screenshot 2024-01-18 at 9 38 36 AM
mbostock commented 8 months ago

This isn’t currently technically possible because the stack transform computes extents for each value (y1–y2); the total across the entire stack isn’t accessible. And also stacks are diverging with negative values, so would you want to plot the minimum value too? Or only if it isn’t zero? That feels too niche to me.

You can plot the total value if you use the group or bin transform (instead of stack), but then you lose the per-series value, and also you’d have two tips simultaneously visible.

    Plot.lineY(
      pulsed_eviction_rate,
      Plot.binX(
        { y: "sum", reverse: cumulative === "normal" },
        {
          x: "date",
          interval: "day",
          y: "count",
          curve: "step",
          cumulative: cumulative === "cumulative",
          tip: true,
          inset: 0
        }
      )
    ),

I can’t think of a way to show both the series value and the total value.

fgregg commented 8 months ago

thanks for your consideration!