Skip to content
15 changes: 12 additions & 3 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
var definedDelta;
if(isPeriod && tickformat) {
var noDtick = ax._dtickInit !== ax.dtick;
var prevDtick = ax.dtick;
if(
!(/%[fLQsSMX]/.test(tickformat))
// %f: microseconds as a decimal number [000000, 999999]
Expand Down Expand Up @@ -706,11 +707,16 @@ axes.calcTicks = function calcTicks(ax, opts) {
) ax.dtick = 'M12';
}
}

if(prevDtick !== ax.dtick) {
// move tick0 back
ax.tick0 = axes.tickIncrement(ax.tick0, prevDtick, !axrev, ax.calendar);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems problematic - if you set a specific tick0 it won't be honored? In any event I don't think we can be pushing a different value back into ax at this point, but if tickFirst needs a different effective start point perhaps we could make it an option to tickFirst?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Addressed in a4cb02b.


// redo first tick
ax._tmin = axes.tickFirst(ax, opts);
}
}

var maxTicks = Math.max(1000, ax._length || 0);
var tickVals = [];
var xPrevious = null;
var x = ax._tmin;

if(ax.rangebreaks && ax._tick0Init !== ax.tick0) {
Expand All @@ -726,6 +732,9 @@ axes.calcTicks = function calcTicks(ax, opts) {
x = axes.tickIncrement(x, ax.dtick, !axrev, ax.calendar);
}

var maxTicks = Math.max(1000, ax._length || 0);
var tickVals = [];
var xPrevious = null;
for(;
(axrev) ? (x >= endTick) : (x <= endTick);
x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)
Expand Down
47 changes: 47 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5681,6 +5681,53 @@ describe('Test axes', function() {
});
});

[
{
range: ['2019-12-10', '2020-01-10'],
positions: ['2019-12-16 12:00', '2020-01-10'],
labels: ['2019-Dec', ' ']
},
{
range: ['2019-12-20', '2020-01-20'],
positions: ['2019-12-20', '2020-01-16 12:00'],
labels: [' ', '2020-Jan']
},
{
range: ['2020-01-20', '2019-12-20'],
positions: ['2020-01-20', '2020-01-16 12:00'],
labels: [' ', '2020-Jan']
}
].forEach(function(t) {
it('should position labels with monthly tickformat when auto dtick is weekly | range:' + t.range, function(done) {
Plotly.newPlot(gd, {
data: [{
x: [
'2020-01-01',
'2020-01-02'
],
mode: 'lines+text',
text: [
'Jan 01',
'Jan 02'
]
}],
layout: {
width: 600,
xaxis: {
range: t.range,
ticklabelmode: 'period',
tickformat: '%Y-%b'
}
}
})
.then(function() {
_assert('', t.positions, t.labels);
})
.catch(failTest)
.then(done);
});
});

[
{
range: ['2020-12-15', '2084-12-15'],
Expand Down