Skip to content

Fix hover label in stacked bars #1163

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

Merged
merged 1 commit into from
Nov 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/traces/bar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
if(Color.opacity(mc)) pointData.color = mc;
else if(Color.opacity(mlc) && mlw) pointData.color = mlc;

var size = (trace.base) ? di.b + di.s : di.s;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@n-riesco Can you clarify why we need this ternary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bars of traces that set base have their di.b set accordingly and are excluded from stacking. The size of these bars is computed as di.b + di.s.

The bars of traces that don't set base have their di.b set to 0, unless they are stacked, in which case, the stacking algorithm sets di.b. For these bars, the bar size is di.s; no need to add di.b (either because it'd be 0, or because it'd be something that the stacking algorithm has set to stack the bars).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think you got this right.

For reference, here's the non-stacked case under base restyle:

gifrecord_2016-11-17_133959

Perhaps we could set a special flag in the stacked bar calcdata traces here instead of relying on the fact that all stacked bars have falsy trace.base. Or maybe adding a few test cases will suffice.

if(trace.orientation === 'h') {
pointData.x0 = pointData.x1 = xa.c2p(di.x, true);
pointData.xLabelVal = di.b + di.s;
pointData.xLabelVal = size;

pointData.y0 = ya.c2p(barPos(di) - barDelta, true);
pointData.y1 = ya.c2p(barPos(di) + barDelta, true);
pointData.yLabelVal = di.p;
}
else {
pointData.y0 = pointData.y1 = ya.c2p(di.y, true);
pointData.yLabelVal = di.b + di.s;
pointData.yLabelVal = size;

pointData.x0 = xa.c2p(barPos(di) - barDelta, true);
pointData.x1 = xa.c2p(barPos(di) + barDelta, true);
Expand Down