This commit is contained in:
Gerard Burns 2024-04-18 13:15:27 +01:00
parent 337214d48c
commit 6176381f5b
4 changed files with 88 additions and 7 deletions

View File

@ -154,8 +154,6 @@
return { type: 'solid' }
}
$: console.log("opt", options);
</script>
<ApexChart {options} />

View File

@ -1,5 +1,91 @@
<script>
import PieChart from "./PieChart.svelte"
import ApexChart from "./ApexChart.svelte"
import formatters from "./formatters";
export let title
export let dataProvider
export let labelColumn
export let valueColumn
export let height
export let width
export let animate
export let dataLabels
export let legend
export let palette
export let c1, c2, c3, c4, c5
$: labelType = dataProvider?.schema?.[labelColumn]?.type === 'datetime' ?
"datetime" : "category"
$: series = getSeries(dataProvider, valueColumn)
$: labels = getLabels(dataProvider, labelColumn, labelType);
$: options = {
series,
labels,
colors: palette === "Custom" ? [c1, c2, c3, c4, c5] : [],
theme: {
palette: palette === "Custom" ? null : palette
},
legend: {
show: legend,
position: "top",
horizontalAlign: "right",
showForSingleSeries: true,
showForNullSeries: true,
showForZeroSeries: true,
},
title: {
text: title,
},
dataLabels: {
enabled: dataLabels
},
chart: {
height: height == null || height === "" ? "auto" : height,
width: width == null || width === "" ? "100%" : width,
type: "donut",
animations: {
enabled: animate
},
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
}
const getSeries = (datasource, valueColumn) => {
const rows = datasource.rows ?? [];
return rows.map(row => {
const value = row?.[valueColumn]
const numValue = parseFloat(value);
if (isNaN(numValue)) {
return 0;
}
return numValue;
})
}
const getLabels = (datasource, labelColumn, labelType) => {
const rows = datasource.rows ?? [];
return rows.map(row => {
const value = row?.[labelColumn]
// If a nullish or non-scalar type, replace it with an empty string
if (!["string", "number", "boolean"].includes(typeof value)) {
return ""
} else if (labelType === "datetime") {
return formatters["Datetime"](value)
}
return value;
})
}
</script>
<PieChart {...$$props} donut />
<ApexChart {options} />

View File

@ -130,8 +130,6 @@
return formatters[valueUnits]
}
$: console.log("opt", options);
</script>
<ApexChart {options} />

View File

@ -86,7 +86,6 @@
return value;
})
}
$: console.log("opt", options);
</script>
<ApexChart {options} />