From 31820c1bbf85b0067a4fc1c765f7a0d93a0548d3 Mon Sep 17 00:00:00 2001 From: cmack Date: Tue, 4 Aug 2020 10:02:58 +0100 Subject: [PATCH] Adding mode functionality to Donut --- .../userInterface/temporaryPanelStructure.js | 5 ++++ packages/standard-components/components.json | 1 + .../src/Chart/Donut.svelte | 28 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js index c4b24a76da..3184ba6844 100644 --- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js +++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js @@ -428,6 +428,11 @@ export default { ...all, }, settings: [ + { + label: "Table", + key: "model", + control: ModelSelect, + }, { label: "Fix Highlight Slice", key: "hasFixedHighlightedSlice", diff --git a/packages/standard-components/components.json b/packages/standard-components/components.json index 6a90567f76..24ca1b0a2e 100644 --- a/packages/standard-components/components.json +++ b/packages/standard-components/components.json @@ -259,6 +259,7 @@ "color": "string", "height": "number", "width": "number", + "model": "string", "hasFixedHighlightedSlice": "bool", "hasLastHoverSliceHighlighted": "bool", "hasHoverAnimation": "bool", diff --git a/packages/standard-components/src/Chart/Donut.svelte b/packages/standard-components/src/Chart/Donut.svelte index 6ee6285417..8c1785a8d9 100644 --- a/packages/standard-components/src/Chart/Donut.svelte +++ b/packages/standard-components/src/Chart/Donut.svelte @@ -15,6 +15,11 @@ let chartElement = null let chartContainer = null + export let _bb + export let model + + let store = _bb.store + export let customMouseOver = null export let customMouseMove = null export let customMouseOut = null @@ -22,7 +27,7 @@ export let orderingFunction = null - export let data = [] + export let data = model ? $store[model] : [] export let color = "britecharts" export let height = 200 export let width = 200 @@ -41,6 +46,27 @@ export let radiusHoverOffset = 0 export let useLegend = true + async function fetchData() { + const FETCH_RECORDS_URL = `/api/views/all_${model}` + const response = await _bb.api.get(FETCH_RECORDS_URL) + if (response.status === 200) { + const json = await response.json() + store.update(state => { + state[model] = json + return state + }) + } else { + throw new Error("Failed to fetch records.", response) + } + } + + onMount(async () => { + await fetchData() + }) + + $: _data = model ? $store[model] : data + $: console.log("_data", _data) + onMount(() => { if (chart) { chart.emptyDataConfig({