Refactor graph class constructor and methods
This commit is contained in:
@@ -42,13 +42,13 @@ 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);
|
||||||
this.timeArray = [];
|
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() {
|
||||||
@@ -127,23 +127,23 @@ class liveGraph extends node{
|
|||||||
|
|
||||||
class graph {
|
class graph {
|
||||||
// Constructor to initialize the graph
|
// Constructor to initialize the graph
|
||||||
constructor(id) {
|
constructor(id, graph) {
|
||||||
this.timeArray = [];
|
if (graph === "live") {
|
||||||
this.tempArray = [];
|
this.nodeId = "liveGraph" + id;
|
||||||
this.humiArray = [];
|
}
|
||||||
this.eco2Array = [];
|
else {
|
||||||
this.tvocArray = [];
|
|
||||||
this.nodeId = "graph" + id;
|
this.nodeId = "graph" + id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Function to create a graph
|
// Function to create a graph
|
||||||
makeGraph(amountOfGraphs) {
|
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: this.array[i],
|
y: array + i,
|
||||||
mode: "lines",
|
mode: "lines",
|
||||||
line: { color: "#FF0000" },
|
line: { color: "#FF0000" },
|
||||||
name: "Temperature",
|
name: "Temperature",
|
||||||
@@ -152,13 +152,13 @@ class graph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Function to update the graph with new values got from updateData function
|
// Function to update the graph with new values got from updateData function
|
||||||
updateGraph() {
|
updateGraph(array1, array2, array3, array4) {
|
||||||
let time = new Date();
|
let time = new Date();
|
||||||
this.timeArray.push(new Date());
|
this.timeArray.push(new Date());
|
||||||
|
|
||||||
let update = {
|
let update = {
|
||||||
x: [[this.timeArray]],
|
x: [[this.timeArray]],
|
||||||
y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]]
|
y: [array1, array2, array3, array4]
|
||||||
};
|
};
|
||||||
|
|
||||||
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
||||||
|
Reference in New Issue
Block a user