postDraw sample
This commit is contained in:
parent
b7d2f1ab0e
commit
b6237697c8
|
@ -47,14 +47,14 @@ class Graph {
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.preDraw();
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
|
this.preDraw(this);
|
||||||
this._draw();
|
this._draw();
|
||||||
this.postDraw();
|
this.postDraw(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_draw() {
|
_draw() {
|
||||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
||||||
|
|
||||||
this.ctx.beginPath();
|
this.ctx.beginPath();
|
||||||
this.ctx.moveTo(0, 0);
|
this.ctx.moveTo(0, 0);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class Graph {
|
||||||
this.ctx.fill();
|
this.ctx.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
_dummyFunc() {}
|
_dummyFunc(_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MovingGraph extends Graph {
|
class MovingGraph extends Graph {
|
||||||
|
|
|
@ -154,6 +154,8 @@
|
||||||
|
|
||||||
graph.smooth = true; // Can change on fly
|
graph.smooth = true; // Can change on fly
|
||||||
|
|
||||||
|
graph.postDraw = postDraw;
|
||||||
|
|
||||||
let amount = Math.random() * graph.getLength() * 1.4;
|
let amount = Math.random() * graph.getLength() * 1.4;
|
||||||
for (let v = 0; v < amount; v++) {
|
for (let v = 0; v < amount; v++) {
|
||||||
graph.add( Math.random() * 100 );
|
graph.add( Math.random() * 100 );
|
||||||
|
@ -178,6 +180,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postDraw(graph) {
|
||||||
|
graph.ctx.beginPath();
|
||||||
|
|
||||||
|
graph.ctx.moveTo(0, 100);
|
||||||
|
graph.ctx.lineTo(10000, 100);
|
||||||
|
|
||||||
|
graph.ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
function callbackData(data) {
|
function callbackData(data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user