diff --git a/components/ui/charts/Chart.client.vue b/components/ui/charts/Chart.client.vue index b1dc1406c..c0871a766 100644 --- a/components/ui/charts/Chart.client.vue +++ b/components/ui/charts/Chart.client.vue @@ -88,7 +88,7 @@ function formatTooltipValue(value, props) { } function generateListEntry(value, index, _, w, props) { - const color = props.colors[index % props.colors.length] + const color = w.globals.colors?.[index] return `
@@ -102,7 +102,7 @@ function generateListEntry(value, index, _, w, props) { } function generateTooltip({ series, seriesIndex, dataPointIndex, w }, props) { - const label = w.globals.lastXAxis.categories[dataPointIndex] + const label = w.globals.lastXAxis.categories?.[dataPointIndex] const formattedLabel = props.formatLabels(label) @@ -158,7 +158,7 @@ function generateTooltip({ series, seriesIndex, dataPointIndex, w }, props) { return tooltip } -const chartOptions = ref({ +const chartOptions = { chart: { id: props.name, fontFamily: @@ -254,7 +254,7 @@ const chartOptions = ref({ tooltip: { custom: (d) => generateTooltip(d, props), }, -}) +} const fillOptions = { colors: props.colors, @@ -292,7 +292,6 @@ const resetChart = () => { xaxis: { categories: props.labels, }, - colors: props.colors, }) chart.value.resetSeries() legendValues.value.forEach((legend) => { @@ -300,8 +299,16 @@ const resetChart = () => { }) } +const updateColors = (colors) => { + chart.value.updateOptions({ + colors, + }) + chart.value.resetSeries() +} + defineExpose({ resetChart, + updateColors, flipLegend, }) diff --git a/components/ui/charts/ChartDisplay.vue b/components/ui/charts/ChartDisplay.vue index 2305f4a24..d28468d3d 100644 --- a/components/ui/charts/ChartDisplay.vue +++ b/components/ui/charts/ChartDisplay.vue @@ -73,6 +73,9 @@
+ @@ -144,7 +147,9 @@ >
@@ -281,6 +286,7 @@ import { formatNumber, DropdownSelect, formatCategoryHeader, + EyeIcon, } from 'omorphia' import dayjs from 'dayjs' import { defineProps, ref, computed } from 'vue' @@ -357,6 +363,24 @@ const projectIsOnDisplay = (id: string) => { return selectedDisplayProjects.value.some((p) => p.id === id) } +const setChartColors = (updatedVal: Ref) => { + downloadsChart.value?.updateColors( + updatedVal.value + ? analytics.formattedData.value.downloads.chart.colors + : analytics.formattedData.value.downloads.chart.defaultColors + ) + viewsChart.value?.updateColors( + updatedVal.value + ? analytics.formattedData.value.views.chart.colors + : analytics.formattedData.value.views.chart.defaultColors + ) + revenueChart.value?.updateColors( + updatedVal.value + ? analytics.formattedData.value.revenue.chart.colors + : analytics.formattedData.value.revenue.chart.defaultColors + ) +} + const resetCharts = () => { downloadsChart.value?.resetChart() viewsChart.value?.resetChart() @@ -365,8 +389,15 @@ const resetCharts = () => { tinyDownloadChart.value?.resetChart() tinyViewChart.value?.resetChart() tinyRevenueChart.value?.resetChart() + + setChartColors(isUsingProjectColors) } +const isUsingProjectColors = ref(true) +watch(() => isUsingProjectColors, setChartColors, { + deep: true, +}) + const analytics = useFetchAllAnalytics(resetCharts, selectedDisplayProjects) const { startDate, endDate, timeRange, timeResolution } = analytics @@ -425,6 +456,9 @@ const downloadSelectedSetAsCSV = () => { } const onDownloadSetAsCSV = useClientTry(async () => await downloadSelectedSetAsCSV()) +const onToggleColors = () => { + isUsingProjectColors.value = !isUsingProjectColors.value +}