-
-
Couldn't load subscription status.
- Fork 1.9k
Fixup weekly and quarterly period label positioning and with rangebreaks #5089
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
Changes from 2 commits
1a09b58
9fce7ad
8928851
ea6eca1
37a0840
e0bd026
6fb0133
f907f2a
fa5d2e3
b318e8b
beed352
104ae5e
7febd59
636531b
dddcaa8
b32b5a4
350a10a
50a3451
2920e31
12ce066
f47c820
c080bc5
4c10ddd
5775048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,8 +23,12 @@ var axAttrs = require('./layout_attributes'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var cleanTicks = require('./clean_ticks'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var constants = require('../../constants/numerical'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMAXYEAR = constants.ONEMAXYEAR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEAVGYEAR = constants.ONEAVGYEAR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMINYEAR = constants.ONEMINYEAR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMAXQUARTER = constants.ONEMAXQUARTER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEAVGQUARTER = constants.ONEAVGQUARTER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMINQUARTER = constants.ONEMINQUARTER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMAXMONTH = constants.ONEMAXMONTH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEAVGMONTH = constants.ONEAVGMONTH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ONEMINMONTH = constants.ONEMINMONTH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -777,20 +781,31 @@ axes.calcTicks = function calcTicks(ax, opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var A = tickVals[a].value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var B = tickVals[b].value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var delta = definedDelta || Math.abs(B - A); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(delta >= ONEDAY * 365) { // Years could have days less than ONEAVGYEAR period | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEAVGYEAR / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if(delta >= ONEAVGQUARTER) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEAVGQUARTER / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if(delta >= ONEMINMONTH) { // Months could have days less than ONEAVGMONTH period | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var actualDelta = Math.abs(B - A); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var actualDelta = Math.abs(B - A); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var delta = definedDelta || actualDelta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(delta >= ONEMINYEAR) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(actualDelta >= ONEMINYEAR && actualDelta <= ONEMAXYEAR) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += actualDelta / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEAVGYEAR / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if(delta >= ONEMINQUARTER) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
alexcjohnson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(actualDelta >= ONEMINQUARTER && actualDelta <= ONEMAXQUARTER) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += actualDelta / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEAVGQUARTER / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if(delta >= ONEMINMONTH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(actualDelta >= ONEMINMONTH && actualDelta <= ONEMAXMONTH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += actualDelta / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEAVGMONTH / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if(delta >= ONEWEEK) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v += ONEWEEK / 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(actualDelta === ONEWEEK && ax._hasDayOfWeekBreaks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v -= ONEDAY; // half of two days which is a good approximate for the number of week-end days | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(ax.rangebreaks) { | |
| // replace ticks inside breaks that would get a tick | |
| // and reduce ticks | |
| var len = tickVals.length; | |
| if(len) { | |
| var tf = 0; | |
| if(ax.tickmode === 'auto') { | |
| tf = | |
| (ax._id.charAt(0) === 'y' ? 2 : 6) * | |
| (ax.tickfont ? ax.tickfont.size : 12); | |
| } | |
| var newTickVals = []; | |
| var prevPos; | |
| var dir = axrev ? 1 : -1; | |
| var first = axrev ? 0 : len - 1; | |
| var last = axrev ? len - 1 : 0; | |
| for(var q = first; dir * q <= dir * last; q += dir) { | |
| var tickVal = tickVals[q]; | |
| if(ax.maskBreaks(tickVal.value) === BADNUM) { | |
| tickVal.value = moveOutsideBreak(tickVal.value, ax); | |
| if(ax._rl && ( | |
| ax._rl[0] === tickVal.value || | |
| ax._rl[1] === tickVal.value | |
| )) continue; | |
| } | |
| var pos = ax.c2p(tickVal.value); | |
| if(pos === prevPos) { | |
| if(newTickVals[newTickVals.length - 1].value < tickVal.value) { | |
| newTickVals[newTickVals.length - 1] = tickVal; | |
| } | |
| } else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) { | |
| prevPos = pos; | |
| newTickVals.push(tickVal); | |
| } | |
| } | |
| tickVals = newTickVals.reverse(); | |
| } | |
| } |
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.
there are still a few cases I'm worried about:
- removing just one weekend day (eg Saturday is still included, just Sunday is removed)
- weekend AND nightly breaks - the shift wouldn't be correct, and could even result in a broken tick because it lands within another rangebreak
- holidays that shorten to a 4-day work week
The only thing I can think of is perhaps figure out the actual range of the week between A and B, go to the midpoint of THAT, and then check if the result is in a break and needs further shifting. Is that possible?
Good call. I am working on a commit to help fix these cases.
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.
Addressed in f907f2a.
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.
Weekend AND nightly breaks is still a problem: https://codepen.io/alexcjohnson/pen/yLOVjJy?editors=0010

If you want to make this a separate issue and address it later, that's fine by me. If you want to go that way please file the issue and then I'll resolve this comment.
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.
Weekend AND nightly breaks is still a problem: https://codepen.io/alexcjohnson/pen/yLOVjJy?editors=0010
Good catch. This one addressed in 50a3451.
Here is a codepen.
Uh oh!
There was an error while loading. Please reload this page.