Skip to content

Commit f8ecd4a

Browse files
committed
fix: only use compact notation if ticks span multiple magnitudes
1 parent 7584d7f commit f8ecd4a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/lib/core/Plot.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
locale: 'en-US',
7474
numberFormat: {
7575
style: 'decimal',
76-
notation: 'compact',
76+
// notation: 'compact',
7777
compactDisplay: 'short'
7878
},
7979
markerDotRadius: 3,

src/lib/marks/AxisX.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@
8989
)
9090
);
9191
92-
let tickFmt = $derived(tickFormat || plot.options.x.tickFormat);
92+
const tickFmt = $derived(tickFormat || plot.options.x.tickFormat);
9393
94-
let useTickFormat = $derived(
94+
const useTickFormat = $derived(
9595
typeof tickFmt === 'function'
9696
? tickFmt
9797
: plot.scales.x.type === 'band' || plot.scales.x.type === 'point'
@@ -107,6 +107,10 @@
107107
: // auto
108108
(d: RawValue) =>
109109
Intl.NumberFormat(plot.options.locale, {
110+
// use compact notation if range covers multipe magnitudes
111+
...(new Set(ticks.map(Math.log10).map(Math.round)).size > 1
112+
? { notation: 'compact' }
113+
: {}),
110114
...DEFAULTS.numberFormat,
111115
style: plot.options.x.percent ? 'percent' : 'decimal'
112116
}).format(d)

src/lib/marks/AxisY.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
: // auto
106106
(d: RawValue) =>
107107
Intl.NumberFormat(plot.options.locale, {
108+
// use compact notation if range covers multipe magnitudes
109+
...(new Set(ticks.map(Math.log10).map(Math.round)).size > 1
110+
? { notation: 'compact' }
111+
: {}),
108112
...DEFAULTS.numberFormat,
109113
style: plot.options.y.percent ? 'percent' : 'decimal'
110114
}).format(d)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy