From 6c93b7a27c4bb3bd2e09acdbe04a5693c0543815 Mon Sep 17 00:00:00 2001 From: Akarshan Kapoor Date: Sat, 21 Sep 2024 16:51:08 +0000 Subject: [PATCH] Add final configuration for the device_dashboard This commit adds the final configuration for device_dashboard.html. Signed-off-by: Akarshan Kapoor --- .../templates/device_dashboard.html | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/server/django/sensordata/templates/device_dashboard.html b/server/django/sensordata/templates/device_dashboard.html index 7a172c4e..26083523 100644 --- a/server/django/sensordata/templates/device_dashboard.html +++ b/server/django/sensordata/templates/device_dashboard.html @@ -107,6 +107,10 @@

Endpoint Details

+
+ + +
@@ -133,7 +137,7 @@

Resource Data

var chart; var ctx = document.getElementById('resourceChart').getContext('2d'); - function updateChart(data, lowerLimit, upperLimit) { + function updateChart(data, lowerLimit, upperLimit, maxYValue) { if (!data.values || !data.resource_name) { console.error('Invalid data received for chart update'); return; @@ -146,6 +150,8 @@

Resource Data

// Create sequence numbers starting from 0 as labels var sequenceLabels = data.values.map((_, index) => index); + var yMax = maxYValue ? parseFloat(maxYValue) : Math.max(...data.values, upperLimit); + chart = new Chart(ctx, { type: 'line', data: { @@ -187,7 +193,6 @@

Resource Data

options: { responsive: true, maintainAspectRatio: false, - aspectRatio: 10, plugins: { legend: { display: true, @@ -245,8 +250,10 @@

Resource Data

weight: 'bold', }, }, + min: 0, + max: yMax, ticks: { - beginAtZero: true, + stepSize: Math.ceil(yMax / 5), color: '#333', font: { size: 12, @@ -263,9 +270,10 @@

Resource Data

var resourceTypeElement = document.getElementById('resource_type'); var lowerLimitInput = document.getElementById('lower_limit'); var upperLimitInput = document.getElementById('upper_limit'); + var maxYValueInput = document.getElementById('max_y_value'); var applySettingsButton = document.getElementById('applySettings'); - function fetchData(lowerLimit, upperLimit) { + function fetchData(lowerLimit, upperLimit, maxYValue) { var endpoint = '{{ selected_endpoint.endpoint }}'; var resourceType = resourceTypeElement ? resourceTypeElement.value : ''; @@ -277,7 +285,7 @@

Resource Data

}) .then(response => response.json()) .then(data => { - updateChart(data, lowerLimit, upperLimit); + updateChart(data, lowerLimit, upperLimit, maxYValue); }) .catch(error => console.error('Error fetching resource data:', error)); } @@ -287,7 +295,8 @@

Resource Data

resourceTypeElement.addEventListener('change', function () { var lowerLimit = parseFloat(lowerLimitInput.value) || 0; var upperLimit = parseFloat(upperLimitInput.value) || 100; - fetchData(lowerLimit, upperLimit); + var maxYValue = parseFloat(maxYValueInput.value) || null; + fetchData(lowerLimit, upperLimit, maxYValue); }); } @@ -295,14 +304,16 @@

Resource Data

applySettingsButton.addEventListener('click', function () { var lowerLimit = parseFloat(lowerLimitInput.value) || 0; var upperLimit = parseFloat(upperLimitInput.value) || 100; - fetchData(lowerLimit, upperLimit); + var maxYValue = parseFloat(maxYValueInput.value) || null; + fetchData(lowerLimit, upperLimit, maxYValue); }); // Automatically fetch data every 5 seconds setInterval(function () { var lowerLimit = parseFloat(lowerLimitInput.value) || 0; var upperLimit = parseFloat(upperLimitInput.value) || 100; - fetchData(lowerLimit, upperLimit); + var maxYValue = parseFloat(maxYValueInput.value) || null; + fetchData(lowerLimit, upperLimit, maxYValue); }, 5000); // 5000 milliseconds = 5 seconds // Initial chart load if data is available @@ -310,7 +321,7 @@

Resource Data

updateChart({ values: {{ graph_data.values | safe }}, resource_name: '{{ selected_resource_type.name }}' - }, {{ percentile_25 }}, {{ percentile_75 }}); + }, {{ percentile_25 }}, {{ percentile_75 }}, null); {% endif %} });