You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stacked histograms have different start/end values on hover #4648
we are just doing the calculation of number of digits to show in these labels independently for each trace even when they're stacked or grouped so the coordinates should match.
changed the title [-]bins can different start/end values on stacked histograms[/-][+]bins can have different start/end values on stacked histograms[/+]on Mar 16, 2020
The test added in ee1a6ba showcases the problem at hand.
The problem comes from the fact that each trace has its own rounding function roundFn which is determined by their trace specific leftGap and rightGap:
changed the title [-]bins can have different start/end values on stacked histograms[/-][+]stacked histograms have different start/end values on hover [/+]on Mar 16, 2020
One possible solution is to defer the evaluation of ph0 and ph1 to after we're done with the calc phase of all traces. This is what is implemented in branch fix-4648. It's rather hacky but it seems to solve the issue at hand.
Ideally things like this belong in crossTraceCalc, though that could also be hacky since histogram shares that with bar. Your solution looks good, it's just better to minimize the work in hover when possible.
Ideally things like this belong in crossTraceCalc, though that could also be hacky since histogram shares that with bar.
I forgot that crossTraceCalc is executed after the calc steps of each trace. I could definitely do the work of computing ph0 and ph1 over there. The only downside is that we will have to loop over all the bars again.
Your solution looks good, it's just better to minimize the work in hover when possible.
I understand that we may not want to add latency to something interactive. Computing everything in advance is probably a better approach considering we don't usually have a lot of bars.
Actually using the bundle from fix-4648-cross, we only get one item when using the hover compare mode. I'm a bit puzzled as to why. Investigating now. Let me know if you have any hint!
@antoinerg the approach in fix-4648-cross looks great, though somehow it's getting a mismatch of bin positions - looks like maybe fullTrace._binEdges is for all traces but each trace may start at a different bin? Only Africa, which has the left-most bin, looks correct. Not sure why that would cause problems for getting all the other items but perhaps fixing that will resolve both?
Here the box says 40-something but the cursor is at 50-something... and if you switch to closest mode you can look at all the traces.
That'll work! I believe the index is simply offset between traces, so it might be more efficient just to store it once, something like cd[0].t.i0 but that's not a big deal.
That'll work! I believe the index is simply offset between traces, so it might be more efficient just to store it once, something like cd[0].t.i0 but that's not a big deal.
Sounds good. In the end, I think I will use my first approach of preparing functions in histogram/calc.js and defer their evaluation until later. However, instead of doing the evaluation in hover, I would do it in the crossTraceCalc step. I think it results in cleaner code.
When deferring the evaluation of ph0 and ph1, I encounter an edge case: both leftGap and rightGap can be zero and the rounding function then returns NaN.
@alexcjohnson I think you wrote getBinSpanLabelRound. Is it easy to account for this edge case? Basically passing this test: c824fa3
Activity
alexcjohnson commentedon Mar 16, 2020
FWIW this happens with regular split hover as well -

alexcjohnson commentedon Mar 16, 2020
we are just doing the calculation of number of digits to show in these labels independently for each trace even when they're stacked or grouped so the coordinates should match.

archmoj commentedon Mar 16, 2020
@alexcjohnson is this a bug?
alexcjohnson commentedon Mar 16, 2020
Yes, bug. I forget how that calculation works but whatever it does should be shared by all traces in a group or stack.
[-]Unified hover x values on stacked histograms[/-][+]bins can different start/end values on stacked histograms[/+][-]bins can different start/end values on stacked histograms[/-][+]bins can have different start/end values on stacked histograms[/+]antoinerg commentedon Mar 16, 2020
The test added in ee1a6ba showcases the problem at hand.
The problem comes from the fact that each trace has its own rounding function
roundFnwhich is determined by their trace specificleftGapandrightGap:plotly.js/src/traces/histogram/calc.js
Lines 112 to 131 in 9a75ef0
which then sets the hover values that end up being different:
plotly.js/src/traces/histogram/calc.js
Lines 176 to 177 in 9a75ef0
[-]bins can have different start/end values on stacked histograms[/-][+]stacked histograms have different start/end values on hover [/+]antoinerg commentedon Mar 16, 2020
One possible solution is to defer the evaluation of
ph0andph1to after we're done with thecalcphase of all traces. This is what is implemented in branchfix-4648. It's rather hacky but it seems to solve the issue at hand.cc @alexcjohnson @archmoj can you have a look at it?
alexcjohnson commentedon Mar 16, 2020
Ideally things like this belong in
crossTraceCalc, though that could also be hacky sincehistogramshares that withbar. Your solution looks good, it's just better to minimize the work inhoverwhen possible.antoinerg commentedon Mar 17, 2020
I forgot that
crossTraceCalcis executed after thecalcsteps of each trace. I could definitely do the work of computingph0andph1over there. The only downside is that we will have to loop over all the bars again.I understand that we may not want to add latency to something interactive. Computing everything in advance is probably a better approach considering we don't usually have a lot of bars.
Thanks for the review @alexcjohnson
antoinerg commentedon Mar 17, 2020
Another solution using
crossTraceCalccan be found in branchfix-4648-cross. Please let me know what you think and how to improve on it!cc @alexcjohnson @archmoj
archmoj commentedon Mar 17, 2020
The https://codepen.io/nicolaskruchten/pen/BaNxYzM is fixed in your branch
fix-4648. But it is not fixed by branchfix-4648-cross.antoinerg commentedon Mar 17, 2020
Actually using the bundle from
fix-4648-cross, we only get one item when using the hover compare mode. I'm a bit puzzled as to why. Investigating now. Let me know if you have any hint!Codepen: https://codepen.io/antoinerg/pen/dyoKMZd
alexcjohnson commentedon Mar 18, 2020
@antoinerg the approach in

fix-4648-crosslooks great, though somehow it's getting a mismatch of bin positions - looks like maybefullTrace._binEdgesis for all traces but each trace may start at a different bin? Only Africa, which has the left-most bin, looks correct. Not sure why that would cause problems for getting all the other items but perhaps fixing that will resolve both?Here the box says 40-something but the cursor is at 50-something... and if you switch to
closestmode you can look at all the traces.antoinerg commentedon Mar 18, 2020
You were exactly right @alexcjohnson! Fixed in 374941b
alexcjohnson commentedon Mar 18, 2020
That'll work! I believe the index is simply offset between traces, so it might be more efficient just to store it once, something like
cd[0].t.i0but that's not a big deal.antoinerg commentedon Mar 18, 2020
Sounds good. In the end, I think I will use my first approach of preparing functions in
histogram/calc.jsand defer their evaluation until later. However, instead of doing the evaluation inhover, I would do it in thecrossTraceCalcstep. I think it results in cleaner code.antoinerg commentedon Mar 18, 2020
When deferring the evaluation of
ph0andph1, I encounter an edge case: bothleftGapandrightGapcan be zero and the rounding function then returnsNaN.@alexcjohnson I think you wrote
getBinSpanLabelRound. Is it easy to account for this edge case? Basically passing this test: c824fa3