Skip to content

Commit 92864b8

Browse files
committed
more robust limiting of date dtick to 100 microseconds
1 parent c62896b commit 92864b8

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/plots/cartesian/axes.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ axes.prepTicks = function(ax) {
503503
ax.tick0 = (ax.type === 'date') ? '2000-01-01' : 0;
504504
}
505505

506+
// ensure we don't try to make ticks below our minimum precision
507+
// see https://github.com/plotly/plotly.js/issues/2892
508+
if(ax.type === 'date' && ax.dtick < 0.1) ax.dtick = 0.1;
509+
506510
// now figure out rounding of tick values
507511
autoTickRound(ax);
508512
};
@@ -692,9 +696,6 @@ axes.autoTicks = function(ax, roughDTick) {
692696
base = getBase(10);
693697
ax.dtick = roundDTick(roughDTick, base, roundBase10);
694698
}
695-
// ensure we don't try to make ticks below our minimum precision
696-
// see https://github.com/plotly/plotly.js/issues/2892
697-
if(ax.dtick < 0.1) ax.dtick = 0.1;
698699
}
699700
else if(ax.type === 'log') {
700701
ax.tick0 = 0;
@@ -788,6 +789,11 @@ function autoTickRound(ax) {
788789
// of all possible ticks - so take the max. length of tick0 and the next one
789790
var tick1len = ax.l2r(tick0ms + dtick).replace(/^-/, '').length;
790791
ax._tickround = Math.max(tick0len, tick1len) - 20;
792+
793+
// We shouldn't get here... but in case there's a situation I'm
794+
// not thinking of where tick0str and tick1str are identical or
795+
// something, fall back on maximum precision
796+
if(ax._tickround < 0) ax._tickround = 4;
791797
}
792798
}
793799
else if(isNumeric(dtick) || dtick.charAt(0) === 'L') {

test/jasmine/tests/axes_test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ describe('Test axes', function() {
20572057
expect(textOut).toEqual(expectedText);
20582058
});
20592059

2060-
it('never gives date dtick < 100 microseconds', function() {
2060+
it('never gives date dtick < 100 microseconds (autotick case)', function() {
20612061
var ax = {
20622062
type: 'date',
20632063
tickmode: 'auto',
@@ -2070,6 +2070,20 @@ describe('Test axes', function() {
20702070
expect(textOut).toEqual(expectedText);
20712071
});
20722072

2073+
it('never gives date dtick < 100 microseconds (explicit tick case)', function() {
2074+
var ax = {
2075+
type: 'date',
2076+
tickmode: 'linear',
2077+
tick0: '2000-01-01',
2078+
dtick: 0.01,
2079+
range: ['2017-02-08 05:21:18.145', '2017-02-08 05:21:18.1451']
2080+
};
2081+
2082+
var textOut = mockCalc(ax);
2083+
var expectedText = ['05:21:18.145<br>Feb 8, 2017', '05:21:18.1451'];
2084+
expect(textOut).toEqual(expectedText);
2085+
});
2086+
20732087
it('should handle edge cases with dates and tickvals', function() {
20742088
var ax = {
20752089
type: 'date',

0 commit comments

Comments
 (0)