Plot: Data Items from Stacked Bar

In the attached notebook, I have a bar chart built with plot and @mkfreeman’s @mkfreeman/plot-tooltip.

I want to provide a tooltip showing the consumption_grade which should apply to any given stacked element. I say stacked, as the fill is taken from consumption_grade, however it doesn’t appear stacked (which is fine) as each consumption_grade happens to fall into different bins.

However, the tooltip is showing as undefined, I expect due to (d) =>Consumption Grade: ${d.consumption_grade} not being grouped correctly.

You need to reduce the title, too. You can pull out the first value for each bin like so:

Plot.binX({y: "count", title: "first"}, …)

Alternatively you can definite your title as a reducer where it is passed the data for each bin, so if you want to pull out the first data point for each bin e.g.:

Plot.binX({y: "count", title: ([d]) => d.consumption_grade}, …)

Thanks @mbostock