@@ -1079,9 +1079,10 @@ function formatDate(ax, out, hover, extraPrecision) {
1079
1079
}
1080
1080
1081
1081
function formatLog ( ax , out , hover , extraPrecision , hideexp ) {
1082
- var dtick = ax . dtick ,
1083
- x = out . x ,
1084
- tickformat = ax . tickformat ;
1082
+ var dtick = ax . dtick ;
1083
+ var x = out . x ;
1084
+ var tickformat = ax . tickformat ;
1085
+ var dtChar0 = typeof dtick === 'string' && dtick . charAt ( 0 ) ;
1085
1086
1086
1087
if ( hideexp === 'never' ) {
1087
1088
// If this is a hover label, then we must *never* hide the exponent
@@ -1093,30 +1094,33 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
1093
1094
hideexp = '' ;
1094
1095
}
1095
1096
1096
- if ( extraPrecision && ( ( typeof dtick !== 'string' ) || dtick . charAt ( 0 ) !== 'L' ) ) dtick = 'L3' ;
1097
+ if ( extraPrecision && ( dtChar0 !== 'L' ) ) dtick = 'L3' ;
1097
1098
1098
- if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1099
+ if ( tickformat || ( dtChar0 === 'L' ) ) {
1099
1100
out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
1100
1101
}
1101
- else if ( isNumeric ( dtick ) || ( ( dtick . charAt ( 0 ) === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
1102
+ else if ( isNumeric ( dtick ) || ( ( dtChar0 === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
1102
1103
var p = Math . round ( x ) ;
1103
- if ( [ 'e' , 'E' , 'power' ] . indexOf ( ax . exponentformat ) !== - 1 ||
1104
- ( isSIFormat ( ax . exponentformat ) && beyondSI ( p ) ) ) {
1104
+ var absP = Math . abs ( p ) ;
1105
+ var exponentFormat = ax . exponentformat ;
1106
+ if ( exponentFormat === 'power' || ( isSIFormat ( exponentFormat ) && beyondSI ( p ) ) ) {
1105
1107
if ( p === 0 ) out . text = 1 ;
1106
1108
else if ( p === 1 ) out . text = '10' ;
1107
- else if ( p > 1 ) out . text = '10<sup>' + p + '</sup>' ;
1108
- else out . text = '10<sup>' + MINUS_SIGN + - p + '</sup>' ;
1109
+ out . text = '10<sup>' + ( p > 1 ? '' : MINUS_SIGN ) + absP + '</sup>' ;
1109
1110
1110
1111
out . fontSize *= 1.25 ;
1111
1112
}
1113
+ else if ( ( exponentFormat === 'e' || exponentFormat === 'E' ) && absP > 2 ) {
1114
+ out . text = '1' + exponentFormat + ( p > 0 ? '+' : MINUS_SIGN ) + absP ;
1115
+ }
1112
1116
else {
1113
1117
out . text = numFormat ( Math . pow ( 10 , x ) , ax , '' , 'fakehover' ) ;
1114
1118
if ( dtick === 'D1' && ax . _id . charAt ( 0 ) === 'y' ) {
1115
1119
out . dy -= out . fontSize / 6 ;
1116
1120
}
1117
1121
}
1118
1122
}
1119
- else if ( dtick . charAt ( 0 ) === 'D' ) {
1123
+ else if ( dtChar0 === 'D' ) {
1120
1124
out . text = String ( Math . round ( Math . pow ( 10 , Lib . mod ( x , 1 ) ) ) ) ;
1121
1125
out . fontSize *= 0.75 ;
1122
1126
}
@@ -1332,11 +1336,8 @@ function numFormat(v, ax, fmtoverride, hover) {
1332
1336
else if ( exponentFormat !== 'power' ) signedExponent = '+' + exponent ;
1333
1337
else signedExponent = String ( exponent ) ;
1334
1338
1335
- if ( exponentFormat === 'e' ) {
1336
- v += 'e' + signedExponent ;
1337
- }
1338
- else if ( exponentFormat === 'E' ) {
1339
- v += 'E' + signedExponent ;
1339
+ if ( exponentFormat === 'e' || exponentFormat === 'E' ) {
1340
+ v += exponentFormat + signedExponent ;
1340
1341
}
1341
1342
else if ( exponentFormat === 'power' ) {
1342
1343
v += '×10<sup>' + signedExponent + '</sup>' ;
0 commit comments