Skip to content

Commit d61dee5

Browse files
committed
fix handling monthly dticks e.g. M3 < M12
1 parent 5d8b0e0 commit d61dee5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/plots/cartesian/axes.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ axes.prepTicks = function(ax, opts) {
571571
autoTickRound(ax);
572572
};
573573

574+
function nMonths(dtick) {
575+
return +(dtick.substring(1));
576+
}
577+
574578
// calculate the ticks: text, values, positioning
575579
// if ticks are set to automatic, determine the right values (tick0,dtick)
576580
// in any case, set tickround to # of digits to round tick labels to,
@@ -663,20 +667,26 @@ axes.calcTicks = function calcTicks(ax, opts) {
663667
// %m: month as a decimal number [01,12]
664668
) {
665669
definedDelta = ONEAVGMONTH;
666-
if(noDtick && ax.dtick < (isMDate ? 'M1' : ONEMINMONTH)) ax.dtick = 'M1';
670+
if(noDtick && (
671+
isMDate ? nMonths(ax.dtick) < 1 : ax.dtick < ONEMINMONTH)
672+
) ax.dtick = 'M1';
667673
} else if(
668674
/%[q]/.test(tickformat)
669675
// %q: quarter of the year as a decimal number [1,4]
670676
) {
671677
definedDelta = ONEAVGQUARTER;
672-
if(noDtick && ax.dtick < (isMDate ? 'M3' : ONEMINQUARTER)) ax.dtick = 'M3';
678+
if(noDtick && (
679+
isMDate ? nMonths(ax.dtick) < 3 : ax.dtick < ONEMINQUARTER)
680+
) ax.dtick = 'M3';
673681
} else if(
674682
/%[Yy]/.test(tickformat)
675683
// %Y: year with century as a decimal number, such as 1999
676684
// %y: year without century as a decimal number [00,99]
677685
) {
678686
definedDelta = ONEAVGYEAR;
679-
if(noDtick && ax.dtick < (isMDate ? 'M12' : ONEMINYEAR)) ax.dtick = 'M12';
687+
if(noDtick && (
688+
isMDate ? nMonths(ax.dtick) < 12 : ax.dtick < ONEMINYEAR)
689+
) ax.dtick = 'M12';
680690
}
681691
}
682692
}

0 commit comments

Comments
 (0)