11<script setup lang="ts">
2- import type { VueUiXyConfig , VueUiXyDatasetItem } from ' vue-data-ui'
2+ import type { Theme as VueDataUiTheme , VueUiXyConfig , VueUiXyDatasetItem } from ' vue-data-ui'
33import { VueUiXy } from ' vue-data-ui/vue-ui-xy'
44import { useDebounceFn , useElementSize } from ' @vueuse/core'
55import { useCssVariables } from ' ~/composables/useColors'
@@ -18,6 +18,7 @@ import type {
1818 YearlyDataPoint ,
1919} from ' ~/types/chart'
2020import { DATE_INPUT_MAX } from ' ~/utils/input'
21+ import { copyAltTextForTrendLineChart } from ' ~/utils/charts'
2122
2223const props = withDefaults (
2324 defineProps <{
@@ -50,6 +51,8 @@ const props = withDefaults(
5051
5152const { locale } = useI18n ()
5253const { accentColors, selectedAccentColor } = useAccentColor ()
54+ const { copy, copied } = useClipboard ()
55+
5356const colorMode = useColorMode ()
5457const resolvedMode = shallowRef <' light' | ' dark' >(' light' )
5558const rootEl = shallowRef <HTMLElement | null >(null )
@@ -1406,7 +1409,7 @@ function drawSvgPrintLegend(svg: Record<string, any>) {
14061409// VueUiXy chart component configuration
14071410const chartConfig = computed <VueUiXyConfig >(() => {
14081411 return {
1409- theme: isDarkMode .value ? ' dark' : ' ' ,
1412+ theme: isDarkMode .value ? ' dark' : ( ' ' as VueDataUiTheme ) ,
14101413 chart: {
14111414 height: isMobile .value ? 950 : 600 ,
14121415 backgroundColor: colors .value .bg ,
@@ -1418,14 +1421,14 @@ const chartConfig = computed<VueUiXyConfig>(() => {
14181421 fullscreen: false ,
14191422 table: false ,
14201423 tooltip: false ,
1421- altCopy: false , // TODO: set to true to enable the alt copy feature
1424+ altCopy: true ,
14221425 },
14231426 buttonTitles: {
14241427 csv: $t (' package.trends.download_file' , { fileType: ' CSV' }),
14251428 img: $t (' package.trends.download_file' , { fileType: ' PNG' }),
14261429 svg: $t (' package.trends.download_file' , { fileType: ' SVG' }),
14271430 annotator: $t (' package.trends.toggle_annotator' ),
1428- altCopy: undefined , // TODO: set to proper translation key
1431+ 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.
14291432 },
14301433 callbacks: {
14311434 img : args => {
@@ -1458,10 +1461,22 @@ const chartConfig = computed<VueUiXyConfig>(() => {
14581461 loadFile (url , buildExportFilename (' svg' ))
14591462 URL .revokeObjectURL (url )
14601463 },
1461- // altCopy: ({ dataset: dst, config: cfg }: { dataset: Array<VueUiXyDatasetItem>; config: VueUiXyConfig}) => {
1462- // // TODO: implement a reusable copy-alt-text-to-clipboard feature based on the dataset & configuration
1463- // console.log({ dst, cfg})
1464- // }
1464+ altCopy : ({ dataset : dst , config : cfg }) =>
1465+ copyAltTextForTrendLineChart ({
1466+ dataset: dst ,
1467+ config: {
1468+ ... cfg ,
1469+ formattedDatasetValues: (dst ?.lines || []).map (d =>
1470+ d .series .map (n => compactNumberFormatter .value .format (n ?? 0 )),
1471+ ),
1472+ hasEstimation:
1473+ supportsEstimation .value && ! isEndDateOnPeriodEnd .value && ! isZoomed .value ,
1474+ granularity: displayedGranularity .value ,
1475+ copy ,
1476+ $t ,
1477+ numberFormatter: compactNumberFormatter .value .format ,
1478+ },
1479+ }),
14651480 },
14661481 },
14671482 grid: {
@@ -1870,7 +1885,10 @@ watch(selectedMetric, value => {
18701885 </template >
18711886 <template #optionAltCopy >
18721887 <span
1873- class =" i-lucide:person-standing w-6 h-6 text-fg-subtle"
1888+ class =" w-6 h-6"
1889+ :class ="
1890+ copied ? 'i-lucide:check text-accent' : 'i-lucide:person-standing text-fg-subtle'
1891+ "
18741892 style =" pointer-events : none "
18751893 aria-hidden =" true"
18761894 />
0 commit comments