@@ -1232,7 +1232,7 @@ function tickTextObj(ax, x, text) {
1232
1232
1233
1233
function formatDate ( ax , out , hover , extraPrecision ) {
1234
1234
var tr = ax . _tickround ,
1235
- fmt = ( hover && ax . hoverformat ) || ax . tickformat ;
1235
+ fmt = ( hover && ax . hoverformat ) || axes . getTickFormat ( ax ) ;
1236
1236
1237
1237
if ( extraPrecision ) {
1238
1238
// second or sub-second precision: extra always shows max digits.
@@ -1288,7 +1288,8 @@ function formatDate(ax, out, hover, extraPrecision) {
1288
1288
1289
1289
function formatLog ( ax , out , hover , extraPrecision , hideexp ) {
1290
1290
var dtick = ax . dtick ,
1291
- x = out . x ;
1291
+ x = out . x ,
1292
+ tickformat = ax . tickformat ;
1292
1293
1293
1294
if ( hideexp === 'never' ) {
1294
1295
// If this is a hover label, then we must *never* hide the exponent
@@ -1302,7 +1303,7 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
1302
1303
1303
1304
if ( extraPrecision && ( ( typeof dtick !== 'string' ) || dtick . charAt ( 0 ) !== 'L' ) ) dtick = 'L3' ;
1304
1305
1305
- if ( ax . tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1306
+ if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1306
1307
out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
1307
1308
}
1308
1309
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) {
1397
1398
tickRound = ax . _tickround ,
1398
1399
exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
1399
1400
exponent = ax . _tickexponent ,
1400
- tickformat = ax . tickformat ,
1401
+ tickformat = axes . getTickFormat ( ax ) ,
1401
1402
separatethousands = ax . separatethousands ;
1402
1403
1403
1404
// special case for hover: set exponent just for this value, and
@@ -1498,6 +1499,76 @@ function numFormat(v, ax, fmtoverride, hover) {
1498
1499
return v ;
1499
1500
}
1500
1501
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
+
1501
1572
axes . subplotMatch = / ^ x ( [ 0 - 9 ] * ) y ( [ 0 - 9 ] * ) $ / ;
1502
1573
1503
1574
// getSubplots - extract all combinations of axes we need to make plots for
0 commit comments