From 1567dde5d3d987e99518f675322ca4464f28e39c Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 16 Apr 2020 18:44:31 +0200 Subject: [PATCH] visualizer: ensure canvas loop is running when starting its own loop --- src/client/widgets/common/queue.js | 12 ++++++++---- src/client/widgets/graphs/visualizer.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/widgets/common/queue.js b/src/client/widgets/common/queue.js index 21911f58..9b0ba092 100644 --- a/src/client/widgets/common/queue.js +++ b/src/client/widgets/common/queue.js @@ -19,11 +19,15 @@ class CanvasQueue extends EventEmitter{ this.queue[widget.hash] = widget this.flushed = 0 + if (!this.running) this.startLoop() - if (!this.running) { - this.running = true - requestAnimationFrame(this.bindedLoop) - } + } + + startLoop() { + + this.running = true + this.flushed = 0 + requestAnimationFrame(this.bindedLoop) } diff --git a/src/client/widgets/graphs/visualizer.js b/src/client/widgets/graphs/visualizer.js index 5e555739..3fcd592b 100644 --- a/src/client/widgets/graphs/visualizer.js +++ b/src/client/widgets/graphs/visualizer.js @@ -53,6 +53,7 @@ module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: if (!this.looping) { this.lastUpdate = Date.now() canvasQueue.on('frame', this.bindedLoop) + if (!canvasQueue.running) canvasQueue.startLoop() this.looping = true this.ticks = 0 }