@@ -575,6 +575,10 @@ axes.prepTicks = function(ax, opts) {
575
575
}
576
576
}
577
577
578
+ if ( ax . ticklabelmode === 'period' ) {
579
+ adjustPeriodDelta ( ax ) ;
580
+ }
581
+
578
582
// check for missing tick0
579
583
if ( ! ax . tick0 ) {
580
584
ax . tick0 = ( ax . type === 'date' ) ? '2000-01-01' : 0 ;
@@ -592,10 +596,16 @@ function nMonths(dtick) {
592
596
return + ( dtick . substring ( 1 ) ) ;
593
597
}
594
598
595
- function adjustPeriodDelta ( ax ) { // adjusts ax.dtick and returns definedDelta
599
+ function adjustPeriodDelta ( ax ) { // adjusts ax.dtick and sets ax._definedDelta
596
600
var definedDelta ;
597
601
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 ( ) ;
599
609
var tickformat = axes . getTickFormat ( ax ) ;
600
610
if ( tickformat ) {
601
611
var noDtick = ax . _dtickInit !== ax . dtick ;
@@ -673,7 +683,13 @@ function adjustPeriodDelta(ax) { // adjusts ax.dtick and returns definedDelta
673
683
}
674
684
}
675
685
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 ;
677
693
}
678
694
679
695
function positionPeriodTicks ( tickVals , ax , definedDelta ) {
@@ -783,7 +799,6 @@ axes.calcTicks = function calcTicks(ax, opts) {
783
799
784
800
var isDLog = ( ax . type === 'log' ) && ! ( isNumeric ( ax . dtick ) || ax . dtick . charAt ( 0 ) === 'L' ) ;
785
801
var isPeriod = ax . ticklabelmode === 'period' ;
786
- var definedDelta = isPeriod ? adjustPeriodDelta ( ax ) : undefined ;
787
802
788
803
// find the first tick
789
804
ax . _tmin = axes . tickFirst ( ax , opts ) ;
@@ -843,7 +858,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
843
858
} ) ;
844
859
}
845
860
846
- if ( isPeriod ) positionPeriodTicks ( tickVals , ax , definedDelta ) ;
861
+ if ( isPeriod ) positionPeriodTicks ( tickVals , ax , ax . _definedDelta ) ;
847
862
848
863
var i ;
849
864
if ( ax . rangebreaks ) {
@@ -1030,11 +1045,16 @@ axes.autoTicks = function(ax, roughDTick) {
1030
1045
// this will also move the base tick off 2000-01-01 if dtick is
1031
1046
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
1032
1047
var tickformat = axes . getTickFormat ( ax ) ;
1048
+ var isPeriod = ax . ticklabelmode === 'period' ;
1049
+ if ( isPeriod ) ax . _rawTick0 = ax . tick0 ;
1050
+
1033
1051
if ( / % [ u V W ] / . test ( tickformat ) ) {
1034
1052
ax . tick0 = Lib . dateTick0 ( ax . calendar , 2 ) ; // Monday
1035
1053
} else {
1036
1054
ax . tick0 = Lib . dateTick0 ( ax . calendar , 1 ) ; // Sunday
1037
1055
}
1056
+
1057
+ if ( isPeriod ) ax . _dowTick0 = ax . tick0 ;
1038
1058
} else if ( roughX2 > ONEHOUR ) {
1039
1059
ax . dtick = roundDTick ( roughDTick , ONEHOUR , roundBase24 ) ;
1040
1060
} else if ( roughX2 > ONEMIN ) {
0 commit comments