From 5bd39c81cc57392eda478be5dd156a77231daac5 Mon Sep 17 00:00:00 2001 From: cmack Date: Fri, 7 Aug 2020 14:46:00 +0100 Subject: [PATCH] Tidyup --- .../src/Chart/Donut.svelte | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/standard-components/src/Chart/Donut.svelte b/packages/standard-components/src/Chart/Donut.svelte index b1031a214f..08cdba7d2e 100644 --- a/packages/standard-components/src/Chart/Donut.svelte +++ b/packages/standard-components/src/Chart/Donut.svelte @@ -36,8 +36,6 @@ export let width = 200 export let margin = null - $: console.log("DATA", data) - export let centeredTextFunction = null export let externalRadius = 25 export let percentageFormat = null @@ -75,6 +73,11 @@ if (model) { await fetchData() data = checkAndReformatData($store[model]) + if (data.length === 0) { + console.error( + "Donut - please provide a valid name and value field for the chart" + ) + } } chart.emptyDataConfig({ @@ -107,13 +110,16 @@ let ignoreList = ["_id", "_rev", "id"] if (dataKey && data.every(d => d[dataKey])) { return data.map(d => { - let obj = { ...d } - let value = obj[dataKey] - if (!ignoreList.includes(dataKey)) { - delete obj[dataKey] + let clonedRecord = { ...d } + if (clonedRecord[formatKey]) { + delete clonedRecord[formatKey] } - obj[formatKey] = value - return obj + let value = clonedRecord[dataKey] + if (!ignoreList.includes(dataKey)) { + delete clonedRecord[dataKey] + } + clonedRecord[formatKey] = value + return clonedRecord }) } else { return data