Bug: areaY tip/pointer position wrong for stacked data #1952
-
(Solutions and options are shown here: https://observablehq.com/d/d091c93672b14460) There seems to be a bug when using the tip/pointer interaction on an
Notice in these screenshots how the tool-tip overlay is positioned wrong for the orange area. You cannot see my mouse-pointer, but it is positioned next to the notch in the overlay. Also note the plot looks a little confusing when the orange area switches between negative and positive. I imagine it is because the lines are interpolated. I don't know if anything could be done about that, but it would of course be a separate issue. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
You could try and add an explicit Plot.stackY transform in the options for the tip mark (the areaY mark does not need it because it stacks implicitly). |
Beta Was this translation helpful? Give feedback.
-
As @Fil said, you need to make the stack transform explicit if you are using it with the tip mark; the area mark applies it implicitly, but the tip mark does not. But there’s no reason to use the tip mark explicitly here when you can use the tip option instead, and then you can continue to benefit from the implicit stack transform provided by the area mark. That looks like this: Plot.plot({
marginLeft: 50,
y: {
grid: true,
label: "Unemployed (thousands)"
},
marks: [
Plot.areaY(unemployment, {x: "date", y: "unemployed", fill: "industry", tip: true}),
Plot.ruleY([0])
]
}) I also removed the “↑” from the label since the arrow is applied implicitly by the axis (though see the labelArrow option) and you don’t want it in the tooltip. And I removed the title option from the area mark, since it was competing with the tip mark, resulting in duplicate tips. I don’t see the problem you describe with the position of the tooltip; it looks correct to me in the screenshot above. Note that for an area mark (or any mark with y1 and y2 channels) the tooltip will be positioned in the vertical center of the band, not on the top of the band. If you want the tip to be on the top of the band, you can again make the tip mark explicit and then use the stackY2 transform instead of stackY. Plot.plot({
marginLeft: 50,
y: {
grid: true,
label: "Unemployed (thousands)"
},
marks: [
Plot.areaY(unemployment, {x: "date", y: "unemployed", fill: "industry"}),
Plot.ruleY([0]),
Plot.tip(unemployment, Plot.pointerX(Plot.stackY2({x: "date", y: "unemployed", fill: "industry"}))),
]
}) I don’t know what to say regarding the other confusion with negative/positive values in the stacked area. What would you expect to see instead? Edit: Looks like you filed a separate issue for this in #1963 so let’s not discuss this further here. |
Beta Was this translation helpful? Give feedback.
As @Fil said, you need to make the stack transform explicit if you are using it with the tip mark; the area mark applies it implicitly, but the tip mark does not. But there’s no reason to use the tip mark explicitly here when you can use the tip option instead, and then you can continue to benefit from the implicit stack transform provided by the area mark. That looks like this:
I also removed the “↑” from the label since the arrow is applied implicitly by the axis (thou…