File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -503,6 +503,10 @@ axes.prepTicks = function(ax) {
503
503
ax . tick0 = ( ax . type === 'date' ) ? '2000-01-01' : 0 ;
504
504
}
505
505
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
+
506
510
// now figure out rounding of tick values
507
511
autoTickRound ( ax ) ;
508
512
} ;
@@ -785,6 +789,11 @@ function autoTickRound(ax) {
785
789
// of all possible ticks - so take the max. length of tick0 and the next one
786
790
var tick1len = ax . l2r ( tick0ms + dtick ) . replace ( / ^ - / , '' ) . length ;
787
791
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 ;
788
797
}
789
798
}
790
799
else if ( isNumeric ( dtick ) || dtick . charAt ( 0 ) === 'L' ) {
Original file line number Diff line number Diff line change @@ -2057,6 +2057,33 @@ describe('Test axes', function() {
2057
2057
expect ( textOut ) . toEqual ( expectedText ) ;
2058
2058
} ) ;
2059
2059
2060
+ it ( 'never gives date dtick < 100 microseconds (autotick case)' , function ( ) {
2061
+ var ax = {
2062
+ type : 'date' ,
2063
+ tickmode : 'auto' ,
2064
+ nticks : '100' ,
2065
+ range : [ '2017-02-08 05:21:18.145' , '2017-02-08 05:21:18.1451' ]
2066
+ } ;
2067
+
2068
+ var textOut = mockCalc ( ax ) ;
2069
+ var expectedText = [ '05:21:18.145<br>Feb 8, 2017' , '05:21:18.1451' ] ;
2070
+ expect ( textOut ) . toEqual ( expectedText ) ;
2071
+ } ) ;
2072
+
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
+
2060
2087
it ( 'should handle edge cases with dates and tickvals' , function ( ) {
2061
2088
var ax = {
2062
2089
type : 'date' ,
You can’t perform that action at this time.
0 commit comments