@@ -30,7 +30,6 @@ axes.listIds = axisIds.listIds;
30
30
axes . getFromId = axisIds . getFromId ;
31
31
axes . getFromTrace = axisIds . getFromTrace ;
32
32
33
-
34
33
// find the list of possible axes to reference with an xref or yref attribute
35
34
// and coerce it to that list
36
35
axes . coerceRef = function ( containerIn , containerOut , td , axLetter ) {
@@ -344,7 +343,9 @@ axes.expand = function(ax, data, options) {
344
343
345
344
axes . autoBin = function ( data , ax , nbins , is2d ) {
346
345
var datamin = Plotly . Lib . aggNums ( Math . min , null , data ) ,
347
- datamax = Plotly . Lib . aggNums ( Math . max , null , data ) ;
346
+ datamax = Plotly . Lib . aggNums ( Math . max , null , data ) ,
347
+ exponentbase = ax . exponentbase || 10 ;
348
+
348
349
if ( ax . type === 'category' ) {
349
350
return {
350
351
start : datamin - 0.5 ,
@@ -361,8 +362,8 @@ axes.autoBin = function(data,ax,nbins,is2d) {
361
362
// the size get smaller than the 'nice' rounded down minimum
362
363
// difference between values
363
364
var distinctData = Plotly . Lib . distinctVals ( data ) ,
364
- msexp = Math . pow ( ax . exponentbase , Math . floor (
365
- Math . log ( distinctData . minDiff ) / Math . log ( ax . exponentbase ) ) ) ,
365
+ msexp = Math . pow ( exponentbase , Math . floor (
366
+ Math . log ( distinctData . minDiff ) / Math . log ( exponentbase ) ) ) ,
366
367
// TODO: there are some date cases where this will fail...
367
368
minSize = msexp * Plotly . Lib . roundUp (
368
369
distinctData . minDiff / msexp , [ 0.9 , 1.9 , 4.9 , 9.9 ] , true ) ;
@@ -582,7 +583,8 @@ function roundDTick(roughDTick, base, roundingSet) {
582
583
// log showing powers plus some intermediates:
583
584
// D1 shows all digits, D2 shows 2 and 5
584
585
axes . autoTicks = function ( ax , roughDTick ) {
585
- var base ;
586
+ var base ,
587
+ exponentbase = ax . exponentbase || 10 ;
586
588
587
589
if ( ax . type === 'date' ) {
588
590
ax . tick0 = new Date ( 2000 , 0 , 1 ) . getTime ( ) ;
@@ -632,9 +634,9 @@ axes.autoTicks = function(ax, roughDTick){
632
634
var nt = 1.5 * Math . abs ( ( ax . range [ 1 ] - ax . range [ 0 ] ) / roughDTick ) ;
633
635
634
636
// ticks on a linear scale, labeled fully
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 ) ) ) ;
637
+ roughDTick = Math . abs ( Math . pow ( exponentbase , ax . range [ 1 ] ) -
638
+ Math . pow ( exponentbase , ax . range [ 0 ] ) ) / nt ;
639
+ base = Math . pow ( exponentbase , Math . floor ( Math . log ( roughDTick ) / Math . log ( exponentbase ) ) ) ;
638
640
ax . dtick = 'L' + roundDTick ( roughDTick , base , roundBase10 ) ;
639
641
}
640
642
else {
@@ -673,7 +675,8 @@ axes.autoTicks = function(ax, roughDTick){
673
675
// or an integer # digits past seconds
674
676
function autoTickRound ( ax ) {
675
677
var dtick = ax . dtick ,
676
- maxend ;
678
+ maxend ,
679
+ exponentbase = ax . exponentbase || 10 ;
677
680
678
681
ax . _tickexponent = 0 ;
679
682
if ( ! isNumeric ( dtick ) && typeof dtick !== 'string' ) dtick = 1 ;
@@ -690,14 +693,14 @@ function autoTickRound(ax) {
690
693
else {
691
694
if ( ! isNumeric ( dtick ) ) dtick = Number ( dtick . substr ( 1 ) ) ;
692
695
// 2 digits past largest digit of dtick
693
- ax . _tickround = 2 - Math . floor ( Math . log ( dtick ) / Math . log ( ax . exponentbase ) + 0.01 ) ;
696
+ ax . _tickround = 2 - Math . floor ( Math . log ( dtick ) / Math . log ( exponentbase ) + 0.01 ) ;
694
697
695
698
if ( ax . type === 'log' ) {
696
- maxend = Math . pow ( ax . exponentbase , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
699
+ maxend = Math . pow ( exponentbase , Math . max ( ax . range [ 0 ] , ax . range [ 1 ] ) ) ;
697
700
}
698
701
else maxend = Math . max ( Math . abs ( ax . range [ 0 ] ) , Math . abs ( ax . range [ 1 ] ) ) ;
699
702
700
- var rangeexp = Math . floor ( Math . log ( maxend ) / Math . log ( ax . exponentbase ) + 0.01 ) ;
703
+ var rangeexp = Math . floor ( Math . log ( maxend ) / Math . log ( exponentbase ) + 0.01 ) ;
701
704
if ( Math . abs ( rangeexp ) > 3 ) {
702
705
if ( ax . exponentformat === 'SI' || ax . exponentformat === 'B' ) {
703
706
ax . _tickexponent = 3 * Math . round ( ( rangeexp - 1 ) / 3 ) ;
@@ -757,7 +760,9 @@ axes.tickFirst = function(ax){
757
760
// that may have been rounded out
758
761
r0 = ax . range [ 0 ] * 1.0001 - ax . range [ 1 ] * 0.0001 ,
759
762
dtick = ax . dtick ,
760
- tick0 = ax . tick0 ;
763
+ tick0 = ax . tick0 ,
764
+ exponentbase = ax . exponentbase || 10 ;
765
+
761
766
if ( isNumeric ( dtick ) ) {
762
767
var tmin = sRound ( ( r0 - tick0 ) / dtick ) * dtick + tick0 ;
763
768
@@ -792,14 +797,14 @@ axes.tickFirst = function(ax){
792
797
// Log scales: Linear, Digits
793
798
else if ( tType === 'L' ) {
794
799
return Math . log ( sRound (
795
- ( Math . pow ( ax . exponentbase , r0 ) - tick0 ) / dtNum ) * dtNum + tick0 ) / Math . log ( ax . exponentbase ) ;
800
+ ( Math . pow ( exponentbase , r0 ) - tick0 ) / dtNum ) * dtNum + tick0 ) / Math . log ( exponentbase ) ;
796
801
}
797
802
else if ( tType === 'D' ) {
798
803
var tickset = ( dtick === 'D2' ) ? roundLog2 : roundLog1 ,
799
804
frac = Plotly . Lib . roundUp ( mod ( r0 , 1 ) , tickset , axrev ) ;
800
805
801
806
return Math . floor ( r0 ) +
802
- Math . log ( d3 . round ( Math . pow ( ax . exponentbase , frac ) , 1 ) ) / Math . log ( ax . exponentbase ) ;
807
+ Math . log ( d3 . round ( Math . pow ( exponentbase , frac ) , 1 ) ) / Math . log ( exponentbase ) ;
803
808
}
804
809
else throw 'unrecognized dtick ' + String ( dtick ) ;
805
810
} ;
@@ -946,7 +951,7 @@ function formatDate(ax, out, hover, extraPrecision) {
946
951
947
952
function formatLog ( ax , out , hover , extraPrecision , hideexp ) {
948
953
var dtick = ax . dtick ,
949
- base = ax . exponentbase ,
954
+ base = ax . exponentbase || 10 ,
950
955
x = out . x ;
951
956
if ( extraPrecision && ( ( typeof dtick !== 'string' ) || dtick . charAt ( 0 ) !== 'L' ) ) dtick = 'L3' ;
952
957
@@ -1021,8 +1026,8 @@ function numFormat(v, ax, fmtoverride, hover) {
1021
1026
tickRound = ax . _tickround ,
1022
1027
exponentFormat = fmtoverride || ax . exponentformat || 'B' ,
1023
1028
exponent = ax . _tickexponent ,
1024
- base = + ax . exponentbase || 10 ,
1025
- isBase10 = ( base === 10 ) ,
1029
+ exponentbase = ax . exponentbase || 10 ,
1030
+ isBase10 = ( exponentbase === 10 ) ,
1026
1031
tickformat = ax . tickformat ;
1027
1032
1028
1033
// special case for hover: set exponent just for this value, and
@@ -1031,7 +1036,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1031
1036
// make a dummy axis obj to get the auto rounding and exponent
1032
1037
var ah = {
1033
1038
exponentformat :ax . exponentformat ,
1034
- exponentbase : ax . exponentbase ,
1039
+ exponentbase : exponentbase ,
1035
1040
dtick : ax . showexponent === 'none' ? ax . dtick :
1036
1041
( isNumeric ( v ) ? Math . abs ( v ) || 1 : 1 ) ,
1037
1042
// if not showing any exponents, don't change the exponent
@@ -1047,7 +1052,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1047
1052
if ( tickformat ) return d3 . format ( tickformat ) ( v ) . replace ( / - / g, '\u2212' ) ;
1048
1053
1049
1054
// 'epsilon' - rounding increment
1050
- var e = isBase10 ? Math . pow ( base , - tickRound ) / 2 : 0 ;
1055
+ var e = isBase10 ? Math . pow ( exponentbase , - tickRound ) / 2 : 0 ;
1051
1056
// var e = 0;
1052
1057
1053
1058
// exponentFormat codes:
@@ -1074,7 +1079,7 @@ function numFormat(v, ax, fmtoverride, hover) {
1074
1079
// take out a common exponent, if any
1075
1080
// Special case for base 2 to follow "SI"
1076
1081
if ( exponent ) {
1077
- v *= Math . pow ( base , - exponent ) ;
1082
+ v *= Math . pow ( exponentbase , - exponent ) ;
1078
1083
tickRound += exponent ;
1079
1084
}
1080
1085
@@ -1111,16 +1116,16 @@ function numFormat(v, ax, fmtoverride, hover) {
1111
1116
} else if ( exponentFormat === 'B' && exponent === 9 ) {
1112
1117
v += 'B' ;
1113
1118
} else if ( exponentFormat === 'SI' || exponentFormat === 'B' ) {
1114
- if ( base === 2 && exponent >= 10 ) {
1115
- v = v * Math . pow ( base , ( exponent - 10 ) ) ;
1119
+ if ( exponentbase === 2 && exponent >= 10 ) {
1120
+ v = v * Math . pow ( exponentbase , ( exponent - 10 ) ) ;
1116
1121
exponent -= 9 ;
1117
- } else if ( base === 2 && exponent < 10 ) {
1118
- v = v * Math . pow ( base , ( exponent ) ) ;
1122
+ } else if ( exponentbase === 2 && exponent < 10 ) {
1123
+ v = v * Math . pow ( exponentbase , ( exponent ) ) ;
1119
1124
exponent = 0 ;
1120
1125
}
1121
1126
v += SIPREFIXES [ exponent / 3 + 5 ] ;
1122
1127
} else {
1123
- v += '×' + base + '<sup>' + signedExponent + '</sup>' ;
1128
+ v += '×' + exponentbase + '<sup>' + signedExponent + '</sup>' ;
1124
1129
}
1125
1130
}
1126
1131
0 commit comments