From e1aea1056793cbbaf25d011f039efaa9ae8eca39 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 22 Mar 2022 17:44:45 +0000 Subject: [PATCH] Update candlestick chart to be reactive --- .../app/charts/CandleStickChart.svelte | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/app/charts/CandleStickChart.svelte b/packages/client/src/components/app/charts/CandleStickChart.svelte index b45e7fe663..b2760b005e 100644 --- a/packages/client/src/components/app/charts/CandleStickChart.svelte +++ b/packages/client/src/components/app/charts/CandleStickChart.svelte @@ -16,17 +16,48 @@ export let animate export let yAxisUnits - $: options = setUpChart(dataProvider) + $: options = setUpChart( + title, + dataProvider, + dateColumn, + openColumn, + highColumn, + lowColumn, + closeColumn, + xAxisLabel, + yAxisLabel, + height, + width, + animate, + yAxisUnits + ) - // Fetch data on mount - const setUpChart = provider => { + const setUpChart = ( + title, + dataProvider, + dateColumn, + openColumn, + highColumn, + lowColumn, + closeColumn, + xAxisLabel, + yAxisLabel, + height, + width, + animate, + yAxisUnits + ) => { const allCols = [dateColumn, openColumn, highColumn, lowColumn, closeColumn] - 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))