@@ -591,7 +591,6 @@ axes.calcTicks = function calcTicks(ax, opts) {
591591 var axrev = ( rng [ 1 ] < rng [ 0 ] ) ;
592592 var minRange = Math . min ( rng [ 0 ] , rng [ 1 ] ) ;
593593 var maxRange = Math . max ( rng [ 0 ] , rng [ 1 ] ) ;
594- var dtick = ax . dtick ;
595594 var tickformat = axes . getTickFormat ( ax ) ;
596595 var isPeriod = ax . ticklabelmode === 'period' ;
597596
@@ -605,10 +604,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
605604 Math . min ( ax . _categories . length - 0.5 , endTick ) ;
606605 }
607606
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' ) ;
609608
610609 var definedDelta ;
611610 if ( isPeriod && tickformat ) {
611+ var noDtick = ! ! ax . _dtickInit ;
612+
612613 if (
613614 ! ( / % [ f L Q s S M X ] / . test ( tickformat ) )
614615 // %f: microseconds as a decimal number [000000, 999999]
@@ -625,12 +626,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
625626 // %I: hour (12-hour clock) as a decimal number [01,12]
626627 ) {
627628 definedDelta = ONEHOUR ;
628- if ( ! dtick ) dtick = ONEHOUR ;
629+ if ( noDtick ) ax . dtick = ONEHOUR ;
629630 } else if (
630631 / % p / . test ( tickformat ) // %p: either AM or PM
631632 ) {
632633 definedDelta = HALFDAY ;
633- if ( ! dtick ) dtick = HALFDAY ;
634+ if ( noDtick ) ax . dtick = HALFDAY ;
634635 } else if (
635636 / % [ A a d e j u w x ] / . test ( tickformat )
636637 // %A: full weekday name
@@ -643,36 +644,36 @@ axes.calcTicks = function calcTicks(ax, opts) {
643644 // %x: the locale’s date, such as %-m/%-d/%Y
644645 ) {
645646 definedDelta = ONEDAY ;
646- if ( ! dtick ) dtick = ONEDAY ;
647+ if ( noDtick ) ax . dtick = ONEDAY ;
647648 } else if (
648649 / % [ U V W ] / . test ( tickformat )
649650 // %U: Sunday-based week of the year as a decimal number [00,53]
650651 // %V: ISO 8601 week of the year as a decimal number [01, 53]
651652 // %W: Monday-based week of the year as a decimal number [00,53]
652653 ) {
653654 definedDelta = ONEWEEK ;
654- if ( ! dtick ) dtick = ONEWEEK ;
655+ if ( noDtick ) ax . dtick = ONEWEEK ;
655656 } else if (
656657 / % [ B b m ] / . test ( tickformat )
657658 // %B: full month name
658659 // %b: abbreviated month name
659660 // %m: month as a decimal number [01,12]
660661 ) {
661662 definedDelta = ONEAVGMONTH ;
662- if ( ! dtick ) dtick = ONEMAXMONTH ;
663+ if ( noDtick ) ax . dtick = 'M1' ;
663664 } else if (
664665 / % [ q ] / . test ( tickformat )
665666 // %q: quarter of the year as a decimal number [1,4]
666667 ) {
667668 definedDelta = ONEAVGQUARTER ;
668- if ( ! dtick ) dtick = ONEMAXQUARTER ;
669+ if ( noDtick ) ax . dtick = 'M3' ;
669670 } else if (
670671 / % [ Y y ] / . test ( tickformat )
671672 // %Y: year with century as a decimal number, such as 1999
672673 // %y: year without century as a decimal number [00,99]
673674 ) {
674675 definedDelta = ONEAVGYEAR ;
675- if ( ! dtick ) dtick = ONEMAXYEAR ;
676+ if ( noDtick ) ax . dtick = 'M12' ;
676677 }
677678 }
678679 }
@@ -684,7 +685,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
684685 tickVals = [ ] ;
685686 for ( var x = ax . _tmin ;
686687 ( axrev ) ? ( x >= endTick ) : ( x <= endTick ) ;
687- x = axes . tickIncrement ( x , dtick , axrev , ax . calendar ) ) {
688+ x = axes . tickIncrement ( x , ax . dtick , axrev , ax . calendar ) ) {
688689 // prevent infinite loops - no more than one tick per pixel,
689690 // and make sure each value is different from the previous
690691 if ( tickVals . length > maxTicks || x === xPrevious ) break ;
@@ -709,7 +710,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
709710 // add one label to show pre tick0 period
710711 tickVals . unshift ( {
711712 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 )
713714 } ) ;
714715 addedPreTick0Label = true ;
715716 }
@@ -961,6 +962,8 @@ axes.autoTicks = function(ax, roughDTick) {
961962 return Math . pow ( v , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
962963 }
963964
965+ ax . _dtickInit = ax . dtick ;
966+
964967 if ( ax . type === 'date' ) {
965968 ax . tick0 = Lib . dateTick0 ( ax . calendar , 0 ) ;
966969 // the criteria below are all based on the rough spacing we calculate
0 commit comments