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

Skip to content

Commit d89bde5

Browse files
committed
log scales with exponent base
1 parent de2ed48 commit d89bde5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/plots/cartesian/axes.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ axes.autoBin = function(data,ax,nbins,is2d) {
361361
// the size get smaller than the 'nice' rounded down minimum
362362
// difference between values
363363
var distinctData = Plotly.Lib.distinctVals(data),
364-
msexp = Math.pow(10, Math.floor(
365-
Math.log(distinctData.minDiff) / Math.LN10)),
364+
msexp = Math.pow(ax.exponentbase, Math.floor(
365+
Math.log(distinctData.minDiff) / Math.log(ax.exponentbase))),
366366
// TODO: there are some date cases where this will fail...
367367
minSize = msexp*Plotly.Lib.roundUp(
368368
distinctData.minDiff/msexp, [0.9, 1.9, 4.9, 9.9], true);
@@ -792,14 +792,14 @@ axes.tickFirst = function(ax){
792792
// Log scales: Linear, Digits
793793
else if(tType === 'L') {
794794
return Math.log(sRound(
795-
(Math.pow(10, r0) - tick0) / dtNum) * dtNum + tick0) / Math.LN10;
795+
(Math.pow(ax.exponentbase, r0) - tick0) / dtNum) * dtNum + tick0) / Math.log(ax.exponentbase);
796796
}
797797
else if(tType === 'D') {
798798
var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
799799
frac = Plotly.Lib.roundUp(mod(r0, 1), tickset, axrev);
800800

801801
return Math.floor(r0) +
802-
Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
802+
Math.log(d3.round(Math.pow(ax.exponentbase, frac), 1)) / Math.log(ax.exponentbase);
803803
}
804804
else throw 'unrecognized dtick ' + String(dtick);
805805
};
@@ -946,31 +946,32 @@ function formatDate(ax, out, hover, extraPrecision) {
946946

947947
function formatLog(ax, out, hover, extraPrecision, hideexp) {
948948
var dtick = ax.dtick,
949+
base = ax.exponentbase,
949950
x = out.x;
950951
if(extraPrecision && ((typeof dtick !== 'string') || dtick.charAt(0)!=='L')) dtick = 'L3';
951952

952953
if(ax.tickformat || (typeof dtick === 'string' && dtick.charAt(0) === 'L')) {
953-
out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision);
954+
out.text = numFormat(Math.pow(base, x), ax, hideexp, extraPrecision);
954955
}
955956
else if(isNumeric(dtick)||((dtick.charAt(0)==='D')&&(mod(x+0.01,1)<0.1))) {
956957
if(['e','E','power'].indexOf(ax.exponentformat)!==-1) {
957958
var p = Math.round(x);
958959
if(p === 0) out.text = 1;
959-
else if(p === 1) out.text = '10';
960-
else if(p > 1) out.text = '10<sup>' + p + '</sup>';
961-
else out.text = '10<sup>\u2212' + -p + '</sup>';
960+
else if(p === 1) out.text = base;
961+
else if(p > 1) out.text = base + '<sup>' + p + '</sup>';
962+
else out.text = base + '<sup>\u2212' + -p + '</sup>';
962963

963964
out.fontSize *= 1.25;
964965
}
965966
else {
966-
out.text = numFormat(Math.pow(10,x), ax,'','fakehover');
967+
out.text = numFormat(Math.pow(base,x), ax,'','fakehover');
967968
if(dtick==='D1' && ax._id.charAt(0)==='y') {
968969
out.dy -= out.fontSize/6;
969970
}
970971
}
971972
}
972973
else if(dtick.charAt(0) === 'D') {
973-
out.text = String(Math.round(Math.pow(10, mod(x, 1))));
974+
out.text = String(Math.round(Math.pow(base, mod(x, 1))));
974975
out.fontSize *= 0.75;
975976
}
976977
else throw 'unrecognized dtick ' + String(dtick);

0 commit comments

Comments
 (0)