Skip to content

Commit a4a8f4a

Browse files
committed
address issue #4697 - avoid rounding errors
1 parent 4f1f9cf commit a4a8f4a

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/plots/cartesian/set_convert.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -723,20 +723,24 @@ module.exports = function setConvert(ax, fullLayout) {
723723

724724
if(brk.enabled) {
725725
if(brk.bounds) {
726+
var t0 = r0;
727+
var t1 = r1;
728+
if(brk.pattern) {
729+
// to remove decimal (most often found in auto ranges)
730+
t0 = Math.floor(t0);
731+
}
732+
726733
bnds = Lib.simpleMap(brk.bounds, brk.pattern ? cleanNumber : ax.r2l);
727734
b0 = bnds[0];
728735
b1 = bnds[1];
729736

730737
// r0 value as date
731-
var r0Date = new Date(r0);
738+
var t0Date = new Date(t0);
732739
// r0 value for break pattern
733740
var bndDelta;
734741
// step in ms between rangebreaks
735742
var step;
736743

737-
var t0 = r0;
738-
var t1 = r1;
739-
740744
switch(brk.pattern) {
741745
case WEEKDAY_PATTERN:
742746
step = 7 * ONEDAY;
@@ -747,11 +751,11 @@ module.exports = function setConvert(ax, fullLayout) {
747751
) * ONEDAY;
748752

749753
t0 += b0 * ONEDAY - (
750-
r0Date.getUTCDay() * ONEDAY +
751-
r0Date.getUTCHours() * ONEHOUR +
752-
r0Date.getUTCMinutes() * ONEMIN +
753-
r0Date.getUTCSeconds() * ONESEC +
754-
r0Date.getUTCMilliseconds()
754+
t0Date.getUTCDay() * ONEDAY +
755+
t0Date.getUTCHours() * ONEHOUR +
756+
t0Date.getUTCMinutes() * ONEMIN +
757+
t0Date.getUTCSeconds() * ONESEC +
758+
t0Date.getUTCMilliseconds()
755759
);
756760
break;
757761
case HOUR_PATTERN:
@@ -763,10 +767,10 @@ module.exports = function setConvert(ax, fullLayout) {
763767
) * ONEHOUR;
764768

765769
t0 += b0 * ONEHOUR - (
766-
r0Date.getUTCHours() * ONEHOUR +
767-
r0Date.getUTCMinutes() * ONEMIN +
768-
r0Date.getUTCSeconds() * ONESEC +
769-
r0Date.getUTCMilliseconds()
770+
t0Date.getUTCHours() * ONEHOUR +
771+
t0Date.getUTCMinutes() * ONEMIN +
772+
t0Date.getUTCSeconds() * ONESEC +
773+
t0Date.getUTCMilliseconds()
770774
);
771775
break;
772776
default:
@@ -776,11 +780,6 @@ module.exports = function setConvert(ax, fullLayout) {
776780
bndDelta = step;
777781
}
778782

779-
if(brk.pattern) {
780-
// to remove decimal (most often found in auto ranges)
781-
t0 = Math.floor(t0);
782-
}
783-
784783
for(var t = t0; t < t1; t += step) {
785784
addBreak(t, t + bndDelta);
786785
}
Loading

0 commit comments

Comments
 (0)