Skip to content

Commit 65ae0f0

Browse files
author
Ignacio Martinez
committed
Create new axis attribute minexponent
Hide SI prefix for 10^n if |n| <= minexponent
1 parent 98c6937 commit 65ae0f0

File tree

10 files changed

+33
-8
lines changed

10 files changed

+33
-8
lines changed

src/components/colorbar/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ module.exports = overrideAll({
173173
showticksuffix: axesAttrs.showticksuffix,
174174
separatethousands: axesAttrs.separatethousands,
175175
exponentformat: axesAttrs.exponentformat,
176+
minexponent: axesAttrs.minexponent,
176177
showexponent: axesAttrs.showexponent,
177178
title: {
178179
text: {

src/plots/cartesian/axes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ function autoTickRound(ax) {
10421042

10431043
var maxend = Math.max(Math.abs(rng[0]), Math.abs(rng[1]));
10441044
var rangeexp = Math.floor(Math.log(maxend) / Math.LN10 + 0.01);
1045-
if(Math.abs(rangeexp) > 3 || ax.exponentformat === 'eng') {
1045+
if(Math.abs(rangeexp) > ax.minexponent) {
10461046
if(isSIFormat(ax.exponentformat) && !beyondSI(rangeexp)) {
10471047
ax._tickexponent = 3 * Math.round((rangeexp - 1) / 3);
10481048
} else ax._tickexponent = rangeexp;
@@ -1496,7 +1496,7 @@ function num2frac(num) {
14961496
var SIPREFIXES = ['f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T'];
14971497

14981498
function isSIFormat(exponentFormat) {
1499-
return exponentFormat === 'SI' || exponentFormat === 'B' || exponentFormat === 'eng';
1499+
return exponentFormat === 'SI' || exponentFormat === 'B';
15001500
}
15011501

15021502
// are we beyond the range of common SI prefixes?
@@ -1525,6 +1525,7 @@ function numFormat(v, ax, fmtoverride, hover) {
15251525
// make a dummy axis obj to get the auto rounding and exponent
15261526
var ah = {
15271527
exponentformat: exponentFormat,
1528+
minexponent: ax.minexponent,
15281529
dtick: ax.showexponent === 'none' ? ax.dtick :
15291530
(isNumeric(v) ? Math.abs(v) || 1 : 1),
15301531
// if not showing any exponents, don't change the exponent

src/plots/cartesian/layout_attributes.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ module.exports = {
665665
},
666666
exponentformat: {
667667
valType: 'enumerated',
668-
values: ['none', 'e', 'E', 'power', 'SI', 'B', 'eng'],
668+
values: ['none', 'e', 'E', 'power', 'SI', 'B'],
669669
dflt: 'B',
670670
role: 'style',
671671
editType: 'ticks',
@@ -677,8 +677,16 @@ module.exports = {
677677
'If *E*, 1E+9.',
678678
'If *power*, 1x10^9 (with 9 in a super script).',
679679
'If *SI*, 1G.',
680-
'If *B*, 1B.',
681-
'*eng* works like *SI*, except it also uses prefixes for milli- and kilo-.'
680+
'If *B*, 1B.'
681+
].join(' ')
682+
},
683+
minexponent: {
684+
valType: 'number',
685+
dflt: 3,
686+
role: 'style',
687+
editType: 'ticks',
688+
description: [
689+
'Hide SI prefix for 10^n if |n| is below this number'
682690
].join(' ')
683691
},
684692
separatethousands: {

src/plots/cartesian/tick_label_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function handleOtherDefaults(containerIn, containerOut, coerce, axType, options)
7272
if(!tickFormat && axType !== 'date') {
7373
coerce('showexponent', showAttrDflt);
7474
coerce('exponentformat');
75+
coerce('minexponent');
7576
coerce('separatethousands');
7677
}
7778
}

src/plots/gl3d/layout/axis_attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = overrideAll({
108108
showticksuffix: axesAttrs.showticksuffix,
109109
showexponent: axesAttrs.showexponent,
110110
exponentformat: axesAttrs.exponentformat,
111+
minexponent: axesAttrs.minexponent,
111112
separatethousands: axesAttrs.separatethousands,
112113
tickformat: axesAttrs.tickformat,
113114
tickformatstops: axesAttrs.tickformatstops,

src/plots/polar/layout_attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var axisTickAttrs = overrideAll({
4747
ticksuffix: axesAttrs.ticksuffix,
4848
showexponent: axesAttrs.showexponent,
4949
exponentformat: axesAttrs.exponentformat,
50+
minexponent: axesAttrs.minexponent,
5051
separatethousands: axesAttrs.separatethousands,
5152
tickfont: axesAttrs.tickfont,
5253
tickangle: axesAttrs.tickangle,

src/plots/ternary/layout_attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var ternaryAxesAttrs = {
4040
ticksuffix: axesAttrs.ticksuffix,
4141
showexponent: axesAttrs.showexponent,
4242
exponentformat: axesAttrs.exponentformat,
43+
minexponent: axesAttrs.minexponent,
4344
separatethousands: axesAttrs.separatethousands,
4445
tickfont: axesAttrs.tickfont,
4546
tickangle: axesAttrs.tickangle,

src/traces/carpet/axis_attributes.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ module.exports = {
269269
},
270270
exponentformat: {
271271
valType: 'enumerated',
272-
values: ['none', 'e', 'E', 'power', 'SI', 'B', 'eng'],
272+
values: ['none', 'e', 'E', 'power', 'SI', 'B'],
273273
dflt: 'B',
274274
role: 'style',
275275
editType: 'calc',
@@ -281,8 +281,16 @@ module.exports = {
281281
'If *E*, 1E+9.',
282282
'If *power*, 1x10^9 (with 9 in a super script).',
283283
'If *SI*, 1G.',
284-
'If *B*, 1B.',
285-
'*eng* works like *SI*, except it also uses prefixes for milli- and kilo-.'
284+
'If *B*, 1B.'
285+
].join(' ')
286+
},
287+
minexponent: {
288+
valType: 'number',
289+
dflt: 3,
290+
role: 'style',
291+
editType: 'ticks',
292+
description: [
293+
'Hide SI prefix for 10^n if |n| is below this number'
286294
].join(' ')
287295
},
288296
separatethousands: {

src/traces/carpet/axis_defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
7878
coerce('separatethousands');
7979
coerce('tickformat');
8080
coerce('exponentformat');
81+
coerce('minexponent');
8182
coerce('showexponent');
8283
coerce('categoryorder');
8384

@@ -186,6 +187,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
186187
delete containerOut.tickangle;
187188
delete containerOut.showexponent;
188189
delete containerOut.exponentformat;
190+
delete containerOut.minexponent;
189191
delete containerOut.tickformat;
190192
delete containerOut.showticksuffix;
191193
delete containerOut.showtickprefix;

src/traces/indicator/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ module.exports = {
355355
showticksuffix: axesAttrs.showticksuffix,
356356
separatethousands: axesAttrs.separatethousands,
357357
exponentformat: axesAttrs.exponentformat,
358+
minexponent: axesAttrs.minexponent,
358359
showexponent: axesAttrs.showexponent,
359360
editType: 'plot'
360361
}, 'plot'),

0 commit comments

Comments
 (0)