@@ -253,8 +253,12 @@ axes.handleTickDefaults = function(containerIn, containerOut, coerce, axType, op
253
253
var expBase = coerce ( 'exponentbase' ) ,
254
254
expFmtDflt = coerce ( 'exponentformat' ) ;
255
255
256
- if ( expBase !== 2 && expBase !== 10 ) expFmtDflt = 'power' ;
257
- if ( expBase === 2 && expFmtDflt !== 'SI' ) expFmtDflt = 'power' ;
256
+ if ( + expBase !== 2 && + expBase !== 10 ) expFmtDflt = 'power' ;
257
+ if ( + expBase === 2 && expFmtDflt !== 'SI' ) expFmtDflt = 'power' ;
258
+ if ( expBase === 'e' ) {
259
+ containerOut . exponentbase = Math . E ;
260
+ containerOut . type = 'log' ;
261
+ }
258
262
259
263
containerOut . exponentformat = expFmtDflt ;
260
264
}
@@ -1377,9 +1381,9 @@ axes.autoTicks = function(ax, roughDTick){
1377
1381
var nt = 1.5 * Math . abs ( ( ax . range [ 1 ] - ax . range [ 0 ] ) / roughDTick ) ;
1378
1382
1379
1383
// ticks on a linear scale, labeled fully
1380
- roughDTick = Math . abs ( Math . pow ( 10 , ax . range [ 1 ] ) -
1381
- Math . pow ( 10 , ax . range [ 0 ] ) ) / nt ;
1382
- base = Math . pow ( 10 , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
1384
+ roughDTick = Math . abs ( Math . pow ( ax . exponentbase , ax . range [ 1 ] ) -
1385
+ Math . pow ( ax . exponentbase , ax . range [ 0 ] ) ) / nt ;
1386
+ base = Math . pow ( ax . exponentbase , Math . floor ( Math . log ( roughDTick ) / Math . log ( ax . exponentbase ) ) ) ;
1383
1387
ax . dtick = 'L' + roundDTick ( roughDTick , base , roundBase10 ) ;
1384
1388
}
1385
1389
else {
@@ -1440,7 +1444,7 @@ function autoTickRound(ax) {
1440
1444
ax . _tickround = 2 - Math . floor ( Math . log ( dtick ) / Math . log ( ax . exponentbase ) + 0.01 ) ;
1441
1445
1442
1446
if ( ax . type === 'log' ) {
1443
- maxend = Math . pow ( 10 , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
1447
+ maxend = Math . pow ( ax . exponentbase , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
1444
1448
}
1445
1449
else maxend = Math . max ( Math . abs ( ax . range [ 0 ] ) , Math . abs ( ax . range [ 1 ] ) ) ;
1446
1450
@@ -1765,7 +1769,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1765
1769
tickRound = ax . _tickround ,
1766
1770
exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
1767
1771
exponent = ax . _tickexponent ,
1768
- base = ax . exponentbase || 10 ,
1772
+ base = + ax . exponentbase || 10 ,
1769
1773
isBase10 = ( base === 10 ) ,
1770
1774
tickformat = ax . tickformat ;
1771
1775
@@ -1791,7 +1795,8 @@ function numFormat(v, ax, fmtoverride, hover) {
1791
1795
if ( tickformat ) return d3 . format ( tickformat ) ( v ) . replace ( / - / g, '\u2212' ) ;
1792
1796
1793
1797
// 'epsilon' - rounding increment
1794
- var e = Math . pow ( base , - tickRound ) / 2 ;
1798
+ var e = isBase10 ? Math . pow ( base , - tickRound ) / 2 : 0 ;
1799
+ // var e = 0;
1795
1800
1796
1801
// exponentFormat codes:
1797
1802
// 'e' (1.2e+6, default)
@@ -1807,6 +1812,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1807
1812
// take the sign out, put it back manually at the end
1808
1813
// - makes cases easier
1809
1814
v = Math . abs ( v ) ;
1815
+
1810
1816
if ( v < e ) {
1811
1817
// 0 is just 0, but may get exponent if it's the last tick
1812
1818
v = '0' ;
@@ -1815,16 +1821,11 @@ function numFormat(v, ax, fmtoverride, hover) {
1815
1821
v += e ;
1816
1822
// take out a common exponent, if any
1817
1823
// Special case for base 2 to follow "SI"
1818
- if ( exponent && base === 2 && exponentFormat === 'SI' ) {
1819
- v = v / 1024 ;
1820
-
1821
- // To make 1024 -> 1k
1822
- exponent -= 9 ;
1823
- tickRound += exponent ;
1824
- } else {
1824
+ if ( exponent ) {
1825
1825
v *= Math . pow ( base , - exponent ) ;
1826
1826
tickRound += exponent ;
1827
1827
}
1828
+
1828
1829
// round the mantissa
1829
1830
if ( tickRound === 0 ) v = String ( Math . floor ( v ) ) ;
1830
1831
else if ( tickRound < 0 ) {
@@ -1857,6 +1858,13 @@ function numFormat(v, ax, fmtoverride, hover) {
1857
1858
} else if ( exponentFormat === 'B' && exponent === 9 ) {
1858
1859
v += 'B' ;
1859
1860
} else if ( exponentFormat === 'SI' || exponentFormat === 'B' ) {
1861
+ if ( base === 2 && exponent >= 10 ) {
1862
+ v = v * Math . pow ( base , ( exponent - 10 ) ) ;
1863
+ exponent -= 9 ;
1864
+ } else if ( base === 2 && exponent < 10 ) {
1865
+ v = v * Math . pow ( base , ( exponent ) ) ;
1866
+ exponent = 0 ;
1867
+ }
1860
1868
v += SIPREFIXES [ exponent / 3 + 5 ] ;
1861
1869
} else {
1862
1870
v += '×' + base + '<sup>' + signedExponent + '</sup>' ;
0 commit comments