Spaces:
Sleeping
Sleeping
Update static/js/util.js
Browse files- static/js/util.js +34 -23
static/js/util.js
CHANGED
|
@@ -589,34 +589,45 @@
|
|
| 589 |
// Plotting Function
|
| 590 |
|
| 591 |
function fetchAndPlotGraph(graphDivId, sensorId, fullscreenToggleId) {
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
|
|
|
| 599 |
|
| 600 |
-
|
|
|
|
| 601 |
|
|
|
|
| 602 |
}
|
| 603 |
|
| 604 |
function setupFullscreenToggle(graphDivId, fullscreenToggleId) {
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
}
|
| 621 |
|
| 622 |
function toggleFullscreen(element) {
|
|
|
|
| 589 |
// Plotting Function
|
| 590 |
|
| 591 |
function fetchAndPlotGraph(graphDivId, sensorId, fullscreenToggleId) {
|
| 592 |
+
const plotUrl = `/sensors/plot/${sensorId}`;
|
| 593 |
+
fetch(plotUrl)
|
| 594 |
+
.then(response => response.json())
|
| 595 |
+
.then(graphs => {
|
| 596 |
+
|
| 597 |
+
// Create the Plotly graph with the updated layout
|
| 598 |
+
Plotly.newPlot(graphDivId, graphs.data, graphs.layout, {responsive: true});
|
| 599 |
+
|
| 600 |
|
| 601 |
+
})
|
| 602 |
+
.catch(error => console.error('Error:', error));
|
| 603 |
|
| 604 |
+
setupFullscreenToggle(graphDivId, fullscreenToggleId);
|
| 605 |
}
|
| 606 |
|
| 607 |
function setupFullscreenToggle(graphDivId, fullscreenToggleId) {
|
| 608 |
+
var divGraph = document.getElementById(graphDivId);
|
| 609 |
+
var btnFullScreenToggle = document.getElementById(fullscreenToggleId);
|
| 610 |
+
|
| 611 |
+
btnFullScreenToggle.addEventListener('click', function() {
|
| 612 |
+
toggleFullscreen(divGraph);
|
| 613 |
+
});
|
| 614 |
+
|
| 615 |
+
// Add event listener for window resize
|
| 616 |
+
window.addEventListener('resize', function() {
|
| 617 |
+
Plotly.relayout(graphDivId, {
|
| 618 |
+
width: divGraph.clientWidth, // Use the clientWidth of the divGraph
|
| 619 |
+
height: divGraph.clientHeight // Use the clientHeight of the divGraph
|
| 620 |
+
});
|
| 621 |
+
});
|
| 622 |
+
|
| 623 |
+
document.addEventListener('fullscreenchange', function() {
|
| 624 |
+
var isFullScreen = Boolean(document.fullscreenElement);
|
| 625 |
+
var update = {
|
| 626 |
+
width: isFullScreen ? window.innerWidth : divGraph.clientWidth,
|
| 627 |
+
height: isFullScreen ? window.innerHeight : 512
|
| 628 |
+
};
|
| 629 |
+
Plotly.relayout(graphDivId, update);
|
| 630 |
+
});
|
| 631 |
}
|
| 632 |
|
| 633 |
function toggleFullscreen(element) {
|