Refactor class constructors and update graph creation

This commit is contained in:
Sietse Jonker
2024-03-22 14:44:25 +01:00
parent e5511d1925
commit 2221be88bf

View File

@@ -19,8 +19,7 @@ class node {
updateConnection() { updateConnection() {
if (connectedNodes[this.nodeId]) { if (connectedNodes[this.nodeId]) {
this.connected = true; this.connected = true;
} } else {
else {
this.connected = false; this.connected = false;
} }
} }
@@ -39,16 +38,16 @@ class feedbackNode extends node {
} }
} }
class liveGraph extends node{ class liveGraph extends node {
// Constructor to initialize the graph // Constructor to initialize the graph
constructor(id) { constructor(id) {
super(id, live); super(id);
this.timeArray = [];
this.tempArray = []; this.tempArray = [];
this.humiArray = []; this.humiArray = [];
this.eco2Array = []; this.eco2Array = [];
this.tvocArray = []; this.tvocArray = [];
this.cnt = 0; this.cnt = 0;
this.nodeId = "liveGraph" + id;
} }
// Fuction to create a graph // Fuction to create a graph
makeGraph() { makeGraph() {
@@ -101,7 +100,12 @@ class liveGraph extends node{
let update = { let update = {
x: [[this.timeArray]], x: [[this.timeArray]],
y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]] y: [
[this.tempArray],
[this.humiArray],
[this.eco2Array],
[this.tvocArray],
],
}; };
let olderTime = time.setMinutes(time.getMinutes() - 1); let olderTime = time.setMinutes(time.getMinutes() - 1);
@@ -127,28 +131,23 @@ class liveGraph extends node{
class graph { class graph {
// Constructor to initialize the graph // Constructor to initialize the graph
constructor(id, graph) { constructor(id) {
if (graph === "live") { this.nodeId = "graph" + id;
this.nodeId = "liveGraph" + id; this.timeArray = [];
}
else {
this.nodeId = "graph" + id;
}
} }
// Function to create a graph // Function to create a graph
makeGraph(amountOfGraphs, array1, array2, array3, array4) { makeGraph(amountOfGraphs, array1, array2, array3, array4) {
for (let i = 0; i < amountOfGraphs; i++) { for (let i = 0; i < amountOfGraphs; i++) {
// Create a new line for temperature
// Create a new line for temperature Plotly.plot(this.nodeId, [
Plotly.plot(this.nodeId, [ {
{ x: this.timeArray, // Use timeArray as x values
x: this.timeArray, // Use timeArray as x values y: array + i,
y: array + i, mode: "lines",
mode: "lines", line: { color: "#FF0000" },
line: { color: "#FF0000" }, name: "Temperature",
name: "Temperature", },
}, ]);
]);
} }
} }
// Function to update the graph with new values got from updateData function // Function to update the graph with new values got from updateData function
@@ -158,7 +157,7 @@ class graph {
let update = { let update = {
x: [[this.timeArray]], x: [[this.timeArray]],
y: [array1, array2, array3, array4] y: [array1, array2, array3, array4],
}; };
let olderTime = time.setMinutes(time.getMinutes() - 1); let olderTime = time.setMinutes(time.getMinutes() - 1);
@@ -166,9 +165,8 @@ class graph {
let minuteView = { let minuteView = {
xaxis: { xaxis: {
type: "date", type: "date",
range: range: [olderTime, futureTime],
}, },
}; };
}
}
} }