@@ -850,7 +850,8 @@ function autoTickRound(ax) {
850850 // not necessarily *all* the information in tick0 though, if it's really odd
851851 // minimal string length for tick0: 'd' is 10, 'M' is 16, 'S' is 19
852852 // take off a leading minus (year < 0 so length is consistent)
853- var tick0str = Lib . ms2DateTime ( Lib . dateTime2ms ( ax . tick0 ) ) . replace ( / ^ - / , '' ) ,
853+ var tick0ms = Lib . dateTime2ms ( ax . tick0 ) ,
854+ tick0str = Lib . ms2DateTime ( tick0ms ) . replace ( / ^ - / , '' ) ,
854855 tick0len = tick0str . length ;
855856
856857 if ( String ( dtick ) . charAt ( 0 ) === 'M' ) {
@@ -862,7 +863,12 @@ function autoTickRound(ax) {
862863 else if ( ( dtick >= ONEDAY && tick0len <= 10 ) || ( dtick >= ONEDAY * 15 ) ) ax . _tickround = 'd' ;
863864 else if ( ( dtick >= ONEMIN && tick0len <= 16 ) || ( dtick >= ONEHOUR ) ) ax . _tickround = 'M' ;
864865 else if ( ( dtick >= ONESEC && tick0len <= 19 ) || ( dtick >= ONEMIN ) ) ax . _tickround = 'S' ;
865- else ax . _tickround = Math . max ( 3 - Math . round ( Math . log ( dtick / 2 ) / Math . LN10 ) , tick0len - 20 ) ;
866+ else {
867+ // of any two adjacent ticks, at least one will have the maximum fractional digits
868+ // of all possible ticks - so take the max. length of tick0 and the next one
869+ var tick1len = Lib . ms2DateTime ( tick0ms + dtick ) . replace ( / ^ - / , '' ) . length ;
870+ ax . _tickround = Math . max ( tick0len , tick1len ) - 20 ;
871+ }
866872 }
867873 else if ( isNumeric ( dtick ) || dtick . charAt ( 0 ) === 'L' ) {
868874 // linear or log (except D1, D2)
@@ -1112,7 +1118,7 @@ function formatDate(ax, out, hover, extraPrecision) {
11121118 if ( tr !== 'M' ) {
11131119 tt += secondFormat ( d ) ;
11141120 if ( tr !== 'S' ) {
1115- tt += numFormat ( mod ( x / 1000 , 1 ) , ax , 'none' , hover )
1121+ tt += numFormat ( d3 . round ( mod ( x / 1000 , 1 ) , 4 ) , ax , 'none' , hover )
11161122 . substr ( 1 ) ;
11171123 }
11181124 }
0 commit comments