@@ -13,12 +13,6 @@ import { parseRepoUrl } from '#shared/utils/git-providers'
1313import type { PackageMetaResponse } from '#shared/types'
1414import { encodePackageName } from '#shared/utils/npm'
1515import { fetchNpmDownloadsRange } from '~/utils/npm/api'
16- import type { AltCopyArgs } from 'vue-data-ui'
17- import {
18- computeLineChartAnalysis ,
19- type TrendLineConfig ,
20- type TrendLineDataset ,
21- } from '../utils/charts'
2216
2317export type PackumentLikeForTime = {
2418 time ?: Record < string , string >
@@ -411,8 +405,6 @@ export function getNpmPackageCreationDate(packument: PackumentLikeForTime): stri
411405}
412406
413407export function useCharts ( ) {
414- const compactNumberFormatter = useCompactNumberFormatter ( )
415-
416408 function resolveDateRange (
417409 evolutionOptions : EvolutionOptions ,
418410 packageCreatedIso : string | null ,
@@ -623,103 +615,11 @@ export function useCharts() {
623615 return next
624616 }
625617
626- function createAltTextForTrendLineChart ( {
627- dataset,
628- config,
629- } : AltCopyArgs < TrendLineDataset , TrendLineConfig > ) : string {
630- if ( ! dataset ) return ''
631-
632- const analysis = dataset . lines . map ( ( { name, series } ) => ( {
633- name,
634- ...computeLineChartAnalysis ( series ) ,
635- dates : config . formattedDates ,
636- hasEstimation : config . hasEstimation ,
637- } ) )
638-
639- const granularityKeyByGranularity : Record < string , string > = {
640- daily : 'package.trends.granularity_dayly' ,
641- weekly : 'package.trends.granularity_weekly' ,
642- monthly : 'package.trends.granularity_monthly' ,
643- yearly : 'package.trends.granularity_yearly' ,
644- }
645-
646- const granularityKey =
647- granularityKeyByGranularity [ config . granularity as unknown as string ] ??
648- 'package.trends.granularity_day'
649-
650- const granularity = String ( config . $t ( granularityKey ) ) . toLocaleLowerCase ( )
651-
652- const packages_analysis = analysis
653- . map ( ( pkg , i ) => {
654- const trendText = ( ( ) => {
655- switch ( pkg . interpretation . trend ) {
656- case 'none' :
657- return config . $t ( 'package.trends.copy_alt.trend_none' )
658- case 'weak' :
659- return config . $t ( 'package.trends.copy_alt.trend_weak' )
660- case 'strong' :
661- return config . $t ( 'package.trends.copy_alt.trend_strong' )
662- case 'undefined' :
663- default :
664- return config . $t ( 'package.trends.copy_alt.trend_undefined' )
665- }
666- } ) ( )
667-
668- return config . $t ( 'package.trends.copy_alt.analysis' , {
669- package_name : pkg . name ,
670- start_value : config . formattedDatasetValues [ i ] ?. [ 0 ] ?? 0 ,
671- end_value : config . formattedDatasetValues [ i ] ?. at ( - 1 ) ?? 0 ,
672- trend : trendText ,
673- downloads_slope : compactNumberFormatter . value . format ( pkg . slope ) ,
674- growth_percentage : `${ pkg . progressionPercent ?. toFixed ( 1 ) } %` ,
675- } )
676- } )
677- . join ( ', ' )
678-
679- const isSinglePackage = analysis . length === 1
680-
681- const estimation_notice = config . hasEstimation
682- ? ` ${
683- isSinglePackage
684- ? config . $t ( 'package.trends.copy_alt.estimation' )
685- : config . $t ( 'package.trends.copy_alt.estimations' )
686- } `
687- : ''
688-
689- const compareText = `${ config . $t ( 'package.trends.copy_alt.compare' , {
690- packages : analysis . map ( a => a . name ) . join ( ', ' ) ,
691- } ) } `
692-
693- const singlePackageText = `${ config . $t ( 'package.trends.copy_alt.single_package' , {
694- package : analysis ?. [ 0 ] ?. name ?? '' ,
695- } ) } `
696-
697- const generalAnalysis = config . $t ( 'package.trends.copy_alt.general_description' , {
698- start_date : analysis ?. [ 0 ] ?. dates [ 0 ] ?. text ,
699- end_date : analysis ?. [ 0 ] ?. dates . at ( - 1 ) ?. text ,
700- granularity,
701- packages_analysis,
702- watermark : config . $t ( 'package.trends.copy_alt.watermark' ) ,
703- estimation_notice,
704- } )
705-
706- return ( isSinglePackage ? singlePackageText : compareText ) + generalAnalysis
707- }
708-
709- async function copyAltTextForTrendLineChart ( {
710- dataset,
711- config,
712- } : AltCopyArgs < TrendLineDataset , TrendLineConfig > ) {
713- const altText = createAltTextForTrendLineChart ( { dataset, config } )
714- await config . copy ( altText )
715- }
716-
717618 return {
718619 fetchPackageDownloadEvolution,
719620 fetchPackageLikesEvolution,
720621 fetchRepoContributorsEvolution,
721622 fetchRepoRefsForPackages,
722623 getNpmPackageCreationDate,
723- copyAltTextForTrendLineChart,
724624 }
725625}
0 commit comments