@@ -1241,7 +1241,7 @@ function tickTextObj(ax, x, text) {
12411241
12421242function formatDate ( ax , out , hover , extraPrecision ) {
12431243 var tr = ax . _tickround ,
1244- fmt = ( hover && ax . hoverformat ) || ax . tickformat ;
1244+ fmt = ( hover && ax . hoverformat ) || axes . getTickFormat ( ax ) ;
12451245
12461246 if ( extraPrecision ) {
12471247 // second or sub-second precision: extra always shows max digits.
@@ -1406,7 +1406,7 @@ function numFormat(v, ax, fmtoverride, hover) {
14061406 tickRound = ax . _tickround ,
14071407 exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
14081408 exponent = ax . _tickexponent ,
1409- tickformat = ax . tickformat ,
1409+ tickformat = axes . getTickFormat ( ax ) ,
14101410 separatethousands = ax . separatethousands ;
14111411
14121412 // special case for hover: set exponent just for this value, and
@@ -1507,6 +1507,59 @@ function numFormat(v, ax, fmtoverride, hover) {
15071507 return v ;
15081508}
15091509
1510+ axes . getTickFormat = function ( ax ) {
1511+ function convertToMs ( dtick ) {
1512+ return typeof dtick !== 'string' ? dtick : Number ( dtick . replace ( 'M' , '' ) * ONEAVGMONTH ) ;
1513+ }
1514+ function isProperStop ( dtick , range , convert ) {
1515+ var convertFn = convert || function ( x ) { return x ; } ;
1516+ var leftDtick = range [ 0 ] ;
1517+ var rightDtick = range [ 1 ] ;
1518+ return ( ! leftDtick || convertFn ( leftDtick ) <= convertFn ( dtick ) ) &&
1519+ ( ! rightDtick || convertFn ( rightDtick ) >= convertFn ( dtick ) ) ;
1520+ }
1521+ function getRangeWidth ( range , convert ) {
1522+ var convertFn = convert || function ( x ) { return x ; } ;
1523+ var left = range [ 0 ] || 0 ;
1524+ var right = range [ 1 ] || 0 ;
1525+ return Math . abs ( convertFn ( right ) - convertFn ( left ) ) ;
1526+ }
1527+
1528+ var tickstop ;
1529+ if ( ax . tickformatstops && ax . tickformatstops . length > 0 ) {
1530+ switch ( ax . type ) {
1531+ case 'date' : {
1532+ tickstop = ax . tickformatstops . reduce ( function ( acc , stop ) {
1533+ if ( ! isProperStop ( ax . dtick , stop . dtickrange , convertToMs ) ) {
1534+ return acc ;
1535+ }
1536+ if ( ! acc ) {
1537+ return stop ;
1538+ } else {
1539+ return getRangeWidth ( stop . dtickrange , convertToMs ) > getRangeWidth ( acc . dtickrange , convertToMs ) ? stop : acc ;
1540+ }
1541+ } , null ) ;
1542+ break ;
1543+ }
1544+ case 'linear' : {
1545+ tickstop = ax . tickformatstops . reduce ( function ( acc , stop ) {
1546+ if ( ! isProperStop ( ax . dtick , stop . dtickrange ) ) {
1547+ return acc ;
1548+ }
1549+ if ( ! acc ) {
1550+ return stop ;
1551+ } else {
1552+ return getRangeWidth ( stop . dtickrange ) > getRangeWidth ( acc . dtickrange ) ? stop : acc ;
1553+ }
1554+ } , null ) ;
1555+ break ;
1556+ }
1557+ default :
1558+ }
1559+ }
1560+ return tickstop ? tickstop . value : ax . tickformat ;
1561+ } ;
1562+
15101563axes . subplotMatch = / ^ x ( [ 0 - 9 ] * ) y ( [ 0 - 9 ] * ) $ / ;
15111564
15121565// getSubplots - extract all combinations of axes we need to make plots for
0 commit comments