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

Skip to content

Commit 4cb2192

Browse files
committed
Gridlines use exponent base
1 parent 7f785d5 commit 4cb2192

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/plots/cartesian/axes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,9 @@ axes.autoTicks = function(ax, roughDTick){
649649
ax.dtick = Math.ceil(Math.max(roughDTick, 1));
650650
}
651651
else{
652-
// auto ticks always start at 0
652+
// auto ticks always start at 0 and increment
653653
ax.tick0 = 0;
654-
base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10));
654+
base = Math.pow(ax.exponentbase, Math.floor(Math.log(roughDTick) / Math.log(ax.exponentbase)));
655655
ax.dtick = roundDTick(roughDTick, base, roundBase10);
656656
}
657657

@@ -1013,12 +1013,13 @@ function formatLinear(ax, out, hover, extraPrecision, hideexp) {
10131013
// also automatically switch to sci. notation
10141014
var SIPREFIXES = ['f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T'];
10151015
function numFormat(v, ax, fmtoverride, hover) {
1016-
// negative?
1016+
// negative?
10171017
var isNeg = v < 0,
10181018
// max number of digits past decimal point to show
10191019
tickRound = ax._tickround,
10201020
exponentFormat = fmtoverride || ax.exponentformat || 'B',
10211021
exponent = ax._tickexponent,
1022+
base = ax.exponentbase || 10,
10221023
tickformat = ax.tickformat;
10231024

10241025
// special case for hover: set exponent just for this value, and
@@ -1027,6 +1028,7 @@ function numFormat(v, ax, fmtoverride, hover) {
10271028
// make a dummy axis obj to get the auto rounding and exponent
10281029
var ah = {
10291030
exponentformat:ax.exponentformat,
1031+
exponentbase: ax.exponentbase,
10301032
dtick: ax.showexponent==='none' ? ax.dtick :
10311033
(isNumeric(v) ? Math.abs(v) || 1 : 1),
10321034
// if not showing any exponents, don't change the exponent

src/plots/cartesian/layout_attributes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ module.exports = {
288288
'If *B*, 1B.'
289289
].join(' ')
290290
},
291+
exponentbase: {
292+
valType: 'number',
293+
min: 0,
294+
dflt: 10
295+
role: 'style',
296+
description: [
297+
'Determines the base for axes and exponent labels.'
298+
].join(' ')
299+
},
291300
tickformat: {
292301
valType: 'string',
293302
dflt: '',

src/plots/cartesian/tick_defaults.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ module.exports = function handleTickDefaults(containerIn, containerOut, coerce,
4242

4343
if(!tickFormat && axType !== 'date') {
4444
coerce('showexponent', showAttrDflt);
45-
coerce('exponentformat');
45+
46+
var expBase = coerce('exponentbase'),
47+
expFmtDflt = coerce('exponentformat');
48+
49+
if (expBase !== 2 && expBase !== 10) expFmtDflt = 'power';
50+
if (expBase === 2 && expFmtDflt !== 'SI') expFmtDflt = 'power';
51+
if (expBase === 'e'){
52+
containerOut.exponentbase = Math.E;
53+
containerOut.type = 'log';
54+
}
55+
56+
containerOut.exponentformat = expFmtDflt;
4657
}
4758
}
4859

0 commit comments

Comments
 (0)