Skip to content

Commit bcf2a71

Browse files
committed
move adjustPeriodDelta logic to prepTicks and discard sunday/monday tweaks on monthly dticks
1 parent b78a80b commit bcf2a71

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/plots/cartesian/axes.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

679695
function 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(/%[uVW]/.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) {

test/jasmine/tests/axes_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5684,17 +5684,17 @@ describe('Test axes', function() {
56845684
[
56855685
{
56865686
range: ['2019-12-10', '2020-01-10'],
5687-
positions: ['2019-12-17 12:00', '2020-01-10'],
5687+
positions: ['2019-12-16 12:00', '2020-01-10'],
56885688
labels: ['2019-Dec', ' ']
56895689
},
56905690
{
56915691
range: ['2019-12-20', '2020-01-20'],
5692-
positions: ['2019-12-20', '2020-01-17 12:00'],
5692+
positions: ['2019-12-20', '2020-01-16 12:00'],
56935693
labels: [' ', '2020-Jan']
56945694
},
56955695
{
56965696
range: ['2020-01-20', '2019-12-20'],
5697-
positions: ['2020-01-20', '2020-01-17 12:00'],
5697+
positions: ['2020-01-20', '2020-01-16 12:00'],
56985698
labels: [' ', '2020-Jan']
56995699
}
57005700
].forEach(function(t) {

0 commit comments

Comments
 (0)