@@ -1232,7 +1232,7 @@ function tickTextObj(ax, x, text) {
12321232
12331233function formatDate ( ax , out , hover , extraPrecision ) {
12341234 var tr = ax . _tickround ,
1235- fmt = ( hover && ax . hoverformat ) || ax . tickformat ;
1235+ fmt = ( hover && ax . hoverformat ) || axes . getTickFormat ( ax ) ;
12361236
12371237 if ( extraPrecision ) {
12381238 // second or sub-second precision: extra always shows max digits.
@@ -1288,7 +1288,8 @@ function formatDate(ax, out, hover, extraPrecision) {
12881288
12891289function formatLog ( ax , out , hover , extraPrecision , hideexp ) {
12901290 var dtick = ax . dtick ,
1291- x = out . x ;
1291+ x = out . x ,
1292+ tickformat = ax . tickformat ;
12921293
12931294 if ( hideexp === 'never' ) {
12941295 // If this is a hover label, then we must *never* hide the exponent
@@ -1302,7 +1303,7 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
13021303
13031304 if ( extraPrecision && ( ( typeof dtick !== 'string' ) || dtick . charAt ( 0 ) !== 'L' ) ) dtick = 'L3' ;
13041305
1305- if ( ax . tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1306+ if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
13061307 out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
13071308 }
13081309 else if ( isNumeric ( dtick ) || ( ( dtick . charAt ( 0 ) === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
@@ -1397,7 +1398,7 @@ function numFormat(v, ax, fmtoverride, hover) {
13971398 tickRound = ax . _tickround ,
13981399 exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
13991400 exponent = ax . _tickexponent ,
1400- tickformat = ax . tickformat ,
1401+ tickformat = axes . getTickFormat ( ax ) ,
14011402 separatethousands = ax . separatethousands ;
14021403
14031404 // special case for hover: set exponent just for this value, and
@@ -1498,6 +1499,76 @@ function numFormat(v, ax, fmtoverride, hover) {
14981499 return v ;
14991500}
15001501
1502+ axes . getTickFormat = function ( ax ) {
1503+ var i ;
1504+
1505+ function convertToMs ( dtick ) {
1506+ return typeof dtick !== 'string' ? dtick : Number ( dtick . replace ( 'M' , '' ) ) * ONEAVGMONTH ;
1507+ }
1508+
1509+ function compareLogTicks ( left , right ) {
1510+ var priority = [ 'L' , 'D' ] ;
1511+ if ( typeof left === typeof right ) {
1512+ if ( typeof left === 'number' ) {
1513+ return left - right ;
1514+ } else {
1515+ var leftPriority = priority . indexOf ( left . charAt ( 0 ) ) ;
1516+ var rightPriority = priority . indexOf ( right . charAt ( 0 ) ) ;
1517+ if ( leftPriority === rightPriority ) {
1518+ return Number ( left . replace ( / ( L | D ) / g, '' ) ) - Number ( right . replace ( / ( L | D ) / g, '' ) ) ;
1519+ } else {
1520+ return leftPriority - rightPriority ;
1521+ }
1522+ }
1523+ } else {
1524+ return typeof left === 'number' ? 1 : - 1 ;
1525+ }
1526+ }
1527+
1528+ function isProperStop ( dtick , range , convert ) {
1529+ var convertFn = convert || function ( x ) { return x ; } ;
1530+ var leftDtick = range [ 0 ] ;
1531+ var rightDtick = range [ 1 ] ;
1532+ return ( ( ! leftDtick && typeof leftDtick !== 'number' ) || convertFn ( leftDtick ) <= convertFn ( dtick ) ) &&
1533+ ( ( ! rightDtick && typeof rightDtick !== 'number' ) || convertFn ( rightDtick ) >= convertFn ( dtick ) ) ;
1534+ }
1535+
1536+ function isProperLogStop ( dtick , range ) {
1537+ var isLeftDtickNull = range [ 0 ] === null ;
1538+ var isRightDtickNull = range [ 1 ] === null ;
1539+ var isDtickInRangeLeft = compareLogTicks ( dtick , range [ 0 ] ) >= 0 ;
1540+ var isDtickInRangeRight = compareLogTicks ( dtick , range [ 1 ] ) <= 0 ;
1541+ return ( isLeftDtickNull || isDtickInRangeLeft ) && ( isRightDtickNull || isDtickInRangeRight ) ;
1542+ }
1543+
1544+ var tickstop ;
1545+ if ( ax . tickformatstops && ax . tickformatstops . length > 0 ) {
1546+ switch ( ax . type ) {
1547+ case 'date' :
1548+ case 'linear' : {
1549+ for ( i = 0 ; i < ax . tickformatstops . length ; i ++ ) {
1550+ if ( isProperStop ( ax . dtick , ax . tickformatstops [ i ] . dtickrange , convertToMs ) ) {
1551+ tickstop = ax . tickformatstops [ i ] ;
1552+ break ;
1553+ }
1554+ }
1555+ break ;
1556+ }
1557+ case 'log' : {
1558+ for ( i = 0 ; i < ax . tickformatstops . length ; i ++ ) {
1559+ if ( isProperLogStop ( ax . dtick , ax . tickformatstops [ i ] . dtickrange ) ) {
1560+ tickstop = ax . tickformatstops [ i ] ;
1561+ break ;
1562+ }
1563+ }
1564+ break ;
1565+ }
1566+ default :
1567+ }
1568+ }
1569+ return tickstop ? tickstop . value : ax . tickformat ;
1570+ } ;
1571+
15011572axes . subplotMatch = / ^ x ( [ 0 - 9 ] * ) y ( [ 0 - 9 ] * ) $ / ;
15021573
15031574// getSubplots - extract all combinations of axes we need to make plots for
0 commit comments