Refactor graph class constructor and methods

This commit is contained in:
Sietse Jonker
2024-03-22 12:38:39 +01:00
parent 07cc13d573
commit ca5d92bd86

View File

@@ -42,13 +42,13 @@ class feedbackNode extends node {
class liveGraph extends node{
// Constructor to initialize the graph
constructor(id) {
super(id, live);
this.timeArray = [];
this.tempArray = [];
this.humiArray = [];
this.eco2Array = [];
this.tvocArray = [];
this.cnt = 0;
this.nodeId = "liveGraph" + id;
}
// Fuction to create a graph
makeGraph() {
@@ -127,23 +127,23 @@ class liveGraph extends node{
class graph {
// Constructor to initialize the graph
constructor(id) {
this.timeArray = [];
this.tempArray = [];
this.humiArray = [];
this.eco2Array = [];
this.tvocArray = [];
constructor(id, graph) {
if (graph === "live") {
this.nodeId = "liveGraph" + id;
}
else {
this.nodeId = "graph" + id;
}
}
// Function to create a graph
makeGraph(amountOfGraphs) {
makeGraph(amountOfGraphs, array1, array2, array3, array4) {
for (let i = 0; i < amountOfGraphs; i++) {
// Create a new line for temperature
Plotly.plot(this.nodeId, [
{
x: this.timeArray, // Use timeArray as x values
y: this.array[i],
y: array + i,
mode: "lines",
line: { color: "#FF0000" },
name: "Temperature",
@@ -152,13 +152,13 @@ class graph {
}
}
// Function to update the graph with new values got from updateData function
updateGraph() {
updateGraph(array1, array2, array3, array4) {
let time = new Date();
this.timeArray.push(new Date());
let update = {
x: [[this.timeArray]],
y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]]
y: [array1, array2, array3, array4]
};
let olderTime = time.setMinutes(time.getMinutes() - 1);