@@ -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,36 @@ 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' ) ) {
1098
+ dtick = 'L3' ;
1099
+ dtChar0 = 'L' ;
1100
+ }
1097
1101
1098
- if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1102
+ if ( tickformat || ( dtChar0 === 'L' ) ) {
1099
1103
out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
1100
1104
}
1101
- else if ( isNumeric ( dtick ) || ( ( dtick . charAt ( 0 ) === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
1105
+ else if ( isNumeric ( dtick ) || ( ( dtChar0 === 'D' ) && ( Lib . mod ( x + 0.01 , 1 ) < 0.1 ) ) ) {
1102
1106
var p = Math . round ( x ) ;
1103
- if ( [ 'e' , 'E' , 'power' ] . indexOf ( ax . exponentformat ) !== - 1 ||
1104
- ( isSIFormat ( ax . exponentformat ) && beyondSI ( p ) ) ) {
1107
+ var absP = Math . abs ( p ) ;
1108
+ var exponentFormat = ax . exponentformat ;
1109
+ if ( exponentFormat === 'power' || ( isSIFormat ( exponentFormat ) && beyondSI ( p ) ) ) {
1105
1110
if ( p === 0 ) out . text = 1 ;
1106
1111
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>' ;
1112
+ else out . text = '10<sup>' + ( p > 1 ? '' : MINUS_SIGN ) + absP + '</sup>' ;
1109
1113
1110
1114
out . fontSize *= 1.25 ;
1111
1115
}
1116
+ else if ( ( exponentFormat === 'e' || exponentFormat === 'E' ) && absP > 2 ) {
1117
+ out . text = '1' + exponentFormat + ( p > 0 ? '+' : MINUS_SIGN ) + absP ;
1118
+ }
1112
1119
else {
1113
1120
out . text = numFormat ( Math . pow ( 10 , x ) , ax , '' , 'fakehover' ) ;
1114
1121
if ( dtick === 'D1' && ax . _id . charAt ( 0 ) === 'y' ) {
1115
1122
out . dy -= out . fontSize / 6 ;
1116
1123
}
1117
1124
}
1118
1125
}
1119
- else if ( dtick . charAt ( 0 ) === 'D' ) {
1126
+ else if ( dtChar0 === 'D' ) {
1120
1127
out . text = String ( Math . round ( Math . pow ( 10 , Lib . mod ( x , 1 ) ) ) ) ;
1121
1128
out . fontSize *= 0.75 ;
1122
1129
}
@@ -1332,11 +1339,8 @@ function numFormat(v, ax, fmtoverride, hover) {
1332
1339
else if ( exponentFormat !== 'power' ) signedExponent = '+' + exponent ;
1333
1340
else signedExponent = String ( exponent ) ;
1334
1341
1335
- if ( exponentFormat === 'e' ) {
1336
- v += 'e' + signedExponent ;
1337
- }
1338
- else if ( exponentFormat === 'E' ) {
1339
- v += 'E' + signedExponent ;
1342
+ if ( exponentFormat === 'e' || exponentFormat === 'E' ) {
1343
+ v += exponentFormat + signedExponent ;
1340
1344
}
1341
1345
else if ( exponentFormat === 'power' ) {
1342
1346
v += '×10<sup>' + signedExponent + '</sup>' ;
0 commit comments