Skip to content

Commit 98c6937

Browse files
author
Ignacio Martinez
committed
Add eng exponentformat for engineering notation
Works just like `SI`, except it uses prefixes for kilo- and milli-.
1 parent 4ac68aa commit 98c6937

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/plots/cartesian/axes.js

Lines changed: 2 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) {
1045+
if(Math.abs(rangeexp) > 3 || ax.exponentformat === 'eng') {
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';
1499+
return exponentFormat === 'SI' || exponentFormat === 'B' || exponentFormat === 'eng';
15001500
}
15011501

15021502
// are we beyond the range of common SI prefixes?

src/plots/cartesian/layout_attributes.js

Lines changed: 3 additions & 2 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'],
668+
values: ['none', 'e', 'E', 'power', 'SI', 'B', 'eng'],
669669
dflt: 'B',
670670
role: 'style',
671671
editType: 'ticks',
@@ -677,7 +677,8 @@ 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.'
680+
'If *B*, 1B.',
681+
'*eng* works like *SI*, except it also uses prefixes for milli- and kilo-.'
681682
].join(' ')
682683
},
683684
separatethousands: {

src/traces/carpet/axis_attributes.js

Lines changed: 3 additions & 2 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'],
272+
values: ['none', 'e', 'E', 'power', 'SI', 'B', 'eng'],
273273
dflt: 'B',
274274
role: 'style',
275275
editType: 'calc',
@@ -281,7 +281,8 @@ 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.'
284+
'If *B*, 1B.',
285+
'*eng* works like *SI*, except it also uses prefixes for milli- and kilo-.'
285286
].join(' ')
286287
},
287288
separatethousands: {

0 commit comments

Comments
 (0)