From ae376003d2f5d60dd308ce12278da517d2653a1f Mon Sep 17 00:00:00 2001 From: BrettS Date: Tue, 29 Jul 2025 17:33:05 +0200 Subject: [PATCH 1/4] History chart drop down categories for mobile and large legends --- .../charts/historyChart/HistoryChart.vue | 45 +---- .../historyChart/HistoryChartLegend.vue | 168 +++++++++--------- .../HistoryChartLegendCategoriesGroup.vue | 47 +++++ .../HistoryChartLegendCategory.vue | 87 +++++++++ .../HistoryChartLegendStandard.vue | 83 +++++++++ .../historyChart/history-chart-model.ts | 10 +- 6 files changed, 321 insertions(+), 119 deletions(-) create mode 100644 packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategoriesGroup.vue create mode 100644 packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategory.vue create mode 100644 packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendStandard.vue diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue index 833a2db61a..0c47460a5a 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue @@ -9,7 +9,7 @@ /> @@ -31,10 +31,6 @@ import { TimeScale, Tooltip, Filler, - ChartEvent, - LegendItem, - LegendElement, - ChartTypeRegistry, ChartDataset, ChartType, } from 'chart.js'; @@ -69,10 +65,6 @@ const props = defineProps<{ const chartRef = ref(null); -const legendLarge = computed(() => - lineChartData?.value?.datasets.length > 15 ? true : false, -); - const applyHiddenDatasetsToChart = ( chart: Chart, ): void => { @@ -125,6 +117,7 @@ const chartRange = computed( const chargePointDatasets = computed(() => chargePointIds.value.map((cpId) => ({ label: `${chargePointNames.value(cpId)}`, + category: 'chargepoint', unit: 'kW', borderColor: '#4766b5', backgroundColor: 'rgba(71, 102, 181, 0.2)', @@ -148,6 +141,7 @@ const vehicleDatasets = computed(() => if (selectedData.value.some((item) => socKey in item)) { return { label: `${vehicle.name} SoC`, + category: 'vehicle', unit: '%', borderColor: '#9F8AFF', borderWidth: 2, @@ -175,6 +169,7 @@ const lineChartData = computed(() => { datasets: [ { label: gridMeterName.value, + category: 'component', unit: 'kW', borderColor: '#a33c42', backgroundColor: 'rgba(239,182,188, 0.2)', @@ -191,6 +186,7 @@ const lineChartData = computed(() => { }, { label: 'Hausverbrauch', + category: 'component', unit: 'kW', borderColor: '#949aa1', backgroundColor: 'rgba(148, 154, 161, 0.2)', @@ -207,6 +203,7 @@ const lineChartData = computed(() => { }, { label: 'PV ges.', + category: 'component', unit: 'kW', borderColor: 'green', backgroundColor: 'rgba(144, 238, 144, 0.2)', @@ -223,6 +220,7 @@ const lineChartData = computed(() => { }, { label: 'Speicher ges.', + category: 'component', unit: 'kW', borderColor: '#b5a647', backgroundColor: 'rgba(181, 166, 71, 0.2)', @@ -239,6 +237,7 @@ const lineChartData = computed(() => { }, { label: 'Speicher SoC', + category: 'component', unit: '%', borderColor: '#FFB96E', borderWidth: 2, @@ -265,33 +264,7 @@ const chartOptions = computed>(() => ({ animation: false, plugins: { legend: { - display: !legendLarge.value && legendDisplay.value, - fullSize: true, - align: 'center' as const, - position: 'bottom' as const, - labels: { - boxWidth: 19, - boxHeight: 0.1, - }, - onClick: ( - e: ChartEvent, - legendItem: LegendItem, - legend: LegendElement, - ) => { - const index = legendItem.datasetIndex!; - const chartInstance = legend.chart; - const datasetName = legendItem.text; - - // Toggle visibility using the store - localDataStore.toggleDataset(datasetName); - - // Update chart visibility - if (localDataStore.isDatasetHidden(datasetName)) { - chartInstance.hide(index); - } else { - chartInstance.show(index); - } - }, + display: false, }, tooltip: { mode: 'index' as const, diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue index 393509c390..6bd5905384 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue @@ -1,40 +1,43 @@ - - diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategoriesGroup.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategoriesGroup.vue new file mode 100644 index 0000000000..2215427764 --- /dev/null +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategoriesGroup.vue @@ -0,0 +1,47 @@ + + + diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategory.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategory.vue new file mode 100644 index 0000000000..65a9ad58d1 --- /dev/null +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendCategory.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendStandard.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendStandard.vue new file mode 100644 index 0000000000..4930b478ee --- /dev/null +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegendStandard.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/history-chart-model.ts b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/history-chart-model.ts index efacd28589..59b420e469 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/history-chart-model.ts +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/history-chart-model.ts @@ -1,4 +1,4 @@ -import { TooltipItem, Chart } from 'chart.js'; // Importieren des TooltipItem-Typs +import type { Chart, ChartDataset, TooltipItem } from 'chart.js'; // Importieren des TooltipItem-Typs export interface HistoryChartTooltipItem extends TooltipItem<'line'> { dataset: TooltipItem<'line'>['dataset'] & { unit?: string; @@ -9,3 +9,11 @@ export interface HistoryChartTooltipItem extends TooltipItem<'line'> { export interface ChartComponentRef { chart?: Chart; } + +export type Category = 'chargepoint' | 'vehicle' | 'battery' | 'component'; + +// Add category to the chart datasets +export interface CategorizedDataset + extends ChartDataset<'line', { x: number; y: number }> { + category: Category; +} From 5efba185ae4dc7de79d97bf06f9a96de19d1a676 Mon Sep 17 00:00:00 2001 From: BrettS Date: Wed, 30 Jul 2025 10:59:00 +0200 Subject: [PATCH 2/4] Clean up typescript interfaces --- .../historyChart/HistoryChartLegend.vue | 22 +++++++++---------- .../historyChart/history-chart-model.ts | 9 +++++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue index 6bd5905384..484143947d 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChartLegend.vue @@ -29,8 +29,8 @@