diff --git a/layouts/partials/chart.html b/layouts/partials/chart.html index de3bcb3..6f9e5bb 100644 --- a/layouts/partials/chart.html +++ b/layouts/partials/chart.html @@ -1,96 +1,97 @@ -
-
-
- -
-
+ } + + function updateChart() { + console.log(chartData); + let chartDataMap = new Map(); + for (let objectId in chartData) { + chartDataMap.set(objectId, chartData[objectId]); + } + var chartDom = document.getElementById(`${id}--chart`); + var myChart = echarts.init(chartDom); + + var option = { + tooltip: { + ...tooltip, + valueFormatter(value, index) { + return nFormatter(value, 0); + }, + }, + xAxis: { + type: "time", + }, + yAxis: { + scale: scaleChart, + type: "value", + }, + series: Array.from(chartDataMap.entries()).map(([name, data]) => ({ + name, + type: chartType, + data, + showSymbol: false, + })), + }; + + myChart.setOption(option, true); + } + + document.addEventListener("rowSelected", (event) => { + console.log( + "Row selected:", + event.detail.row.offsetParent.id, + event.detail.row.value, + event.detail.valueId, + event.detail.selectableRows, + ); + valueId = event.detail.valueId + let selectedRow = { + [valueId]: event.detail.row.value, + }; + query = queryConstructor(selectedRow); + fetchDataForChart(query, valueId); + }); + + document.addEventListener("rowDeselected", (event) => { + console.log( + "Row deselected:", + event.detail.row.offsetParent.id, + event.detail.row.value, + ); + delete chartData[event.detail.row.value]; + updateChart(); + }); + } + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e336652..5624d97 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -9,6 +9,7 @@ + diff --git a/layouts/shortcodes/chart.html b/layouts/shortcodes/chart.html index 10c581a..ce478ee 100644 --- a/layouts/shortcodes/chart.html +++ b/layouts/shortcodes/chart.html @@ -1,8 +1,10 @@ {{ partial "chart.html" }} -
+
+
+
diff --git a/layouts/shortcodes/table.html b/layouts/shortcodes/table.html index d18114f..2f77f05 100644 --- a/layouts/shortcodes/table.html +++ b/layouts/shortcodes/table.html @@ -1,5 +1,5 @@ {{ partial "table.html" }} -
+