Refactor classes.js to update connection status and add feedbackNode and graph classes

This commit is contained in:
Sietse Jonker
2024-03-22 12:31:53 +01:00
parent 1982db8c50
commit 07cc13d573

View File

@@ -16,12 +16,30 @@ class node {
this.TVOC = TVOC; this.TVOC = TVOC;
} }
// Function to update the connection status // Function to update the connection status
updateConnection(status) { updateConnection() {
this.connected = status; if (connectedNodes[this.nodeId]) {
this.connected = true;
}
else {
this.connected = false;
}
} }
} }
class liveGraph { class feedbackNode extends node {
// Constructor to initialize the feedback node
constructor(nodeId) {
super(nodeId);
this.feedback = {};
this.answers = 0;
}
// Function to update the feedback
updateFeedback(feedback) {
this.feedback = feedback;
}
}
class liveGraph extends node{
// Constructor to initialize the graph // Constructor to initialize the graph
constructor(id) { constructor(id) {
this.timeArray = []; this.timeArray = [];
@@ -106,3 +124,51 @@ class liveGraph {
this.tvocArray.push(TVOC / 10); this.tvocArray.push(TVOC / 10);
} }
} }
class graph {
// Constructor to initialize the graph
constructor(id) {
this.timeArray = [];
this.tempArray = [];
this.humiArray = [];
this.eco2Array = [];
this.tvocArray = [];
this.nodeId = "graph" + id;
}
// Function to create a graph
makeGraph(amountOfGraphs) {
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],
mode: "lines",
line: { color: "#FF0000" },
name: "Temperature",
},
]);
}
}
// 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:
},
};
}
}