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

Skip to content

Commit 8ac9ef5

Browse files
committed
Uses correct formatting per base
1 parent 9beef0c commit 8ac9ef5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/plots/cartesian/axes.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ axes.autoBin = function(data,ax,nbins,is2d) {
373373
// piggyback off autotick code to make "nice" bin sizes
374374
var dummyax = {
375375
type: ax.type==='log' ? 'linear' : ax.type,
376-
range:[datamin, datamax],
377-
exponentbase: ax.exponentbase
376+
range:[datamin, datamax]
378377
};
379378
axes.autoTicks(dummyax, size0);
380379
var binstart = axes.tickIncrement(
@@ -691,7 +690,7 @@ function autoTickRound(ax) {
691690
else {
692691
if(!isNumeric(dtick)) dtick = Number(dtick.substr(1));
693692
// 2 digits past largest digit of dtick
694-
ax._tickround = 2 - Math.floor(Math.log(dtick) / Math.LN10 + 0.01);
693+
ax._tickround = 2 - Math.floor(Math.log(dtick) / Math.log(ax.exponentbase) + 0.01);
695694

696695
if(ax.type === 'log') {
697696
maxend = Math.pow(10, Math.max(ax.range[0], ax.range[1]));
@@ -1021,6 +1020,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10211020
exponentFormat = fmtoverride || ax.exponentformat || 'B',
10221021
exponent = ax._tickexponent,
10231022
base = ax.exponentbase || 10,
1023+
isBase10 = (base === 10),
10241024
tickformat = ax.tickformat;
10251025

10261026
// special case for hover: set exponent just for this value, and
@@ -1045,7 +1045,7 @@ 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(10, -tickRound) / 2;
1048+
var e = Math.pow(base, -tickRound) / 2;
10491049

10501050
// exponentFormat codes:
10511051
// 'e' (1.2e+6, default)
@@ -1069,8 +1069,8 @@ function numFormat(v, ax, fmtoverride, hover) {
10691069
v += e;
10701070
// take out a common exponent, if any
10711071
// Special case for base 2 to follow "SI"
1072-
if(exponent && base === 2) {
1073-
v = v/1024;
1072+
if(exponent && base === 2 && exponentFormat === 'SI') {
1073+
v = v / 1024;
10741074

10751075
// To make 1024 -> 1k
10761076
exponent -= 9;
@@ -1105,13 +1105,13 @@ function numFormat(v, ax, fmtoverride, hover) {
11051105

11061106
if(exponentFormat === 'e' ||
11071107
((exponentFormat === 'SI' || exponentFormat === 'B') &&
1108-
(exponent > 12 || exponent < -15))) {
1108+
(exponent > 12 || exponent < -15)) && isBase10) {
11091109
v += 'e' + signedExponent;
1110-
} else if(exponentFormat === 'E' && base === 10) {
1110+
} else if(exponentFormat === 'E') {
11111111
v += 'E' + signedExponent;
1112-
} else if(exponentFormat === 'B' && exponent === 9 && base === 10) {
1112+
} else if(exponentFormat === 'B' && exponent === 9) {
11131113
v += 'B';
1114-
} else if((exponentFormat === 'SI' || exponentFormat === 'B') && (base === 2 || base === 10)) {
1114+
} else if(exponentFormat === 'SI' || exponentFormat === 'B') {
11151115
v += SIPREFIXES[exponent / 3 + 5];
11161116
} else {
11171117
v += '&times;' + base + '<sup>' + signedExponent + '</sup>';

0 commit comments

Comments
 (0)