@@ -591,7 +591,6 @@ axes.calcTicks = function calcTicks(ax, opts) {
591
591
var axrev = ( rng [ 1 ] < rng [ 0 ] ) ;
592
592
var minRange = Math . min ( rng [ 0 ] , rng [ 1 ] ) ;
593
593
var maxRange = Math . max ( rng [ 0 ] , rng [ 1 ] ) ;
594
- var dtick = ax . dtick ;
595
594
var tickformat = axes . getTickFormat ( ax ) ;
596
595
var isPeriod = ax . ticklabelmode === 'period' ;
597
596
@@ -605,10 +604,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
605
604
Math . min ( ax . _categories . length - 0.5 , endTick ) ;
606
605
}
607
606
608
- var isDLog = ( ax . type === 'log' ) && ! ( isNumeric ( dtick ) || dtick . charAt ( 0 ) === 'L' ) ;
607
+ var isDLog = ( ax . type === 'log' ) && ! ( isNumeric ( ax . dtick ) || ax . dtick . charAt ( 0 ) === 'L' ) ;
609
608
610
609
var definedDelta ;
611
610
if ( isPeriod && tickformat ) {
611
+ var noDtick = ! ! ax . _dtickInit ;
612
+
612
613
if (
613
614
! ( / % [ f L Q s S M X ] / . test ( tickformat ) )
614
615
// %f: microseconds as a decimal number [000000, 999999]
@@ -625,12 +626,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
625
626
// %I: hour (12-hour clock) as a decimal number [01,12]
626
627
) {
627
628
definedDelta = ONEHOUR ;
628
- if ( ! dtick ) dtick = ONEHOUR ;
629
+ if ( noDtick ) ax . dtick = ONEHOUR ;
629
630
} else if (
630
631
/ % p / . test ( tickformat ) // %p: either AM or PM
631
632
) {
632
633
definedDelta = HALFDAY ;
633
- if ( ! dtick ) dtick = HALFDAY ;
634
+ if ( noDtick ) ax . dtick = HALFDAY ;
634
635
} else if (
635
636
/ % [ A a d e j u w x ] / . test ( tickformat )
636
637
// %A: full weekday name
@@ -643,36 +644,36 @@ axes.calcTicks = function calcTicks(ax, opts) {
643
644
// %x: the locale’s date, such as %-m/%-d/%Y
644
645
) {
645
646
definedDelta = ONEDAY ;
646
- if ( ! dtick ) dtick = ONEDAY ;
647
+ if ( noDtick ) ax . dtick = ONEDAY ;
647
648
} else if (
648
649
/ % [ U V W ] / . test ( tickformat )
649
650
// %U: Sunday-based week of the year as a decimal number [00,53]
650
651
// %V: ISO 8601 week of the year as a decimal number [01, 53]
651
652
// %W: Monday-based week of the year as a decimal number [00,53]
652
653
) {
653
654
definedDelta = ONEWEEK ;
654
- if ( ! dtick ) dtick = ONEWEEK ;
655
+ if ( noDtick ) ax . dtick = ONEWEEK ;
655
656
} else if (
656
657
/ % [ B b m ] / . test ( tickformat )
657
658
// %B: full month name
658
659
// %b: abbreviated month name
659
660
// %m: month as a decimal number [01,12]
660
661
) {
661
662
definedDelta = ONEAVGMONTH ;
662
- if ( ! dtick ) dtick = ONEMAXMONTH ;
663
+ if ( noDtick ) ax . dtick = 'M1' ;
663
664
} else if (
664
665
/ % [ q ] / . test ( tickformat )
665
666
// %q: quarter of the year as a decimal number [1,4]
666
667
) {
667
668
definedDelta = ONEAVGQUARTER ;
668
- if ( ! dtick ) dtick = ONEMAXQUARTER ;
669
+ if ( noDtick ) ax . dtick = 'M3' ;
669
670
} else if (
670
671
/ % [ Y y ] / . test ( tickformat )
671
672
// %Y: year with century as a decimal number, such as 1999
672
673
// %y: year without century as a decimal number [00,99]
673
674
) {
674
675
definedDelta = ONEAVGYEAR ;
675
- if ( ! dtick ) dtick = ONEMAXYEAR ;
676
+ if ( noDtick ) ax . dtick = 'M12' ;
676
677
}
677
678
}
678
679
}
@@ -684,7 +685,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
684
685
tickVals = [ ] ;
685
686
for ( var x = ax . _tmin ;
686
687
( axrev ) ? ( x >= endTick ) : ( x <= endTick ) ;
687
- x = axes . tickIncrement ( x , dtick , axrev , ax . calendar ) ) {
688
+ x = axes . tickIncrement ( x , ax . dtick , axrev , ax . calendar ) ) {
688
689
// prevent infinite loops - no more than one tick per pixel,
689
690
// and make sure each value is different from the previous
690
691
if ( tickVals . length > maxTicks || x === xPrevious ) break ;
@@ -709,7 +710,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
709
710
// add one label to show pre tick0 period
710
711
tickVals . unshift ( {
711
712
minor : false ,
712
- value : axes . tickIncrement ( tickVals [ 0 ] . value , dtick , ! axrev , ax . caldendar )
713
+ value : axes . tickIncrement ( tickVals [ 0 ] . value , ax . dtick , ! axrev , ax . caldendar )
713
714
} ) ;
714
715
addedPreTick0Label = true ;
715
716
}
@@ -961,6 +962,8 @@ axes.autoTicks = function(ax, roughDTick) {
961
962
return Math . pow ( v , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
962
963
}
963
964
965
+ ax . _dtickInit = ax . dtick ;
966
+
964
967
if ( ax . type === 'date' ) {
965
968
ax . tick0 = Lib . dateTick0 ( ax . calendar , 0 ) ;
966
969
// the criteria below are all based on the rough spacing we calculate
0 commit comments