This commit is contained in:
cmack 2020-08-07 14:46:00 +01:00
parent 4dbd635985
commit 5bd39c81cc
1 changed files with 14 additions and 8 deletions

View File

@ -36,8 +36,6 @@
export let width = 200 export let width = 200
export let margin = null export let margin = null
$: console.log("DATA", data)
export let centeredTextFunction = null export let centeredTextFunction = null
export let externalRadius = 25 export let externalRadius = 25
export let percentageFormat = null export let percentageFormat = null
@ -75,6 +73,11 @@
if (model) { if (model) {
await fetchData() await fetchData()
data = checkAndReformatData($store[model]) data = checkAndReformatData($store[model])
if (data.length === 0) {
console.error(
"Donut - please provide a valid name and value field for the chart"
)
}
} }
chart.emptyDataConfig({ chart.emptyDataConfig({
@ -107,13 +110,16 @@
let ignoreList = ["_id", "_rev", "id"] let ignoreList = ["_id", "_rev", "id"]
if (dataKey && data.every(d => d[dataKey])) { if (dataKey && data.every(d => d[dataKey])) {
return data.map(d => { return data.map(d => {
let obj = { ...d } let clonedRecord = { ...d }
let value = obj[dataKey] if (clonedRecord[formatKey]) {
if (!ignoreList.includes(dataKey)) { delete clonedRecord[formatKey]
delete obj[dataKey]
} }
obj[formatKey] = value let value = clonedRecord[dataKey]
return obj if (!ignoreList.includes(dataKey)) {
delete clonedRecord[dataKey]
}
clonedRecord[formatKey] = value
return clonedRecord
}) })
} else { } else {
return data return data