diff --git a/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/chart_widget.js b/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/chart_widget.js index fa606fe..d165c54 100644 --- a/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/chart_widget.js +++ b/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/chart_widget.js @@ -1,21 +1,16 @@ import {LineChart} from "./modules/chart.js"; -let chart = new LineChart() - -// TODO: DB Entry that controls this config, the page will then spit them out onto the page via backend, -// we then loop through each class with config embedded -const widgetConfig = { - // "type": "", - "deviceModuleId": "a62408c2-bc89-48e2-8c23-9494bbf33cb7", - "startDate": "2024-01-25", - "endDate": "2024-02-24", -} - +const widgetTypeLineChart = "lineChart" class Widget { constructor(config) { - this.container = document.getElementById("chartContainer"); - this.config = widgetConfig + this.config = config + const container = document.getElementById(this.config.id); + + this.chart; + if (this.config.chartType == widgetTypeLineChart) { + this.chart = new LineChart(container) + } } async getDeviceData() { @@ -72,9 +67,31 @@ class Widget { const deviceData = await this.getDeviceData() const deviceReadings = await this.getDeviceReadings() - chart.draw(deviceReadings, deviceData.schema) + this.chart.draw(deviceReadings, deviceData.schema) } } -const widget = new Widget(widgetConfig) -widget.render() + +// TODO: DB Entry that controls this config, the page will then spit them out onto the page via backend, +// we then loop through each class with config embedded +const widgetConfigs = [ + { + "id": "chartContainer1", + "chartType": widgetTypeLineChart, + "deviceModuleId": "c2f30e74-4708-4dff-9347-466563e353c8", + "startDate": "2024-01-25", + "endDate": "2024-02-24" + }, + { + "id": "chartContainer2", + "chartType": widgetTypeLineChart, + "deviceModuleId": "a62408c2-bc89-48e2-8c23-9494bbf33cb7", + "startDate": "2024-01-25", + "endDate": "2024-02-24" + } +]; + +widgetConfigs.forEach((widgetConfig) => { + const widget = new Widget(widgetConfig) + widget.render() +}); diff --git a/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/modules/chart.js b/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/modules/chart.js index b67b245..2f945c2 100644 --- a/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/modules/chart.js +++ b/shedpi_hub_dashboard/static/shedpi_hub_dashboard/js/modules/chart.js @@ -3,8 +3,8 @@ import {getSchemaDataFields} from "./utils.js"; /* Chart visual */ class LineChart { - constructor() { - this.container = document.getElementById("chartContainer"); + constructor(container) { + this.container = container; } mapDataSet(dataset, schema) { diff --git a/shedpi_hub_dashboard/templates/index.html b/shedpi_hub_dashboard/templates/index.html index f95d1c2..9abdf7c 100644 --- a/shedpi_hub_dashboard/templates/index.html +++ b/shedpi_hub_dashboard/templates/index.html @@ -10,7 +10,16 @@

Dashboard

- + + Placeholder + + Chart + +
+
+
+
+ Placeholder Chart @@ -18,7 +27,6 @@

Dashboard

- {% endblock content %}