feat(frontend); Improve Pie schema (#983)

* Make the pie schema good

* Remove private info

* Fix build error
This commit is contained in:
Kai Jellinghaus
2022-12-03 20:48:04 +01:00
committed by GitHub
parent 5163c2fe8b
commit 86eae2c824
2 changed files with 30 additions and 3 deletions

View File

@@ -285,7 +285,7 @@
</span>
</div>
{:else if inputCat == 'resource-object'}
<ObjectResourceInput {compact} {format} bind:value />
<ObjectResourceInput {format} bind:value />
{:else if inputCat == 'object'}
{#if properties && Object.keys(properties).length > 0}
<div class="p-4 pl-8 border rounded w-full">

View File

@@ -40,11 +40,38 @@
animation: false
}
let result: ChartData<'pie', number[], unknown> | undefined = undefined
let nextColor = 0
// TODO: Replace with nicer windmill branded color pallet.
const colors = ['#3b82f6', '#ff6384', '#4bc0c0', '#ff9f40', '#9966ff', '#ffcd56', '#c9cbcf']
function generateColor() {
const col = colors[nextColor]
nextColor = (nextColor + 1) % colors.length
return col
}
let result: { name: string; value: number; color: string | undefined }[] | undefined = undefined
let data: ChartData<'pie', number[], string> | undefined = undefined
$: if (Array.isArray(result)) {
nextColor = 0
data = {
datasets: [
{
data: result.map((x) => x.value),
backgroundColor: result.map((x) => x.color ?? generateColor())
}
],
labels: result.map((x) => x.name)
}
} else {
data = undefined
}
</script>
<RunnableComponent {id} {path} {runType} {inlineScriptName} bind:inputs bind:result>
{#if result}
<Pie data={result} {options} />
<Pie {data} {options} />
{/if}
</RunnableComponent>