@@ -575,6 +575,10 @@ axes.prepTicks = function(ax, opts) {
575575 }
576576 }
577577
578+ if ( ax . ticklabelmode === 'period' ) {
579+ adjustPeriodDelta ( ax ) ;
580+ }
581+
578582 // check for missing tick0
579583 if ( ! ax . tick0 ) {
580584 ax . tick0 = ( ax . type === 'date' ) ? '2000-01-01' : 0 ;
@@ -592,10 +596,16 @@ function nMonths(dtick) {
592596 return + ( dtick . substring ( 1 ) ) ;
593597}
594598
595- function adjustPeriodDelta ( ax ) { // adjusts ax.dtick and returns definedDelta
599+ function adjustPeriodDelta ( ax ) { // adjusts ax.dtick and sets ax._definedDelta
596600 var definedDelta ;
597601
598- var isMDate = ( ax . type === 'date' ) && ! ( isNumeric ( ax . dtick ) || ax . dtick . charAt ( 0 ) === 'M' ) ;
602+ function mDate ( ) {
603+ return ! (
604+ isNumeric ( ax . dtick ) ||
605+ ax . dtick . charAt ( 0 ) !== 'M'
606+ ) ;
607+ }
608+ var isMDate = mDate ( ) ;
599609 var tickformat = axes . getTickFormat ( ax ) ;
600610 if ( tickformat ) {
601611 var noDtick = ax . _dtickInit !== ax . dtick ;
@@ -673,7 +683,13 @@ function adjustPeriodDelta(ax) { // adjusts ax.dtick and returns definedDelta
673683 }
674684 }
675685
676- return definedDelta ;
686+ isMDate = mDate ( ) ;
687+ if ( isMDate && ax . tick0 === ax . _dowTick0 ) {
688+ // discard Sunday/Monday tweaks
689+ ax . tick0 = ax . _rawTick0 ;
690+ }
691+
692+ ax . _definedDelta = definedDelta ;
677693}
678694
679695function positionPeriodTicks ( tickVals , ax , definedDelta ) {
@@ -783,7 +799,6 @@ axes.calcTicks = function calcTicks(ax, opts) {
783799
784800 var isDLog = ( ax . type === 'log' ) && ! ( isNumeric ( ax . dtick ) || ax . dtick . charAt ( 0 ) === 'L' ) ;
785801 var isPeriod = ax . ticklabelmode === 'period' ;
786- var definedDelta = isPeriod ? adjustPeriodDelta ( ax ) : undefined ;
787802
788803 // find the first tick
789804 ax . _tmin = axes . tickFirst ( ax , opts ) ;
@@ -843,7 +858,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
843858 } ) ;
844859 }
845860
846- if ( isPeriod ) positionPeriodTicks ( tickVals , ax , definedDelta ) ;
861+ if ( isPeriod ) positionPeriodTicks ( tickVals , ax , ax . _definedDelta ) ;
847862
848863 var i ;
849864 if ( ax . rangebreaks ) {
@@ -1030,11 +1045,16 @@ axes.autoTicks = function(ax, roughDTick) {
10301045 // this will also move the base tick off 2000-01-01 if dtick is
10311046 // 2 or 3 days... but that's a weird enough case that we'll ignore it.
10321047 var tickformat = axes . getTickFormat ( ax ) ;
1048+ var isPeriod = ax . ticklabelmode === 'period' ;
1049+ if ( isPeriod ) ax . _rawTick0 = ax . tick0 ;
1050+
10331051 if ( / % [ u V W ] / . test ( tickformat ) ) {
10341052 ax . tick0 = Lib . dateTick0 ( ax . calendar , 2 ) ; // Monday
10351053 } else {
10361054 ax . tick0 = Lib . dateTick0 ( ax . calendar , 1 ) ; // Sunday
10371055 }
1056+
1057+ if ( isPeriod ) ax . _dowTick0 = ax . tick0 ;
10381058 } else if ( roughX2 > ONEHOUR ) {
10391059 ax . dtick = roundDTick ( roughDTick , ONEHOUR , roundBase24 ) ;
10401060 } else if ( roughX2 > ONEMIN ) {
0 commit comments