Skip to content
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

Improve positioning of rangebreaks #4698

Merged
merged 11 commits into from
Mar 28, 2020
119 changes: 57 additions & 62 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,70 +723,65 @@ module.exports = function setConvert(ax, fullLayout) {

if(brk.enabled) {
if(brk.bounds) {
var t0 = r0;
var t1 = r1;
if(brk.pattern) {
bnds = Lib.simpleMap(brk.bounds, cleanNumber);

// r0 value as date
var r0Date = new Date(r0);
// r0 value for break pattern
var r0Pattern;
// delta between r0 and first break in break pattern values
var r0PatternDelta;
// delta between break bounds in ms
var bndDelta;
// step in ms between rangebreaks
var step;
// tracker to position bounds
var t;

switch(brk.pattern) {
case WEEKDAY_PATTERN:
b0 = bnds[0];
b1 = bnds[1];
r0Pattern = r0Date.getUTCDay();
r0PatternDelta = b0 - r0Pattern;
bndDelta = (b1 >= b0 ? b1 - b0 : (b1 + 7) - b0) * ONEDAY;
step = 7 * ONEDAY;

t = r0 + r0PatternDelta * ONEDAY -
r0Date.getUTCHours() * ONEHOUR -
r0Date.getUTCMinutes() * ONEMIN -
r0Date.getUTCSeconds() * ONESEC -
r0Date.getUTCMilliseconds();
break;
case HOUR_PATTERN:
b0 = bnds[0];
b1 = bnds[1];
r0Pattern = r0Date.getUTCHours();
r0PatternDelta = b0 - r0Pattern;
bndDelta = (b1 >= b0 ? b1 - b0 : (b1 + 24) - b0) * ONEHOUR;
step = ONEDAY;

t = r0 + r0PatternDelta * ONEHOUR -
r0Date.getUTCMinutes() * ONEMIN -
r0Date.getUTCSeconds() * ONESEC -
r0Date.getUTCMilliseconds();
break;
}
// to remove decimal (most often found in auto ranges)
t0 = Math.floor(t0);
}

while(t <= r1) {
// TODO we need to remove decimal (most often found
// in auto ranges) for this to work correctly,
// should this be Math.floor, Math.ceil or
// Math.round ??
addBreak(Math.floor(t), Math.floor(t + bndDelta));
t += step;
}
} else {
bnds = Lib.simpleMap(brk.bounds, ax.r2l);
if(bnds[0] <= bnds[1]) {
b0 = bnds[0];
b1 = bnds[1];
} else {
b0 = bnds[1];
b1 = bnds[0];
}
addBreak(b0, b1);
bnds = Lib.simpleMap(brk.bounds, brk.pattern ? cleanNumber : ax.r2l);
b0 = bnds[0];
b1 = bnds[1];

// r0 value as date
var t0Date = new Date(t0);
// r0 value for break pattern
var bndDelta;
// step in ms between rangebreaks
var step;

switch(brk.pattern) {
case WEEKDAY_PATTERN:
step = 7 * ONEDAY;

bndDelta = (
(b1 < b0 ? 7 : 0) +
(b1 - b0)
) * ONEDAY;

t0 += b0 * ONEDAY - (
t0Date.getUTCDay() * ONEDAY +
t0Date.getUTCHours() * ONEHOUR +
t0Date.getUTCMinutes() * ONEMIN +
t0Date.getUTCSeconds() * ONESEC +
t0Date.getUTCMilliseconds()
);
break;
case HOUR_PATTERN:
step = ONEDAY;

bndDelta = (
(b1 < b0 ? 24 : 0) +
(b1 - b0)
) * ONEHOUR;

t0 += b0 * ONEHOUR - (
t0Date.getUTCHours() * ONEHOUR +
t0Date.getUTCMinutes() * ONEMIN +
t0Date.getUTCSeconds() * ONESEC +
t0Date.getUTCMilliseconds()
);
break;
default:
t0 = Math.min(bnds[0], bnds[1]);
t1 = Math.max(bnds[0], bnds[1]);
step = t1 - t0;
bndDelta = step;
}

for(var t = t0; t < t1; t += step) {
addBreak(t, t + bndDelta);
}
} else {
var vals = Lib.simpleMap(brk.values, ax.d2c);
Expand Down
Binary file modified test/image/baselines/axes_breaks-night_autorange-reversed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.