Teapack1 commited on
Commit
4b52765
1 Parent(s): 83de6ee

Update static/js/util.js

Browse files
Files changed (1) hide show
  1. 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
- const plotUrl = `/sensors/plot/${sensorId}`;
593
- fetch(plotUrl)
594
- .then(response => response.json())
595
- .then(graphs => {
596
- Plotly.newPlot(graphDivId, graphs.data, graphs.layout, {responsive: true});
597
- })
598
- .catch(error => console.error('Error:', error));
 
599
 
600
- setupFullscreenToggle(graphDivId, fullscreenToggleId);
 
601
 
 
602
  }
603
 
604
  function setupFullscreenToggle(graphDivId, fullscreenToggleId) {
605
- var divGraph = document.getElementById(graphDivId);
606
- var btnFullScreenToggle = document.getElementById(fullscreenToggleId);
607
-
608
- btnFullScreenToggle.addEventListener('click', function() {
609
- toggleFullscreen(divGraph);
610
- });
611
-
612
- document.addEventListener('fullscreenchange', function() {
613
- var isFullScreen = Boolean(document.fullscreenElement);
614
- var update = {
615
- width: isFullScreen ? window.innerWidth : 1200,
616
- height: isFullScreen ? window.innerHeight : 512
617
- };
618
- Plotly.relayout(graphDivId, update);
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) {