@@ -632,9 +632,9 @@ axes.autoTicks = function(ax, roughDTick){
632
632
var nt = 1.5 * Math . abs ( ( ax . range [ 1 ] - ax . range [ 0 ] ) / roughDTick ) ;
633
633
634
634
// ticks on a linear scale, labeled fully
635
- roughDTick = Math . abs ( Math . pow ( 10 , ax . range [ 1 ] ) -
636
- Math . pow ( 10 , ax . range [ 0 ] ) ) / nt ;
637
- base = Math . pow ( 10 , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
635
+ roughDTick = Math . abs ( Math . pow ( ax . exponentbase , ax . range [ 1 ] ) -
636
+ Math . pow ( ax . exponentbase , ax . range [ 0 ] ) ) / nt ;
637
+ base = Math . pow ( ax . exponentbase , Math . floor ( Math . log ( roughDTick ) / Math . log ( ax . exponentbase ) ) ) ;
638
638
ax . dtick = 'L' + roundDTick ( roughDTick , base , roundBase10 ) ;
639
639
}
640
640
else {
@@ -693,7 +693,7 @@ function autoTickRound(ax) {
693
693
ax . _tickround = 2 - Math . floor ( Math . log ( dtick ) / Math . log ( ax . exponentbase ) + 0.01 ) ;
694
694
695
695
if ( ax . type === 'log' ) {
696
- maxend = Math . pow ( 10 , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
696
+ maxend = Math . pow ( ax . exponentbase , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
697
697
}
698
698
else maxend = Math . max ( Math . abs ( ax . range [ 0 ] ) , Math . abs ( ax . range [ 1 ] ) ) ;
699
699
@@ -1019,7 +1019,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1019
1019
tickRound = ax . _tickround ,
1020
1020
exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
1021
1021
exponent = ax . _tickexponent ,
1022
- base = ax . exponentbase || 10 ,
1022
+ base = + ax . exponentbase || 10 ,
1023
1023
isBase10 = ( base === 10 ) ,
1024
1024
tickformat = ax . tickformat ;
1025
1025
@@ -1045,7 +1045,8 @@ function numFormat(v, ax, fmtoverride, hover) {
1045
1045
if ( tickformat ) return d3 . format ( tickformat ) ( v ) . replace ( / - / g, '\u2212' ) ;
1046
1046
1047
1047
// 'epsilon' - rounding increment
1048
- var e = Math . pow ( base , - tickRound ) / 2 ;
1048
+ var e = isBase10 ? Math . pow ( base , - tickRound ) / 2 : 0 ;
1049
+ // var e = 0;
1049
1050
1050
1051
// exponentFormat codes:
1051
1052
// 'e' (1.2e+6, default)
@@ -1061,6 +1062,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1061
1062
// take the sign out, put it back manually at the end
1062
1063
// - makes cases easier
1063
1064
v = Math . abs ( v ) ;
1065
+
1064
1066
if ( v < e ) {
1065
1067
// 0 is just 0, but may get exponent if it's the last tick
1066
1068
v = '0' ;
@@ -1069,16 +1071,11 @@ function numFormat(v, ax, fmtoverride, hover) {
1069
1071
v += e ;
1070
1072
// take out a common exponent, if any
1071
1073
// Special case for base 2 to follow "SI"
1072
- if ( exponent && base === 2 && exponentFormat === 'SI' ) {
1073
- v = v / 1024 ;
1074
-
1075
- // To make 1024 -> 1k
1076
- exponent -= 9 ;
1077
- tickRound += exponent ;
1078
- } else {
1074
+ if ( exponent ) {
1079
1075
v *= Math . pow ( base , - exponent ) ;
1080
1076
tickRound += exponent ;
1081
1077
}
1078
+
1082
1079
// round the mantissa
1083
1080
if ( tickRound === 0 ) v = String ( Math . floor ( v ) ) ;
1084
1081
else if ( tickRound < 0 ) {
@@ -1112,6 +1109,13 @@ function numFormat(v, ax, fmtoverride, hover) {
1112
1109
} else if ( exponentFormat === 'B' && exponent === 9 ) {
1113
1110
v += 'B' ;
1114
1111
} else if ( exponentFormat === 'SI' || exponentFormat === 'B' ) {
1112
+ if ( base === 2 && exponent >= 10 ) {
1113
+ v = v * Math . pow ( base , ( exponent - 10 ) ) ;
1114
+ exponent -= 9 ;
1115
+ } else if ( base === 2 && exponent < 10 ) {
1116
+ v = v * Math . pow ( base , ( exponent ) ) ;
1117
+ exponent = 0 ;
1118
+ }
1115
1119
v += SIPREFIXES [ exponent / 3 + 5 ] ;
1116
1120
} else {
1117
1121
v += '×' + base + '<sup>' + signedExponent + '</sup>' ;
0 commit comments