From 352d236f2ed02c4a74ac3f0f821da6dff49efd46 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 11 Aug 2022 16:59:50 +0100 Subject: [PATCH] Custom colors for Pie Chart --- packages/client/manifest.json | 66 ++++++++++++++++++- .../src/components/app/charts/PieChart.svelte | 12 +++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 3394a94203..a60e5c6b15 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -1811,10 +1811,11 @@ }, { "type": "select", - "label": "Colours", + "label": "Colors", "key": "palette", "defaultValue": "Palette 1", "options": [ + "Custom", "Palette 1", "Palette 2", "Palette 3", @@ -1827,6 +1828,56 @@ "Palette 10" ] }, + { + "type": "color", + "label": "C1", + "key": "c1", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, + { + "type": "color", + "label": "C2", + "key": "c2", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, + { + "type": "color", + "label": "C3", + "key": "c3", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, + { + "type": "color", + "label": "C4", + "key": "c4", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, + { + "type": "color", + "label": "C5", + "key": "c5", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, { "type": "boolean", "label": "Data Labels", @@ -1893,10 +1944,11 @@ }, { "type": "select", - "label": "Colours", + "label": "Colors", "key": "palette", "defaultValue": "Palette 1", "options": [ + "Custom", "Palette 1", "Palette 2", "Palette 3", @@ -1909,6 +1961,16 @@ "Palette 10" ] }, + { + "type": "color", + "label": "Color", + "key": "color", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, { "type": "boolean", "label": "Data Labels", diff --git a/packages/client/src/components/app/charts/PieChart.svelte b/packages/client/src/components/app/charts/PieChart.svelte index 38a42ee37b..8cb7317d94 100644 --- a/packages/client/src/components/app/charts/PieChart.svelte +++ b/packages/client/src/components/app/charts/PieChart.svelte @@ -13,6 +13,7 @@ export let legend export let donut export let palette + export let c1, c2, c3, c4, c5 $: options = setUpChart( title, @@ -25,9 +26,13 @@ animate, legend, donut, - palette + palette, + c1 && c2 && c3 && c4 && c5 ? [c1, c2, c3, c4, c5] : null, + customColor ) + $: customColor = palette === "Custom" + const setUpChart = ( title, dataProvider, @@ -39,7 +44,9 @@ animate, legend, donut, - palette + palette, + colors, + customColor ) => { if ( !dataProvider || @@ -70,6 +77,7 @@ .legend(legend) .legendPosition("right") .palette(palette) + .colors(customColor ? colors : null) // Add data if valid datasource const series = data.map(row => parseFloat(row[valueColumn]))