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

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit de2ed48

Browse files
committed
exponent bases fixed for linear
1 parent 8ac9ef5 commit de2ed48

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/plots/cartesian/axes.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ axes.autoTicks = function(ax, roughDTick){
632632
var nt = 1.5 * Math.abs((ax.range[1] - ax.range[0]) / roughDTick);
633633

634634
// ticks on a linear scale, labeled fully
635-
roughDTick = Math.abs(Math.pow(10, ax.range[1]) -
636-
Math.pow(10, ax.range[0])) / nt;
637-
base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10));
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)));
638638
ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);
639639
}
640640
else {
@@ -693,7 +693,7 @@ function autoTickRound(ax) {
693693
ax._tickround = 2 - Math.floor(Math.log(dtick) / Math.log(ax.exponentbase) + 0.01);
694694

695695
if(ax.type === 'log') {
696-
maxend = Math.pow(10, Math.max(ax.range[0], ax.range[1]));
696+
maxend = Math.pow(ax.exponentbase, Math.max(ax.range[0], ax.range[1]));
697697
}
698698
else maxend = Math.max(Math.abs(ax.range[0]), Math.abs(ax.range[1]));
699699

@@ -1019,7 +1019,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10191019
tickRound = ax._tickround,
10201020
exponentFormat = fmtoverride || ax.exponentformat || 'B',
10211021
exponent = ax._tickexponent,
1022-
base = ax.exponentbase || 10,
1022+
base = +ax.exponentbase || 10,
10231023
isBase10 = (base === 10),
10241024
tickformat = ax.tickformat;
10251025

@@ -1045,7 +1045,8 @@ function numFormat(v, ax, fmtoverride, hover) {
10451045
if(tickformat) return d3.format(tickformat)(v).replace(/-/g,'\u2212');
10461046

10471047
// 'epsilon' - rounding increment
1048-
var e = Math.pow(base, -tickRound) / 2;
1048+
var e = isBase10 ? Math.pow(base, -tickRound) / 2 : 0;
1049+
// var e = 0;
10491050

10501051
// exponentFormat codes:
10511052
// 'e' (1.2e+6, default)
@@ -1061,6 +1062,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10611062
// take the sign out, put it back manually at the end
10621063
// - makes cases easier
10631064
v = Math.abs(v);
1065+
10641066
if(v < e) {
10651067
// 0 is just 0, but may get exponent if it's the last tick
10661068
v = '0';
@@ -1069,16 +1071,11 @@ function numFormat(v, ax, fmtoverride, hover) {
10691071
v += e;
10701072
// take out a common exponent, if any
10711073
// Special case for base 2 to follow "SI"
1072-
if(exponent && base === 2 && exponentFormat === 'SI') {
1073-
v = v / 1024;
1074-
1075-
// To make 1024 -> 1k
1076-
exponent -= 9;
1077-
tickRound += exponent;
1078-
} else {
1074+
if(exponent){
10791075
v *= Math.pow(base, -exponent);
10801076
tickRound += exponent;
10811077
}
1078+
10821079
// round the mantissa
10831080
if(tickRound === 0) v = String(Math.floor(v));
10841081
else if(tickRound < 0) {
@@ -1112,6 +1109,13 @@ function numFormat(v, ax, fmtoverride, hover) {
11121109
} else if(exponentFormat === 'B' && exponent === 9) {
11131110
v += 'B';
11141111
} else if(exponentFormat === 'SI' || exponentFormat === 'B') {
1112+
if(base === 2 && exponent >= 10){
1113+
v = v * Math.pow(base, (exponent - 10));
1114+
exponent -= 9;
1115+
} else if(base === 2 && exponent < 10){
1116+
v = v * Math.pow(base, (exponent));
1117+
exponent = 0;
1118+
}
11151119
v += SIPREFIXES[exponent / 3 + 5];
11161120
} else {
11171121
v += '&times;' + base + '<sup>' + signedExponent + '</sup>';

src/plots/cartesian/layout_attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ module.exports = {
289289
].join(' ')
290290
},
291291
exponentbase: {
292-
valType: 'number',
293-
min: 2,
292+
valType: 'enumerated',
293+
values: [2, '2', 'e', 8, '8', 10, '10', 16, '16'],
294294
dflt: 10,
295295
role: 'style',
296296
description: [

0 commit comments

Comments
 (0)