From 5930fe90a10c0213091a04e5e4c1cb9ee41f83c3 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 23 Sep 2024 17:46:59 +0100 Subject: [PATCH] refactor --- layouts/partials/chart.html | 183 +++++++++++++++++----------------- layouts/partials/head.html | 1 + layouts/partials/table.html | 29 ++++-- layouts/shortcodes/chart.html | 4 +- layouts/shortcodes/table.html | 2 +- shell.nix | 2 +- static/css/charts.css | 21 +--- static/js/mangrove-map.js | 3 - 8 files changed, 122 insertions(+), 123 deletions(-) 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" }} -
+