Skip to content

stacked histograms have different start/end values on hover #4648

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

Closed
nicolaskruchten opened this issue Mar 16, 2020 · 16 comments · Fixed by #4662
Closed

stacked histograms have different start/end values on hover #4648

nicolaskruchten opened this issue Mar 16, 2020 · 16 comments · Fixed by #4662
Assignees
Labels
bug something broken
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

https://codepen.io/nicolaskruchten/pen/BaNxYzM

This is weird:

image

@nicolaskruchten nicolaskruchten added this to the v1.53.0 milestone Mar 16, 2020
@alexcjohnson
Copy link
Collaborator

FWIW this happens with regular split hover as well -
Screen Shot 2020-03-16 at 9 56 51 AM

@alexcjohnson
Copy link
Collaborator

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.
Screen Shot 2020-03-16 at 10 04 17 AM

@archmoj
Copy link
Contributor

archmoj commented Mar 16, 2020

@alexcjohnson is this a bug?

@alexcjohnson
Copy link
Collaborator

Yes, bug. I forget how that calculation works but whatever it does should be shared by all traces in a group or stack.

@archmoj archmoj added the bug something broken label Mar 16, 2020
@antoinerg antoinerg changed the title Unified hover x values on stacked histograms bins can different start/end values on stacked histograms Mar 16, 2020
@antoinerg antoinerg changed the title bins can different start/end values on stacked histograms bins can have different start/end values on stacked histograms Mar 16, 2020
@antoinerg
Copy link
Contributor

antoinerg commented 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:

for(i = 0; i < pos0.length; i++) {
var posi = pos0[i];
n = Lib.findBin(posi, bins);
if(n >= 0 && n < nMax) {
total += binFunc(n, i, size, rawCounterData, counts);
if(uniqueValsPerBin && inputPoints[n].length && posi !== pos0[inputPoints[n][0]]) {
uniqueValsPerBin = false;
}
inputPoints[n].push(i);
ptNumber2cdIndex[i] = n;
leftGap = Math.min(leftGap, posi - binEdges[n]);
rightGap = Math.min(rightGap, binEdges[n + 1] - posi);
}
}
var roundFn;
if(!uniqueValsPerBin) {
roundFn = getBinSpanLabelRound(leftGap, rightGap, binEdges, pa, calendar);
}

which then sets the hover values that end up being different:

cdi.ph0 = roundFn(binEdges[i]);
cdi.ph1 = roundFn(binEdges[i + 1], true);

@antoinerg antoinerg changed the title bins can have different start/end values on stacked histograms stacked histograms have different start/end values on hover Mar 16, 2020
@antoinerg antoinerg assigned antoinerg and unassigned antoinerg Mar 16, 2020
@antoinerg
Copy link
Contributor

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.

cc @alexcjohnson @archmoj can you have a look at it?

@alexcjohnson
Copy link
Collaborator

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.

@antoinerg
Copy link
Contributor

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.

Thanks for the review @alexcjohnson

@antoinerg
Copy link
Contributor

Another solution using crossTraceCalc can be found in branch fix-4648-cross. Please let me know what you think and how to improve on it!

cc @alexcjohnson @archmoj

@archmoj
Copy link
Contributor

archmoj commented Mar 17, 2020

The https://codepen.io/nicolaskruchten/pen/BaNxYzM is fixed in your branch fix-4648. But it is not fixed by branch fix-4648-cross .

@antoinerg
Copy link
Contributor

antoinerg commented Mar 17, 2020

The https://codepen.io/nicolaskruchten/pen/BaNxYzM is fixed in your branch fix-4648. But it is not fixed by branch fix-4648-cross .

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
Copy link
Collaborator

alexcjohnson commented Mar 18, 2020

@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.
Screen Shot 2020-03-17 at 9 42 29 PM

@antoinerg
Copy link
Contributor

looks like maybe fullTrace._binEdges is for all traces but each trace may start at a different bin?

You were exactly right @alexcjohnson! Fixed in 374941b

@alexcjohnson
Copy link
Collaborator

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.

@antoinerg
Copy link
Contributor

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.

@antoinerg
Copy link
Contributor

antoinerg commented Mar 18, 2020

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

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 a pull request may close this issue.

4 participants