From 38e8971019fb7d96dda223d777e507b2058b741e Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 11 Aug 2022 15:31:39 +0100 Subject: [PATCH] Custom color bar chart --- packages/client/manifest.json | 13 ++++++++++++- .../src/components/app/charts/ApexChart.svelte | 4 +++- .../src/components/app/charts/ApexOptionsBuilder.js | 10 ++++++++-- .../src/components/app/charts/BarChart.svelte | 12 ++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 0368b43562..3394a94203 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -1466,10 +1466,11 @@ }, { "type": "select", - "label": "Colours", + "label": "Colors", "key": "palette", "defaultValue": "Palette 1", "options": [ + "Custom", "Palette 1", "Palette 2", "Palette 3", @@ -1482,6 +1483,16 @@ "Palette 10" ] }, + { + "type": "color", + "label": "C1", + "key": "c1", + "barSeparator": false, + "dependsOn": { + "setting": "palette", + "value": "Custom" + } + }, { "type": "boolean", "label": "Stacked", diff --git a/packages/client/src/components/app/charts/ApexChart.svelte b/packages/client/src/components/app/charts/ApexChart.svelte index 7bb37a587b..87d78bf5a2 100644 --- a/packages/client/src/components/app/charts/ApexChart.svelte +++ b/packages/client/src/components/app/charts/ApexChart.svelte @@ -10,7 +10,9 @@ {#if options} -
+ {#key options.customColor} +
+ {/key} {:else if $builderStore.inBuilder}
diff --git a/packages/client/src/components/app/charts/ApexOptionsBuilder.js b/packages/client/src/components/app/charts/ApexOptionsBuilder.js index ef4083d648..31c5a820f7 100644 --- a/packages/client/src/components/app/charts/ApexOptionsBuilder.js +++ b/packages/client/src/components/app/charts/ApexOptionsBuilder.js @@ -62,8 +62,14 @@ export class ApexOptionsBuilder { return this.setOption(["title", "text"], title) } - color(color) { - return this.setOption(["colors"], [color]) + colors(colors) { + if (!colors) { + delete this.options.colors + this.options["customColor"] = false + return this + } + this.options["customColor"] = true + return this.setOption(["colors"], colors) } width(width) { diff --git a/packages/client/src/components/app/charts/BarChart.svelte b/packages/client/src/components/app/charts/BarChart.svelte index f1e02d8af6..75c147f5d4 100644 --- a/packages/client/src/components/app/charts/BarChart.svelte +++ b/packages/client/src/components/app/charts/BarChart.svelte @@ -16,6 +16,7 @@ export let stacked export let yAxisUnits export let palette + export let c1, c2, c3, c4, c5 export let horizontal $: options = setUpChart( @@ -33,9 +34,13 @@ stacked, yAxisUnits, palette, - horizontal + horizontal, + c1 ? [c1] : null, + customColor ) + $: customColor = palette === "Custom" + const setUpChart = ( title, dataProvider, @@ -51,7 +56,9 @@ stacked, yAxisUnits, palette, - horizontal + horizontal, + colors, + customColor ) => { const allCols = [labelColumn, ...(valueColumns || [null])] if ( @@ -85,6 +92,7 @@ .stacked(stacked) .palette(palette) .horizontal(horizontal) + .colors(customColor ? colors : null) // Add data let useDates = false