Skip to content

Fix hover label in stacked bars#1163

Merged
etpinard merged 1 commit into
plotly:masterfrom
n-riesco:pr-20161117-fix-issue-1157
Nov 17, 2016
Merged

Fix hover label in stacked bars#1163
etpinard merged 1 commit into
plotly:masterfrom
n-riesco:pr-20161117-fix-issue-1157

Conversation

@n-riesco

Copy link
Copy Markdown
Contributor

Fixes #1157

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

Fixes plotly#1157
Comment thread src/traces/bar/hover.js
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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