Repository navigation
Date bin shift - #1201
Date bin shift#1201
Conversation
to avoid all data lying ambiguously on bin edges
some environments accept non-integer date parts, some don't.
| * and ticks on these days incrementing by month would be very unusual | ||
| */ | ||
| var y = new Date(x + THREEDAYS); | ||
| return y.setUTCMonth(y.getUTCMonth() + dtSigned) - THREEDAYS; |
There was a problem hiding this comment.
@etpinard FYI - this is a slightly breaking change... if anyone explicitly asked for n-month ticks starting on the 26th, 27th, or 28th of a month and the ticks continue past a February, subsequent ticks will be shifted to the last few days of subsequent months. I think it's fairly unlikely this has ever been done, and even if it has it was probably in order to put ticks near the end of the month rather than on that specific date.
Anyway I think the advantages far outweigh this risk.
- month ticks will never accidentally shift into the wrong month, even if, as a result of this change, they will sometimes change dates (which they did before anyway)
- you can now put ticks in the last couple of days of the month and have them stay there.
It's probably not clear from this comment why I did this in this PR: I needed it for month bins with exactDay data, where the first bin should start 12 hours before the beginning of each month.
There was a problem hiding this comment.
Anyway I think the advantages far outweigh this risk.
👍
| var distinctData = Lib.distinctVals(data), | ||
| msexp = Math.pow(10, Math.floor( | ||
| Math.log(distinctData.minDiff) / Math.LN10)), | ||
| // TODO: there are some date cases where this will fail... |
There was a problem hiding this comment.
removed because I have no idea anymore what this was about. We'll wait for a bug report...
| // the display makes them linear (using only y0 and dy) | ||
| // when we sort out https://github.com/plotly/plotly.js/issues/1151 | ||
| // lets also make it display the bins with nonuniform size | ||
| // Can we also make it display the bins with nonuniform size? |
There was a problem hiding this comment.
Removed from the scope of this PR because it turned out to be more of a pain than I thought, and it's a really minor effect visually.
| // TODO: this gives half-day gaps between all but the first two | ||
| // bars. Now that we have explicit per-bar positioning, perhaps | ||
| // we should fill the space, rather than insisting on equal-width | ||
| // bars? |
There was a problem hiding this comment.
This effect is a little more important than getting the exact right bin sizes in the 2D case, because here it leads to visible gaps between many of the bars. Unfortunately it's also quite a bit more effort to solve when you consider stacked or grouped traces. Worth making an issue for it?
| binEnd = binStart + bincount * dummyAx.dtick; | ||
| } | ||
| else { | ||
| // month ticks - should be the only nonlinear kind we have at this point. |
There was a problem hiding this comment.
... after traces/histogram/clean_bins.js that is, correct?
There was a problem hiding this comment.
This is only relevant to auto-binning, where nonlinear ticks are dtick values... dtick only has special meaning on date axes (where 'M<n>' is n-months) and on log axes, but when you display a histogram on log axes we still bin on a linear scale.
|
|
||
| // unmber of data points that needs to be an exact value | ||
| // to shift that increment to (near) the bin center | ||
| var threshold = 0.8 * dataCount; |
There was a problem hiding this comment.
non- ⛔ It would be nice to put these auto-algo threshold fractions in a constants.js file somewhere. It's not obvious where that file should be though.
There was a problem hiding this comment.
Alright, I'll leave this as is for now but I'm happy to change it if you tell me where to put them. I don't have a good feel for what would make this easy to grok.
There was a problem hiding this comment.
No action required in this PR.
| * and ticks on these days incrementing by month would be very unusual | ||
| */ | ||
| var y = new Date(x + THREEDAYS); | ||
| return y.setUTCMonth(y.getUTCMonth() + dtSigned) - THREEDAYS; |
There was a problem hiding this comment.
Anyway I think the advantages far outweigh this risk.
👍
| // first row of z below) | ||
| expect(out.y0).toBe('1969-07-02 14:24'); | ||
| expect(out.dy).toBe(365.2 * oneDay); | ||
| // Can we also make it display the bins with nonuniform size? |
Fixes #1151
Implements an auto-shifting algorithm for nonuniform (n-month) bins in date histograms. Covers 3 cases:
A couple of comments