diff --git a/app/components/Package/TrendsChart.vue b/app/components/Package/TrendsChart.vue index 7d08014719..08792b00e8 100644 --- a/app/components/Package/TrendsChart.vue +++ b/app/components/Package/TrendsChart.vue @@ -23,7 +23,7 @@ import { endDateOnlyToUtcMs, DEFAULT_PREDICTION_POINTS, } from '~/utils/chart-data-prediction' -import { applyBlocklistCorrection, getAnomaliesForPackages } from '~/utils/download-anomalies' +import { applyHampelCorrection } from '~/utils/download-anomalies' import { copyAltTextForTrendLineChart, sanitise, loadFile, applyEllipsis } from '~/utils/charts' import('vue-data-ui/style.css') @@ -976,12 +976,10 @@ const effectiveDataSingle = computed(() => { } if (isDownloadsMetric.value && data.length) { - const pkg = effectivePackageNames.value[0] ?? props.packageName ?? '' if (settings.value.chartFilter.anomaliesFixed) { - data = applyBlocklistCorrection({ - data, - packageName: pkg, - granularity: displayedGranularity.value, + data = applyHampelCorrection(data, { + halfWindow: settings.value.chartFilter.hampelWindow, + threshold: settings.value.chartFilter.hampelThreshold, }) } } @@ -1026,7 +1024,10 @@ const chartData = computed<{ let data = state.evolutionsByPackage[pkg] ?? [] if (isDownloadsMetric.value && data.length) { if (settings.value.chartFilter.anomaliesFixed) { - data = applyBlocklistCorrection({ data, packageName: pkg, granularity }) + data = applyHampelCorrection(data, { + halfWindow: settings.value.chartFilter.hampelWindow, + threshold: settings.value.chartFilter.hampelThreshold, + }) } } const points = extractSeriesPoints(granularity, data) @@ -1556,20 +1557,6 @@ const chartConfig = computed(() => { const isDownloadsMetric = computed(() => selectedMetric.value === 'downloads') const showCorrectionControls = shallowRef(false) -const packageAnomalies = computed(() => getAnomaliesForPackages(effectivePackageNames.value)) -const hasAnomalies = computed(() => packageAnomalies.value.length > 0) - -function formatAnomalyDate(dateStr: string) { - const [y, m, d] = dateStr.split('-').map(Number) - if (!y || !m || !d) return dateStr - return new Intl.DateTimeFormat(locale.value, { - year: 'numeric', - month: 'short', - day: 'numeric', - timeZone: 'UTC', - }).format(new Date(Date.UTC(y, m - 1, d))) -} - // Trigger data loading when the metric is switched watch(selectedMetric, value => { if (!isMounted.value) return @@ -1717,69 +1704,63 @@ watch(selectedMetric, value => { class="accent-[var(--accent-color,var(--fg-subtle))]" /> + +
+ +
{{ $t('package.trends.known_anomalies') }} - +