Skip to content

Commit 4fedb2e

Browse files
committed
fix(label): improve range label formating
1 parent eebb926 commit 4fedb2e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/e3sm_quickview/module/serve/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ window.trame.utils.quickview = {
66
if (useLog && value > 0) {
77
return `10^(${Math.log10(value).toFixed(1)})`;
88
}
9+
const nSignDigit = Math.log10(Math.abs(value));
10+
if (Math.abs(nSignDigit) < 6 || value === 0) {
11+
if (nSignDigit > 0 && nSignDigit < 3) {
12+
return new Intl.NumberFormat("US", { maximumFractionDigits: 2 }).format(
13+
value,
14+
);
15+
}
16+
if (nSignDigit > 3) {
17+
return new Intl.NumberFormat("US", { maximumFractionDigits: 0 }).format(
18+
value,
19+
);
20+
}
21+
22+
return new Intl.NumberFormat().format(value);
23+
}
924
return value.toExponential(1);
1025
},
1126
cols(size) {

0 commit comments

Comments
 (0)