@@ -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,36 @@ 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' ) ) {
1098+ dtick = 'L3' ;
1099+ dtChar0 = 'L' ;
1100+ }
10971101
1098- if ( tickformat || ( typeof dtick === 'string' && dtick . charAt ( 0 ) === 'L' ) ) {
1102+ if ( tickformat || ( dtChar0 === 'L' ) ) {
10991103 out . text = numFormat ( Math . pow ( 10 , x ) , ax , hideexp , extraPrecision ) ;
11001104 }
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 ) ) ) {
11021106 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 ) ) ) {
11051110 if ( p === 0 ) out . text = 1 ;
11061111 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>' ;
11091113
11101114 out . fontSize *= 1.25 ;
11111115 }
1116+ else if ( ( exponentFormat === 'e' || exponentFormat === 'E' ) && absP > 2 ) {
1117+ out . text = '1' + exponentFormat + ( p > 0 ? '+' : MINUS_SIGN ) + absP ;
1118+ }
11121119 else {
11131120 out . text = numFormat ( Math . pow ( 10 , x ) , ax , '' , 'fakehover' ) ;
11141121 if ( dtick === 'D1' && ax . _id . charAt ( 0 ) === 'y' ) {
11151122 out . dy -= out . fontSize / 6 ;
11161123 }
11171124 }
11181125 }
1119- else if ( dtick . charAt ( 0 ) === 'D' ) {
1126+ else if ( dtChar0 === 'D' ) {
11201127 out . text = String ( Math . round ( Math . pow ( 10 , Lib . mod ( x , 1 ) ) ) ) ;
11211128 out . fontSize *= 0.75 ;
11221129 }
@@ -1332,11 +1339,8 @@ function numFormat(v, ax, fmtoverride, hover) {
13321339 else if ( exponentFormat !== 'power' ) signedExponent = '+' + exponent ;
13331340 else signedExponent = String ( exponent ) ;
13341341
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 ;
13401344 }
13411345 else if ( exponentFormat === 'power' ) {
13421346 v += '×10<sup>' + signedExponent + '</sup>' ;
0 commit comments