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

Conversation

n-riesco
Copy link
Contributor

Fixes #1157

* Fixed incorrect bar size in the hover labels of stacked bars.

Fixes plotly#1157
@@ -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.

@etpinard etpinard added status: reviewable bug something broken labels Nov 17, 2016
@etpinard
Copy link
Contributor

Thanks @n-riesco for the quick turnaround 🍻

@etpinard etpinard merged commit 1c32bc5 into plotly:master Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants