@@ -1079,9 +1079,10 @@ function formatDate(ax, out, hover, extraPrecision) {
10791079}
10801080
10811081function 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 ) ;
10851086
10861087 if ( hideexp === 'never' ) {
10871088 // If this is a hover label, then we must *never* hide the exponent
@@ -1093,30 +1094,33 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
10931094 hideexp = '' ;
10941095 }
10951096
1096- if ( extraPrecision && ( ( typeof dtick !== 'string' ) || dtick . charAt ( 0 ) !== 'L' ) ) dtick = 'L3' ;
1097+ if ( extraPrecision && ( dtChar0 !== 'L' ) ) dtick = 'L3' ;
10971098
1098- if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1099+ if ( tickformat || ( dtChar0 === 'L' ) ) {
10991100 out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
11001101 }
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 ) ) ) {
11021103 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 ) ) ) {
11051107 if ( p === 0 ) out . text = 1 ;
11061108 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>' ;
11091110
11101111 out . fontSize *= 1.25 ;
11111112 }
1113+ else if ( ( exponentFormat === 'e' || exponentFormat === 'E' ) && absP > 2 ) {
1114+ out . text = '1' + exponentFormat + ( p > 0 ? '+' : MINUS_SIGN ) + absP ;
1115+ }
11121116 else {
11131117 out . text = numFormat ( Math . pow ( 10 , x ) , ax , '' , 'fakehover' ) ;
11141118 if ( dtick === 'D1' && ax . _id . charAt ( 0 ) === 'y' ) {
11151119 out . dy -= out . fontSize / 6 ;
11161120 }
11171121 }
11181122 }
1119- else if ( dtick . charAt ( 0 ) === 'D' ) {
1123+ else if ( dtChar0 === 'D' ) {
11201124 out . text = String ( Math . round ( Math . pow ( 10 , Lib . mod ( x , 1 ) ) ) ) ;
11211125 out . fontSize *= 0.75 ;
11221126 }
@@ -1332,11 +1336,8 @@ function numFormat(v, ax, fmtoverride, hover) {
13321336 else if ( exponentFormat !== 'power' ) signedExponent = '+' + exponent ;
13331337 else signedExponent = String ( exponent ) ;
13341338
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 ;
13401341 }
13411342 else if ( exponentFormat === 'power' ) {
13421343 v += '×10<sup>' + signedExponent + '</sup>' ;
0 commit comments