Skip to content

Commit b7f71a6

Browse files
authored
fix: round chart numbers in applyDataCorrection for consistent rounding (#2556)
1 parent cbcdc54 commit b7f71a6

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

app/components/Chart/SplitSparkline.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ const props = defineProps<{
3131
3232
const { locale } = useI18n()
3333
const colorMode = useColorMode()
34-
const numberFormatter = useNumberFormatter({
35-
maximumFractionDigits: 0,
36-
})
34+
const numberFormatter = useNumberFormatter()
3735
const resolvedMode = shallowRef<'light' | 'dark'>('light')
3836
const rootEl = shallowRef<HTMLElement | null>(null)
3937
const palette = getPalette('')

app/components/Package/TrendsChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ const chartConfig = computed<VueUiXyConfig>(() => {
15401540
const rows = items
15411541
.map((d: Record<string, any>) => {
15421542
const label = String(d?.name ?? '').trim()
1543-
const raw = Math.round(Number(d?.value ?? 0))
1543+
const raw = Number(d?.value ?? 0)
15441544
const v = compactNumberFormatter.value.format(Number.isFinite(raw) ? raw : 0)
15451545
15461546
if (!hasMultipleItems) {

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ function handleModalTransitioned() {
6060
}
6161
6262
const { fetchPackageDownloadEvolution } = useCharts()
63-
const numberFormatter = useNumberFormatter({
64-
maximumFractionDigits: 0,
65-
})
63+
const numberFormatter = useNumberFormatter()
6664
6765
const { accentColors, selectedAccentColor } = useAccentColor()
6866

app/utils/chart-data-correction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface ChartFilterSettings {
8383
}
8484

8585
/**
86-
* Applies moving average then smoothing in sequence.
86+
* Applies moving average, smoothing and then rounding up in sequence.
8787
*/
8888
export function applyDataCorrection<T extends { value: number }>(
8989
data: T[],
@@ -92,5 +92,6 @@ export function applyDataCorrection<T extends { value: number }>(
9292
let result = data
9393
result = movingAverage(result, settings.averageWindow)
9494
result = smoothing(result, settings.smoothingTau)
95+
result = result.map(d => ({ ...d, value: Math.ceil(d.value) }))
9596
return result
9697
}

0 commit comments

Comments
 (0)