Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ axes.prepTicks = function(ax) {
ax.tick0 = (ax.type === 'date') ? '2000-01-01' : 0;
}

// ensure we don't try to make ticks below our minimum precision
// see https://github.com/plotly/plotly.js/issues/2892
if(ax.type === 'date' && ax.dtick < 0.1) ax.dtick = 0.1;

// now figure out rounding of tick values
autoTickRound(ax);
};
Expand Down Expand Up @@ -785,6 +789,11 @@ function autoTickRound(ax) {
// of all possible ticks - so take the max. length of tick0 and the next one
var tick1len = ax.l2r(tick0ms + dtick).replace(/^-/, '').length;
ax._tickround = Math.max(tick0len, tick1len) - 20;

// We shouldn't get here... but in case there's a situation I'm
// not thinking of where tick0str and tick1str are identical or
// something, fall back on maximum precision
if(ax._tickround < 0) ax._tickround = 4;
}
}
else if(isNumeric(dtick) || dtick.charAt(0) === 'L') {
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,33 @@ describe('Test axes', function() {
expect(textOut).toEqual(expectedText);
});

it('never gives date dtick < 100 microseconds (autotick case)', function() {
var ax = {
type: 'date',
tickmode: 'auto',
nticks: '100',
range: ['2017-02-08 05:21:18.145', '2017-02-08 05:21:18.1451']
};

var textOut = mockCalc(ax);
var expectedText = ['05:21:18.145<br>Feb 8, 2017', '05:21:18.1451'];
expect(textOut).toEqual(expectedText);
});

it('never gives date dtick < 100 microseconds (explicit tick case)', function() {
var ax = {
type: 'date',
tickmode: 'linear',
tick0: '2000-01-01',
dtick: 0.01,
range: ['2017-02-08 05:21:18.145', '2017-02-08 05:21:18.1451']
};

var textOut = mockCalc(ax);
var expectedText = ['05:21:18.145<br>Feb 8, 2017', '05:21:18.1451'];
expect(textOut).toEqual(expectedText);
});

it('should handle edge cases with dates and tickvals', function() {
var ax = {
type: 'date',
Expand Down