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

Skip to content

Commit 3a64fb7

Browse files
committed
Gridlines use exponent base
1 parent 183b4b9 commit 3a64fb7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/plots/cartesian/axes.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ axes.handleTickDefaults = function(containerIn, containerOut, coerce, axType, op
250250
if(!tickFormat && axType !== 'date') {
251251
coerce('showexponent', showAttrDflt);
252252
coerce('exponentformat');
253+
coerce('exponentbase');
253254
}
254255
}
255256

@@ -1387,9 +1388,9 @@ axes.autoTicks = function(ax, roughDTick){
13871388
ax.dtick = Math.ceil(Math.max(roughDTick, 1));
13881389
}
13891390
else{
1390-
// auto ticks always start at 0
1391+
// auto ticks always start at 0 and increment
13911392
ax.tick0 = 0;
1392-
base = Math.pow(10, Math.floor(Math.log(roughDTick) / Math.LN10));
1393+
base = Math.pow(ax.exponentbase, Math.floor(Math.log(roughDTick) / Math.log(ax.exponentbase)));
13931394
ax.dtick = roundDTick(roughDTick, base, roundBase10);
13941395
}
13951396

@@ -1750,12 +1751,13 @@ function formatLinear(ax, out, hover, extraPrecision, hideexp) {
17501751
// also automatically switch to sci. notation
17511752
var SIPREFIXES = ['f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T'];
17521753
function numFormat(v, ax, fmtoverride, hover) {
1753-
// negative?
1754+
// negative?
17541755
var isNeg = v < 0,
17551756
// max number of digits past decimal point to show
17561757
tickRound = ax._tickround,
17571758
exponentFormat = fmtoverride || ax.exponentformat || 'B',
17581759
exponent = ax._tickexponent,
1760+
base = ax.exponentbase || 10,
17591761
tickformat = ax.tickformat;
17601762

17611763
// special case for hover: set exponent just for this value, and
@@ -1764,6 +1766,7 @@ function numFormat(v, ax, fmtoverride, hover) {
17641766
// make a dummy axis obj to get the auto rounding and exponent
17651767
var ah = {
17661768
exponentformat:ax.exponentformat,
1769+
exponentbase: ax.exponentbase,
17671770
dtick: ax.showexponent==='none' ? ax.dtick :
17681771
(isNumeric(v) ? Math.abs(v) || 1 : 1),
17691772
// 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
@@ -289,6 +289,15 @@ module.exports = {
289289
'If *B*, 1B.'
290290
].join(' ')
291291
},
292+
exponentbase: {
293+
valType: 'number',
294+
min: 0,
295+
dflt: 10
296+
role: 'style',
297+
description: [
298+
'Determines the base for axes and exponent labels.'
299+
].join(' ')
300+
},
292301
tickformat: {
293302
valType: 'string',
294303
dflt: '',

0 commit comments

Comments
 (0)