Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b3d17f

Browse files
committed
Set default of 10 for exponentbase in all method calls
1 parent 620cfb9 commit 8b3d17f

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/plots/cartesian/axes.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ axes.listIds = axisIds.listIds;
3030
axes.getFromId = axisIds.getFromId;
3131
axes.getFromTrace = axisIds.getFromTrace;
3232

33-
3433
// find the list of possible axes to reference with an xref or yref attribute
3534
// and coerce it to that list
3635
axes.coerceRef = function(containerIn, containerOut, td, axLetter) {
@@ -344,7 +343,9 @@ axes.expand = function(ax, data, options) {
344343

345344
axes.autoBin = function(data,ax,nbins,is2d) {
346345
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+
348349
if(ax.type==='category') {
349350
return {
350351
start: datamin - 0.5,
@@ -361,8 +362,8 @@ axes.autoBin = function(data,ax,nbins,is2d) {
361362
// the size get smaller than the 'nice' rounded down minimum
362363
// difference between values
363364
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))),
366367
// TODO: there are some date cases where this will fail...
367368
minSize = msexp*Plotly.Lib.roundUp(
368369
distinctData.minDiff/msexp, [0.9, 1.9, 4.9, 9.9], true);
@@ -582,7 +583,8 @@ function roundDTick(roughDTick, base, roundingSet) {
582583
// log showing powers plus some intermediates:
583584
// D1 shows all digits, D2 shows 2 and 5
584585
axes.autoTicks = function(ax, roughDTick){
585-
var base;
586+
var base,
587+
exponentbase = ax.exponentbase || 10;
586588

587589
if(ax.type === 'date'){
588590
ax.tick0 = new Date(2000, 0, 1).getTime();
@@ -632,9 +634,9 @@ axes.autoTicks = function(ax, roughDTick){
632634
var nt = 1.5 * Math.abs((ax.range[1] - ax.range[0]) / roughDTick);
633635

634636
// 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)));
638640
ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);
639641
}
640642
else {
@@ -673,7 +675,8 @@ axes.autoTicks = function(ax, roughDTick){
673675
// or an integer # digits past seconds
674676
function autoTickRound(ax) {
675677
var dtick = ax.dtick,
676-
maxend;
678+
maxend,
679+
exponentbase = ax.exponentbase || 10;
677680

678681
ax._tickexponent = 0;
679682
if(!isNumeric(dtick) && typeof dtick !== 'string') dtick = 1;
@@ -690,14 +693,14 @@ function autoTickRound(ax) {
690693
else {
691694
if(!isNumeric(dtick)) dtick = Number(dtick.substr(1));
692695
// 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);
694697

695698
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]));
697700
}
698701
else maxend = Math.max(Math.abs(ax.range[0]), Math.abs(ax.range[1]));
699702

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);
701704
if(Math.abs(rangeexp) > 3) {
702705
if(ax.exponentformat === 'SI' || ax.exponentformat === 'B') {
703706
ax._tickexponent = 3 * Math.round((rangeexp - 1) / 3);
@@ -757,7 +760,9 @@ axes.tickFirst = function(ax){
757760
// that may have been rounded out
758761
r0 = ax.range[0] * 1.0001 - ax.range[1] * 0.0001,
759762
dtick = ax.dtick,
760-
tick0 = ax.tick0;
763+
tick0 = ax.tick0,
764+
exponentbase = ax.exponentbase || 10;
765+
761766
if(isNumeric(dtick)) {
762767
var tmin = sRound((r0 - tick0) / dtick) * dtick + tick0;
763768

@@ -792,14 +797,14 @@ axes.tickFirst = function(ax){
792797
// Log scales: Linear, Digits
793798
else if(tType === 'L') {
794799
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);
796801
}
797802
else if(tType === 'D') {
798803
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
799804
frac = Plotly.Lib.roundUp(mod(r0, 1), tickset, axrev);
800805

801806
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);
803808
}
804809
else throw 'unrecognized dtick ' + String(dtick);
805810
};
@@ -946,7 +951,7 @@ function formatDate(ax, out, hover, extraPrecision) {
946951

947952
function formatLog(ax, out, hover, extraPrecision, hideexp) {
948953
var dtick = ax.dtick,
949-
base = ax.exponentbase,
954+
base = ax.exponentbase || 10,
950955
x = out.x;
951956
if(extraPrecision && ((typeof dtick !== 'string') || dtick.charAt(0)!=='L')) dtick = 'L3';
952957

@@ -1021,8 +1026,8 @@ function numFormat(v, ax, fmtoverride, hover) {
10211026
tickRound = ax._tickround,
10221027
exponentFormat = fmtoverride || ax.exponentformat || 'B',
10231028
exponent = ax._tickexponent,
1024-
base = +ax.exponentbase || 10,
1025-
isBase10 = (base === 10),
1029+
exponentbase = ax.exponentbase || 10,
1030+
isBase10 = (exponentbase === 10),
10261031
tickformat = ax.tickformat;
10271032

10281033
// special case for hover: set exponent just for this value, and
@@ -1031,7 +1036,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10311036
// make a dummy axis obj to get the auto rounding and exponent
10321037
var ah = {
10331038
exponentformat:ax.exponentformat,
1034-
exponentbase: ax.exponentbase,
1039+
exponentbase: exponentbase,
10351040
dtick: ax.showexponent==='none' ? ax.dtick :
10361041
(isNumeric(v) ? Math.abs(v) || 1 : 1),
10371042
// if not showing any exponents, don't change the exponent
@@ -1047,7 +1052,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10471052
if(tickformat) return d3.format(tickformat)(v).replace(/-/g,'\u2212');
10481053

10491054
// 'epsilon' - rounding increment
1050-
var e = isBase10 ? Math.pow(base, -tickRound) / 2 : 0;
1055+
var e = isBase10 ? Math.pow(exponentbase, -tickRound) / 2 : 0;
10511056
// var e = 0;
10521057

10531058
// exponentFormat codes:
@@ -1074,7 +1079,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10741079
// take out a common exponent, if any
10751080
// Special case for base 2 to follow "SI"
10761081
if(exponent){
1077-
v *= Math.pow(base, -exponent);
1082+
v *= Math.pow(exponentbase, -exponent);
10781083
tickRound += exponent;
10791084
}
10801085

@@ -1111,16 +1116,16 @@ function numFormat(v, ax, fmtoverride, hover) {
11111116
} else if(exponentFormat === 'B' && exponent === 9) {
11121117
v += 'B';
11131118
} 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));
11161121
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));
11191124
exponent = 0;
11201125
}
11211126
v += SIPREFIXES[exponent / 3 + 5];
11221127
} else {
1123-
v += '&times;' + base + '<sup>' + signedExponent + '</sup>';
1128+
v += '&times;' + exponentbase + '<sup>' + signedExponent + '</sup>';
11241129
}
11251130
}
11261131

0 commit comments

Comments
 (0)