Skip to content

Commit

Permalink
address issue #4697 - avoid rounding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Mar 28, 2020
1 parent 4f1f9cf commit a4a8f4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,20 +723,24 @@ module.exports = function setConvert(ax, fullLayout) {

if(brk.enabled) {
if(brk.bounds) {
var t0 = r0;
var t1 = r1;
if(brk.pattern) {
// to remove decimal (most often found in auto ranges)
t0 = Math.floor(t0);
}

bnds = Lib.simpleMap(brk.bounds, brk.pattern ? cleanNumber : ax.r2l);
b0 = bnds[0];
b1 = bnds[1];

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

var t0 = r0;
var t1 = r1;

switch(brk.pattern) {
case WEEKDAY_PATTERN:
step = 7 * ONEDAY;
Expand All @@ -747,11 +751,11 @@ module.exports = function setConvert(ax, fullLayout) {
) * ONEDAY;

t0 += b0 * ONEDAY - (
r0Date.getUTCDay() * ONEDAY +
r0Date.getUTCHours() * ONEHOUR +
r0Date.getUTCMinutes() * ONEMIN +
r0Date.getUTCSeconds() * ONESEC +
r0Date.getUTCMilliseconds()
t0Date.getUTCDay() * ONEDAY +
t0Date.getUTCHours() * ONEHOUR +
t0Date.getUTCMinutes() * ONEMIN +
t0Date.getUTCSeconds() * ONESEC +
t0Date.getUTCMilliseconds()
);
break;
case HOUR_PATTERN:
Expand All @@ -763,10 +767,10 @@ module.exports = function setConvert(ax, fullLayout) {
) * ONEHOUR;

t0 += b0 * ONEHOUR - (
r0Date.getUTCHours() * ONEHOUR +
r0Date.getUTCMinutes() * ONEMIN +
r0Date.getUTCSeconds() * ONESEC +
r0Date.getUTCMilliseconds()
t0Date.getUTCHours() * ONEHOUR +
t0Date.getUTCMinutes() * ONEMIN +
t0Date.getUTCSeconds() * ONESEC +
t0Date.getUTCMilliseconds()
);
break;
default:
Expand All @@ -776,11 +780,6 @@ module.exports = function setConvert(ax, fullLayout) {
bndDelta = step;
}

if(brk.pattern) {
// to remove decimal (most often found in auto ranges)
t0 = Math.floor(t0);
}

for(var t = t0; t < t1; t += step) {
addBreak(t, t + bndDelta);
}
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.

0 comments on commit a4a8f4a

Please sign in to comment.