Add graph classes and update HTML files
This commit is contained in:
79
web/newWebsite/graph-classes.js
Normal file
79
web/newWebsite/graph-classes.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
class Graph{
|
||||||
|
constructor(id) {
|
||||||
|
this.id = "graph" + id;
|
||||||
|
this.timeArray = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to create a graph
|
||||||
|
makeGraph(line, lineColor, name) {
|
||||||
|
let lineArray;
|
||||||
|
switch (line) {
|
||||||
|
case "temp":
|
||||||
|
lineArray = this.tempArray;
|
||||||
|
break;
|
||||||
|
case "humi":
|
||||||
|
lineArray = this.humiArray;
|
||||||
|
break;
|
||||||
|
case "eco2":
|
||||||
|
lineArray = this.eco2Array;
|
||||||
|
break;
|
||||||
|
case "tvoc":
|
||||||
|
lineArray = this.tvocArray;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error("Invalid line");
|
||||||
|
}
|
||||||
|
this.timeArray.push(new Date());
|
||||||
|
Plotly.plot(this.id, [
|
||||||
|
{
|
||||||
|
x: this.timeArray,
|
||||||
|
y: lineArray,
|
||||||
|
mode: "lines",
|
||||||
|
line: { color: lineColor },
|
||||||
|
name: name,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LiveGraph extends Graph{
|
||||||
|
// Constructor to initialize the graph
|
||||||
|
constructor(id){
|
||||||
|
super(id);
|
||||||
|
this.tempArray = [];
|
||||||
|
this.humiArray = [];
|
||||||
|
this.eco2Array = [];
|
||||||
|
this.tvocArray = [];
|
||||||
|
this.cnt = 0;
|
||||||
|
}
|
||||||
|
// Function to update the graph with new values got from updateData function
|
||||||
|
updateGraph() {
|
||||||
|
let time = new Date();
|
||||||
|
this.timeArray.push(new Date());
|
||||||
|
|
||||||
|
let update = {
|
||||||
|
x: [[this.timeArray]],
|
||||||
|
y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]]
|
||||||
|
};
|
||||||
|
|
||||||
|
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
||||||
|
let futureTime = time.setMinutes(time.getMinutes() + 1);
|
||||||
|
let minuteView = {
|
||||||
|
xaxis: {
|
||||||
|
type: "date",
|
||||||
|
range: [olderTime, futureTime],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
Plotly.relayout(this.id, minuteView);
|
||||||
|
if (this.cnt === 10) clearInterval(interval);
|
||||||
|
}
|
||||||
|
// function to get the new data for graph
|
||||||
|
updateData(temperature, humidity, eCO2, TVOC) {
|
||||||
|
// Update the graph
|
||||||
|
this.tempArray.push(temperature);
|
||||||
|
this.humiArray.push(humidity);
|
||||||
|
this.eco2Array.push(eCO2 / 10);
|
||||||
|
this.tvocArray.push(TVOC / 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
web/newWebsite/graph-main.js
Normal file
2
web/newWebsite/graph-main.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
|
@@ -6,6 +6,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="styles/graph-styles.css">
|
<link rel="stylesheet" href="styles/graph-styles.css">
|
||||||
<title>Graphs</title>
|
<title>Graphs</title>
|
||||||
|
<script src="https://cdn.plot.ly/plotly-latest.min.js" charset="utf-8"></script>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
|
||||||
@@ -25,9 +26,10 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<script src="graph-main.js"></script>
|
<div id="graph1"></div>
|
||||||
|
|
||||||
<script src="graph-classes.js"></script>
|
<script src="graph-classes.js"></script>
|
||||||
|
<script src="graph-main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@@ -6,6 +6,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="styles/dashboard-styles.css">
|
<link rel="stylesheet" href="styles/dashboard-styles.css">
|
||||||
<title>Gauges</title>
|
<title>Gauges</title>
|
||||||
|
<script src="https://cdn.plot.ly/plotly-latest.min.js" charset="utf-8"></script>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
|
||||||
@@ -29,5 +30,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
<script src="GaugGroup.js"></script>
|
<script src="GaugGroup.js"></script>
|
||||||
|
<script src="graph-classes.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user