@@ -27,6 +27,7 @@ var ONEDAY = constants.ONEDAY;
2727var ONEHOUR = constants . ONEHOUR ;
2828var ONEMIN = constants . ONEMIN ;
2929var ONESEC = constants . ONESEC ;
30+ var MINUS_SIGN = constants . MINUS_SIGN ;
3031
3132var MID_SHIFT = require ( '../../constants/alignment' ) . MID_SHIFT ;
3233
@@ -1055,7 +1056,7 @@ function autoTickRound(ax) {
10551056
10561057 var rangeexp = Math . floor ( Math . log ( maxend ) / Math . LN10 + 0.01 ) ;
10571058 if ( Math . abs ( rangeexp ) > 3 ) {
1058- if ( ax . exponentformat === 'SI' || ax . exponentformat === 'B' ) {
1059+ if ( isSIFormat ( ax . exponentformat ) && ! beyondSI ( rangeexp ) ) {
10591060 ax . _tickexponent = 3 * Math . round ( ( rangeexp - 1 ) / 3 ) ;
10601061 }
10611062 else ax . _tickexponent = rangeexp ;
@@ -1299,12 +1300,13 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
12991300 out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
13001301 }
13011302 else if ( isNumeric ( dtick ) || ( ( dtick . charAt ( 0 ) === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
1302- if ( [ 'e' , 'E' , 'power' ] . indexOf ( ax . exponentformat ) !== - 1 ) {
1303- var p = Math . round ( x ) ;
1303+ var p = Math . round ( x ) ;
1304+ if ( [ 'e' , 'E' , 'power' ] . indexOf ( ax . exponentformat ) !== - 1 ||
1305+ ( isSIFormat ( ax . exponentformat ) && beyondSI ( p ) ) ) {
13041306 if ( p === 0 ) out . text = 1 ;
13051307 else if ( p === 1 ) out . text = '10' ;
13061308 else if ( p > 1 ) out . text = '10<sup>' + p + '</sup>' ;
1307- else out . text = '10<sup>\u2212' + - p + '</sup>' ;
1309+ else out . text = '10<sup>' + MINUS_SIGN + - p + '</sup>' ;
13081310
13091311 out . fontSize *= 1.25 ;
13101312 }
@@ -1359,6 +1361,21 @@ function formatLinear(ax, out, hover, extraPrecision, hideexp) {
13591361// also automatically switch to sci. notation
13601362var SIPREFIXES = [ 'f' , 'p' , 'n' , 'μ' , 'm' , '' , 'k' , 'M' , 'G' , 'T' ] ;
13611363
1364+ function isSIFormat ( exponentFormat ) {
1365+ return exponentFormat === 'SI' || exponentFormat === 'B' ;
1366+ }
1367+
1368+ // are we beyond the range of common SI prefixes?
1369+ // 10^-16 -> 1x10^-16
1370+ // 10^-15 -> 1f
1371+ // ...
1372+ // 10^14 -> 100T
1373+ // 10^15 -> 1x10^15
1374+ // 10^16 -> 1x10^16
1375+ function beyondSI ( exponent ) {
1376+ return exponent > 14 || exponent < - 15 ;
1377+ }
1378+
13621379function numFormat ( v , ax , fmtoverride , hover ) {
13631380 // negative?
13641381 var isNeg = v < 0 ,
@@ -1387,7 +1404,7 @@ function numFormat(v, ax, fmtoverride, hover) {
13871404 if ( ax . hoverformat ) tickformat = ax . hoverformat ;
13881405 }
13891406
1390- if ( tickformat ) return d3 . format ( tickformat ) ( v ) . replace ( / - / g, '\u2212' ) ;
1407+ if ( tickformat ) return d3 . format ( tickformat ) ( v ) . replace ( / - / g, MINUS_SIGN ) ;
13911408
13921409 // 'epsilon' - rounding increment
13931410 var e = Math . pow ( 10 , - tickRound ) / 2 ;
@@ -1436,14 +1453,14 @@ function numFormat(v, ax, fmtoverride, hover) {
14361453
14371454 // add exponent
14381455 if ( exponent && exponentFormat !== 'hide' ) {
1456+ if ( isSIFormat ( exponentFormat ) && beyondSI ( exponent ) ) exponentFormat = 'power' ;
1457+
14391458 var signedExponent ;
1440- if ( exponent < 0 ) signedExponent = '\u2212' + - exponent ;
1459+ if ( exponent < 0 ) signedExponent = MINUS_SIGN + - exponent ;
14411460 else if ( exponentFormat !== 'power' ) signedExponent = '+' + exponent ;
14421461 else signedExponent = String ( exponent ) ;
14431462
1444- if ( exponentFormat === 'e' ||
1445- ( ( exponentFormat === 'SI' || exponentFormat === 'B' ) &&
1446- ( exponent > 12 || exponent < - 15 ) ) ) {
1463+ if ( exponentFormat === 'e' ) {
14471464 v += 'e' + signedExponent ;
14481465 }
14491466 else if ( exponentFormat === 'E' ) {
@@ -1455,19 +1472,18 @@ function numFormat(v, ax, fmtoverride, hover) {
14551472 else if ( exponentFormat === 'B' && exponent === 9 ) {
14561473 v += 'B' ;
14571474 }
1458- else if ( exponentFormat === 'SI' || exponentFormat === 'B' ) {
1475+ else if ( isSIFormat ( exponentFormat ) ) {
14591476 v += SIPREFIXES [ exponent / 3 + 5 ] ;
14601477 }
14611478 }
14621479
14631480 // put sign back in and return
14641481 // replace standard minus character (which is technically a hyphen)
14651482 // with a true minus sign
1466- if ( isNeg ) return '\u2212' + v ;
1483+ if ( isNeg ) return MINUS_SIGN + v ;
14671484 return v ;
14681485}
14691486
1470-
14711487axes . subplotMatch = / ^ x ( [ 0 - 9 ] * ) y ( [ 0 - 9 ] * ) $ / ;
14721488
14731489// getSubplots - extract all combinations of axes we need to make plots for
0 commit comments