@@ -9,13 +9,16 @@ import {
99 drawNpmxLogoAndTaglineWatermark ,
1010} from ' ~/composables/useChartWatermark'
1111import TooltipApp from ' ~/components/Tooltip/App.vue'
12+ import { copyAltTextForVersionsBarChart } from ' ~/utils/charts'
1213
1314const props = defineProps <{
1415 packageName: string
1516 inModal? : boolean
1617}>()
1718
1819const { accentColors, selectedAccentColor } = useAccentColor ()
20+ const { copy, copied } = useClipboard ()
21+
1922const colorMode = useColorMode ()
2023const resolvedMode = shallowRef <' light' | ' dark' >(' light' )
2124const rootEl = shallowRef <HTMLElement | null >(null )
@@ -190,14 +193,14 @@ const chartConfig = computed<VueUiXyConfig>(() => {
190193 fullscreen: false ,
191194 table: false ,
192195 tooltip: false ,
193- altCopy: false , // TODO: set to true to enable the alt copy feature
196+ altCopy: true ,
194197 },
195198 buttonTitles: {
196199 csv: $t (' package.trends.download_file' , { fileType: ' CSV' }),
197200 img: $t (' package.trends.download_file' , { fileType: ' PNG' }),
198201 svg: $t (' package.trends.download_file' , { fileType: ' SVG' }),
199202 annotator: $t (' package.trends.toggle_annotator' ),
200- altCopy: undefined , // TODO: set to proper translation key
203+ altCopy: $t ( ' package.trends.copy_alt.button_label ' ) , // Do not make this text dependant on the `copied` variable, since this would re-render the component, which is undesirable if the minimap was used to select a time frame.
201204 },
202205 callbacks: {
203206 img : args => {
@@ -230,10 +233,19 @@ const chartConfig = computed<VueUiXyConfig>(() => {
230233 loadFile (url , buildExportFilename (' svg' ))
231234 URL .revokeObjectURL (url )
232235 },
233- // altCopy: ({ dataset: dst, config: cfg }: { dataset: Array<VueUiXyDatasetItem>; config: VueUiXyConfig}) => {
234- // // TODO: implement a reusable copy-alt-text-to-clipboard feature based on the dataset & configuration
235- // console.log({ dst, cfg})
236- // }
236+ altCopy : ({ dataset : dst , config : cfg }) =>
237+ copyAltTextForVersionsBarChart ({
238+ dataset: dst ,
239+ config: {
240+ ... cfg ,
241+ datapointLabels: xAxisLabels .value ,
242+ dateRangeLabel: dateRangeLabel .value ,
243+ semverGroupingMode: groupingMode .value ,
244+ copy ,
245+ $t ,
246+ numberFormatter: compactNumberFormatter .value .format ,
247+ },
248+ }),
237249 },
238250 },
239251 grid: {
@@ -575,6 +587,16 @@ const chartConfig = computed<VueUiXyConfig>(() => {
575587 aria-hidden =" true"
576588 />
577589 </template >
590+ <template #optionAltCopy >
591+ <span
592+ class =" w-6 h-6"
593+ :class ="
594+ copied ? 'i-lucide:check text-accent' : 'i-lucide:person-standing text-fg-subtle'
595+ "
596+ style =" pointer-events : none "
597+ aria-hidden =" true"
598+ />
599+ </template >
578600 </VueUiXy >
579601 </div >
580602
0 commit comments