-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Match hist bins #1944
Match hist bins #1944
Conversation
src/traces/histogram/calc.js
Outdated
// with each other). | ||
// | ||
// TODO: there's probably a weird case here where a larger bin pushes the | ||
// start/end out, then it gets shrunk and doesn't make sense with the smaller bin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a small set of cases, by fixing the major problem (bin sizes getting drawn wrong) we introduce a smaller problem (bin edges get shifted so an undesirably large fraction of data is ambiguously right at bin edges). This is possible because we set minSize
and minStart
independently so they can come from different traces. The vast majority of the time though the bin edges are still positioned nicely at the end of this, and the fix would need to involve keeping minStart
based on the same trace that gave minSize
while expanding it to encompass all of these traces, which wouldn't be too hard for numeric bins but gets tricky for 'M<#>'
bins. To me then this isn't worth fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind not fixing this either. It would be nice to add a test case to document this behavior though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested in ec12eab
src/traces/histogram/calc.js
Outdated
* return an array of traces that are all stacked or grouped together | ||
* TODO: only considers histograms. Should we also harmonize with bars? | ||
* in principle people can mix and match these, but bars always | ||
* specify their positions explicitly... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try to treat bars the same as we treat manually-binned histograms in adjusting the autobins. That has more edge cases to consider though, nonuniform bar spacing being perhaps the hardest to manage, so I'm inclined not to worry about this one either. If someone is grouping/stacking bars with histograms I'd like to think it would be clear to them that they need to set the histogram binning to match the bar positions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined not to worry about this one either
No worries for me either.
src/traces/histogram/calc.js
Outdated
// the raw data was prepared in calcAllAutoBins (during the first trace in | ||
// this group) and stashed. Pull it out and drop the stash | ||
var pos0 = trace._pos0; | ||
delete trace._pos0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe calcAllAutoBins
should return a tuple e.g. [binspec, pos0]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps... we'd still need to stash _pos0
because it could be used in a totally separate call to calc
, but at least that could all be dealt with inside calcAllAutoBins
, so yeah that would be easier to understand. 👍 (unless we end up moving to setPositions
...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reorg so _pos0
is only in calcAllAutoBins
in 89093ad
src/traces/histogram/calc.js
Outdated
|
||
// all but the first trace in this group has already been marked finished | ||
// clear this flag, so next time we run calc we will run autobin again | ||
if(trace._autoBinFinished) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should move auto-bins computations to histograms/set_positions
(which loops over all traces of a given trace type) to avoid having to use _
flags like this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... maybe histogram/calc.js
should only sanitize pos
and size
values and call arraysToCalcdata
, and leave the rest to set_positions.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
histogram/calc.js
should only sanitizepos
andsize
values and callarraysToCalcdata
, and leave the rest toset_positions.js
?
Pro: that would avoid coupling between traces in a part of the code (calc
) that's supposed to be operating on one trace at a time... and set_positions
is only called after calc
(as opposed to every replot), which is when it's needed.
Con: we'd need to be saving these sanitized pos0
during calc
, rather than making an actual calcdata[i]
array - or perhaps stashing it in calcdata[i][0]
as we used to do with trace-wide stuff (and still do here and there) but then setPositions
would need to fill in the rest of calcdata[i]
once it determined the bin spec.
So I feel like in the end it would be more confusing that way. Thoughts?
Incidentally, it looks like we're probably calling setPositions
twice unnecessarily if we have both histogram and bar traces on the same plot. I'll investigate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I feel like in the end it would be more confusing that way. Thoughts?
Good point. I don't have a strong opinion. This whole calc
vs set_positions
debate was just something that came to mind, not anything blocking that's for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK cool - I'm going to leave it then, but this discussion will be useful to keep in mind for the future, I suspect at some point we will want to reimagine the whole pipeline to be a bit more flexible - particularly in regards to minimizing redraw work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incidentally, it looks like we're probably calling
setPositions
twice unnecessarily if we have both histogram and bar traces on the same plot. I'll investigate...
Yes we were. Fixed in e81fcb6 - I couldn't think of an easy way to test that we're not doing extra work, but we do have a test that this didn't break anything, in bar_and_histogram.json
. I also had it avoid even doing the setPositions
loop when there are no setPositions
functions to call.
jasmine.addMatchers(customMatchers); | ||
}); | ||
|
||
function _calc(opts, extraTraces) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR probably deserves an image test too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified test images in 3f173a4 - previously trace1 would have gotten bin size 2, so bin centers at 1 & 2 for trace0, 0.5, 2.5, and 4.5 for trace1 and displayed bar widths of 0.5. Now they all get bin size = displayed bar width = 1
also fixed a typo in the test that means... we were actually already sort of supposed to be testing the TODO about start/size interactions
src/traces/histogram/calc.js
Outdated
|
||
return trace[binAttr]; | ||
return [trace[binAttr], pos0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks!
💃 though we should probably add a few examples on https://github.com/plotly/documentation to help out users at some point. FYI @alexcjohnson, the next oldest bug is #109 but maybe I should take that one 😄 |
Haha you noticed my pattern 🥂 Some of them are getting a liiittle too old. |
This seems to generate errors when I have multiple traces. Only happens when I toggle one on/off a few times.
|
@jurasource that error looks similar to #2020 - can you confirm? |
@etpinard yes, it's the same error |
Fixes #50 and #1864
barmode
is not'overlay'
, get the same bin size and alignment