Fix hover label in stacked bars#1163
Conversation
* Fixed incorrect bar size in the hover labels of stacked bars. Fixes plotly#1157
| 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; |
There was a problem hiding this comment.
@n-riesco Can you clarify why we need this ternary?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Ok. I think you got this right.
For reference, here's the non-stacked case under base restyle:
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.
|
Thanks @n-riesco for the quick turnaround 🍻 |

Fixes #1157