Skip to content

Commit 256a457

Browse files
committed
fix: various
1 parent e4815da commit 256a457

4 files changed

Lines changed: 44 additions & 44 deletions

File tree

app/components/Package/TimelineChart.vue

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const props = defineProps<{
2828
selectedVersion: string | null
2929
}>()
3030
31+
const { settings } = useSettings()
3132
const route = useRoute('timeline')
3233
3334
const activeVersion = computed(() => route.params.version)
@@ -36,43 +37,6 @@ const packageName = computed(() =>
3637
route.params.org ? `${route.params.org}/${route.params.packageName}` : route.params.packageName,
3738
)
3839
39-
function addTimelineEntries(
40-
entries: ConvertedTimelineSizeCacheEntry[],
41-
timelineEntries: TimelineVersion[],
42-
): EnrichedTimelineSizeCacheEntry[] {
43-
const timelineEntryByVersion = new Map(timelineEntries.map(entry => [entry.version, entry]))
44-
45-
return entries.map(entry => {
46-
const version = entry.name.split('@')[1] ?? ''
47-
const timelineEntry = timelineEntryByVersion.get(version)
48-
49-
return {
50-
...entry,
51-
version,
52-
time: timelineEntry?.time,
53-
license: timelineEntry?.license,
54-
type: timelineEntry?.type,
55-
hasTypes: timelineEntry?.hasTypes,
56-
hasTrustedPublisher: timelineEntry?.hasTrustedPublisher,
57-
hasProvenance: timelineEntry?.hasProvenance,
58-
tags: timelineEntry?.tags ?? [],
59-
events: [],
60-
hasPositive: false,
61-
hasNegative: false,
62-
}
63-
})
64-
}
65-
66-
function convertMapEntries(
67-
entries: Array<{ key: string; value: TimelineSizeCacheValue }>,
68-
): ConvertedTimelineSizeCacheEntry[] {
69-
return entries.map(({ key, value }) => ({
70-
name: key,
71-
totalSize: value.totalSize,
72-
dependencyCount: value.dependencyCount,
73-
}))
74-
}
75-
7640
function addEvaluationFlags(
7741
entries: EnrichedTimelineSizeCacheEntry[],
7842
versionSubEvents: Map<string, SubEvent[]>,
@@ -90,9 +54,33 @@ function addEvaluationFlags(
9054
}
9155
9256
const convertedData = computed(() => {
93-
const base = convertMapEntries(Array.from(props.sizeCache, ([key, value]) => ({ key, value })))
94-
const withTimelineEntries = addTimelineEntries(base, props.timelineEntries)
95-
return addEvaluationFlags(withTimelineEntries, props.versionSubEvents).toReversed()
57+
const entries = props.timelineEntries.flatMap(timelineEntry => {
58+
const key = `${packageName.value}@${timelineEntry.version}`
59+
const value = props.sizeCache.get(key)
60+
61+
if (!value) {
62+
return []
63+
}
64+
65+
return {
66+
name: key,
67+
totalSize: value.totalSize,
68+
dependencyCount: value.dependencyCount,
69+
version: timelineEntry.version,
70+
time: timelineEntry.time,
71+
license: timelineEntry.license,
72+
type: timelineEntry.type,
73+
hasTypes: timelineEntry.hasTypes,
74+
hasTrustedPublisher: timelineEntry.hasTrustedPublisher,
75+
hasProvenance: timelineEntry.hasProvenance,
76+
tags: timelineEntry.tags ?? [],
77+
events: [],
78+
hasPositive: false,
79+
hasNegative: false,
80+
}
81+
})
82+
83+
return addEvaluationFlags(entries, props.versionSubEvents).toReversed()
9684
})
9785
9886
const versions = computed(() => convertedData.value.map(d => d.name.split('@')[1] ?? ''))
@@ -230,7 +218,7 @@ const watermarkColors = computed(() => ({
230218
231219
const mobileBreakpointWidth = 640
232220
const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpointWidth)
233-
const isZeroBase = shallowRef(false)
221+
234222
const commonScaleSteps = computed(() => {
235223
if (activeTab.value === 'totalSize') {
236224
return seriesTotalSize.value.max - seriesTotalSize.value.min > 5 ? 6 : 3
@@ -283,7 +271,7 @@ const config = computed<VueUiXyConfig>(() => {
283271
formatter: ({ value }) => {
284272
return formatter.value.format(value ?? 0)
285273
},
286-
scaleMin: isZeroBase.value
274+
scaleMin: settings.value.timelineChart.isZeroBased
287275
? 0
288276
: activeTab.value === 'totalSize'
289277
? seriesTotalSize.value.min
@@ -478,7 +466,10 @@ const indexSelection = computed(() => {
478466
</TabList>
479467
</TabRoot>
480468

481-
<SettingsToggle v-model="isZeroBase" :label="$t('package.timeline.chart.base_scale')" />
469+
<SettingsToggle
470+
v-model="settings.timelineChart.isZeroBased"
471+
:label="$t('package.timeline.chart.base_scale')"
472+
/>
482473
</div>
483474
<ClientOnly>
484475
<VueUiXy :dataset="datasets[activeTab]" :config :selected-x-index="indexSelection">

app/composables/useSettings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export interface AppSettings {
5050
anomaliesFixed: boolean
5151
predictionPoints: number
5252
}
53+
timelineChart: {
54+
isZeroBased: boolean
55+
}
5356
}
5457

5558
const DEFAULT_SETTINGS: AppSettings = {
@@ -77,6 +80,9 @@ const DEFAULT_SETTINGS: AppSettings = {
7780
anomaliesFixed: true,
7881
predictionPoints: 4,
7982
},
83+
timelineChart: {
84+
isZeroBased: false,
85+
},
8086
}
8187

8288
const STORAGE_KEY = 'npmx-settings'

app/utils/charts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ export function createAltTextForTimelineChart({
750750
const withEvents = dataset.filter(d => d.events.length)
751751
const first = dataset[0]
752752
const last = dataset.at(-1)
753+
754+
if (!first || !last) return ''
755+
753756
const firstValue = config.metric === 'totalSize' ? first?.totalSize : first?.dependencyCount
754757
const lastValue = config.metric === 'totalSize' ? last?.totalSize : last?.dependencyCount
755758
const overall_progress_percentage = Math.round(((lastValue ?? 0) / (firstValue ?? 1) - 1) * 100)

i18n/locales/fr-FR.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@
581581
"copy_alt": {
582582
"key_changes": "Principaux changements: {version_events}",
583583
"version_events": "version {version}: {events}",
584-
"general_description": "Graphique en ligne montrant la métrique {metric} pour le paquet {package}, depuis la version {first} à {last}. La valeur de la métrique {metric} pour la version {first} est {first_value}, et {last_value} pour la version {last} ({overall_progress_percentage}% overall). {key_changes} {watermark}."
584+
"general_description": "Graphique en ligne montrant la métrique {metric} pour le paquet {package}, depuis la version {first} à {last}. La valeur de la métrique {metric} pour la version {first} est {first_value}, et {last_value} pour la version {last} ({overall_progress_percentage}% dans l'ensemble). {key_changes} {watermark}."
585585
}
586586
}
587587
},

0 commit comments

Comments
 (0)