MCPcopy
hub / github.com/npmx-dev/npmx.dev / createAltTextForTimelineChart

Function createAltTextForTimelineChart

app/utils/charts.ts:741–792  ·  view source on GitHub ↗
({
  dataset,
  config,
}: AltCopyArgs<EnrichedTimelineSizeCacheEntry[], TimelineChartConfig>)

Source from the content-addressed store, hash-verified

739
740// Used for TimelineChart.vue
741export function createAltTextForTimelineChart({
742 dataset,
743 config,
744}: AltCopyArgs<EnrichedTimelineSizeCacheEntry[], TimelineChartConfig>) {
745 if (!dataset) return ''
746 const metric =
747 config.metric === 'totalSize'
748 ? config.$t('package.stats.install_size')
749 : config.$t('compare.dependencies')
750 const withEvents = dataset.filter(d => d.events.length)
751 const first = dataset[0]
752 const last = dataset.at(-1)
753
754 if (!first || !last) return ''
755
756 const firstValue = config.metric === 'totalSize' ? first?.totalSize : first?.dependencyCount
757 const lastValue = config.metric === 'totalSize' ? last?.totalSize : last?.dependencyCount
758 const baseline = firstValue ?? 0
759 const current = lastValue ?? baseline
760 const overall_progress_percentage =
761 baseline > 0 ? Math.round(((current - baseline) / baseline) * 100) : 0
762
763 const version_events = withEvents
764 .map(item =>
765 config.$t('package.timeline.chart.copy_alt.version_events', {
766 version: item.version,
767 // eslint-disable-next-line @intlify/vue-i18n/no-dynamic-keys
768 events: item.events.map(e => config.$t(e.text).toLocaleLowerCase()).join(', '),
769 }),
770 )
771 .join('; ')
772
773 const key_changes = !withEvents.length
774 ? ''
775 : config.$t('package.timeline.chart.copy_alt.key_changes', {
776 version_events,
777 })
778
779 const altText = config.$t('package.timeline.chart.copy_alt.general_description', {
780 metric: metric.toLocaleLowerCase(),
781 package: config.packageName,
782 first: first?.version ?? '',
783 last: last?.version ?? '',
784 first_value: config.numberFormatter(firstValue ?? 0),
785 last_value: config.numberFormatter(lastValue ?? 0),
786 overall_progress_percentage,
787 key_changes,
788 watermark: config.$t('package.trends.copy_alt.watermark'),
789 })
790
791 return altText
792}
793
794export async function copyAltTextForTimelineChart({
795 dataset,

Callers 2

charts.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected