({
dataset,
config,
}: AltCopyArgs<TrendLineDataset, TrendLineConfig>)
| 485 | |
| 486 | // Used for TrendsChart.vue |
| 487 | export function createAltTextForTrendLineChart({ |
| 488 | dataset, |
| 489 | config, |
| 490 | }: AltCopyArgs<TrendLineDataset, TrendLineConfig>): string { |
| 491 | if (!dataset) return '' |
| 492 | |
| 493 | const analysis = dataset.lines.map(({ name, series }) => ({ |
| 494 | name, |
| 495 | ...computeLineChartAnalysis(series), |
| 496 | dates: config.formattedDates, |
| 497 | hasEstimation: config.hasEstimation, |
| 498 | })) |
| 499 | |
| 500 | const granularityKeyByGranularity: Record<string, string> = { |
| 501 | daily: 'package.trends.granularity_daily', |
| 502 | weekly: 'package.trends.granularity_weekly', |
| 503 | monthly: 'package.trends.granularity_monthly', |
| 504 | yearly: 'package.trends.granularity_yearly', |
| 505 | } |
| 506 | |
| 507 | const granularityKey = |
| 508 | granularityKeyByGranularity[config.granularity] ?? 'package.trends.granularity_weekly' |
| 509 | |
| 510 | const granularity = String(config.$t(granularityKey)).toLocaleLowerCase() |
| 511 | |
| 512 | const packages_analysis = analysis |
| 513 | .map((pkg, i) => { |
| 514 | const trendText = (() => { |
| 515 | switch (pkg.interpretation.trend) { |
| 516 | case 'none': |
| 517 | return config.$t('package.trends.copy_alt.trend_none') |
| 518 | case 'weak': |
| 519 | return config.$t('package.trends.copy_alt.trend_weak') |
| 520 | case 'strong': |
| 521 | return config.$t('package.trends.copy_alt.trend_strong') |
| 522 | case 'undefined': |
| 523 | default: |
| 524 | return config.$t('package.trends.copy_alt.trend_undefined') |
| 525 | } |
| 526 | })() |
| 527 | |
| 528 | return config.$t('package.trends.copy_alt.analysis', { |
| 529 | package_name: pkg.name, |
| 530 | start_value: config.formattedDatasetValues[i]?.[0] ?? 0, |
| 531 | end_value: config.formattedDatasetValues[i]?.at(-1) ?? 0, |
| 532 | trend: trendText, |
| 533 | downloads_slope: config.numberFormatter(pkg.slope), |
| 534 | }) |
| 535 | }) |
| 536 | .join(', ') |
| 537 | |
| 538 | const isSinglePackage = analysis.length === 1 |
| 539 | |
| 540 | const estimation_notice = config.hasEstimation |
| 541 | ? ` ${ |
| 542 | isSinglePackage |
| 543 | ? config.$t('package.trends.copy_alt.estimation') |
| 544 | : config.$t('package.trends.copy_alt.estimations') |
no test coverage detected