From 84cdfa5eac9a803982ff0e9a1b4b27d259ffbdb6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 22 Mar 2022 17:44:58 +0000 Subject: [PATCH] Update line chart to be reactive --- .../components/app/charts/LineChart.svelte | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/app/charts/LineChart.svelte b/packages/client/src/components/app/charts/LineChart.svelte index 2c05292670..afb9f14262 100644 --- a/packages/client/src/components/app/charts/LineChart.svelte +++ b/packages/client/src/components/app/charts/LineChart.svelte @@ -23,17 +23,56 @@ export let stacked export let gradient - $: options = setUpChart(dataProvider) + $: options = setUpChart( + title, + dataProvider, + labelColumn, + valueColumns, + xAxisLabel, + yAxisLabel, + height, + width, + animate, + dataLabels, + curve, + legend, + yAxisUnits, + palette, + area, + stacked, + gradient + ) - // Fetch data on mount - const setUpChart = provider => { + const setUpChart = ( + title, + dataProvider, + labelColumn, + valueColumns, + xAxisLabel, + yAxisLabel, + height, + width, + animate, + dataLabels, + curve, + legend, + yAxisUnits, + palette, + area, + stacked, + gradient + ) => { const allCols = [labelColumn, ...(valueColumns || [null])] - if (!provider || !provider.rows?.length || allCols.find(x => x == null)) { + if ( + !dataProvider || + !dataProvider.rows?.length || + allCols.find(x => x == null) + ) { return null } // Fetch, filter and sort data - const { schema, rows } = provider + const { schema, rows } = dataProvider const reducer = row => (valid, column) => valid && row[column] != null const hasAllColumns = row => allCols.reduce(reducer(row), true) const data = rows.filter(row => hasAllColumns(row))