From bbc161c481b775b226476ae52c2228f80a1e1607 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 22 Mar 2022 17:44:32 +0000 Subject: [PATCH] Update bar chart to be reactive --- .../src/components/app/charts/BarChart.svelte | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/app/charts/BarChart.svelte b/packages/client/src/components/app/charts/BarChart.svelte index 9a340c404e..af1bb478fe 100644 --- a/packages/client/src/components/app/charts/BarChart.svelte +++ b/packages/client/src/components/app/charts/BarChart.svelte @@ -18,16 +18,53 @@ export let palette export let horizontal - $: options = setUpChart(dataProvider) + $: options = setUpChart( + title, + dataProvider, + labelColumn, + valueColumns, + xAxisLabel, + yAxisLabel, + height, + width, + dataLabels, + animate, + legend, + stacked, + yAxisUnits, + palette, + horizontal + ) - const setUpChart = provider => { + const setUpChart = ( + title, + dataProvider, + labelColumn, + valueColumns, + xAxisLabel, + yAxisLabel, + height, + width, + dataLabels, + animate, + legend, + stacked, + yAxisUnits, + palette, + horizontal + ) => { + console.log("new chart") 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 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)).slice(0, 100)