Refactor classes.js to update connection status and add feedbackNode and graph classes
This commit is contained in:
@@ -16,12 +16,30 @@ class node {
|
||||
this.TVOC = TVOC;
|
||||
}
|
||||
// Function to update the connection status
|
||||
updateConnection(status) {
|
||||
this.connected = status;
|
||||
updateConnection() {
|
||||
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(id) {
|
||||
this.timeArray = [];
|
||||
@@ -106,3 +124,51 @@ class liveGraph {
|
||||
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:
|
||||
},
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user