diff --git a/HISTORY.md b/HISTORY.md index 7aef9f36..53f0fe68 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ http://visjs.org - Added German (de) locale. Thanks @Tooa. - Fixed critical camera zoom bug #1273. - Fixed unselectAll method. #1256 +- Fixed bug that broke the network if drawn in a hidden div #1254 ### Timeline diff --git a/dist/vis.js b/dist/vis.js index ac903761..50d54588 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -35946,6 +35946,11 @@ return /******/ (function(modules) { // webpackBootstrap var h = this.canvas.frame.canvas.clientHeight; ctx.clearRect(0, 0, w, h); + // if the div is hidden, we stop the redraw here for performance. + if (this.canvas.frame.clientWidth === 0) { + return; + } + // set scaling and translation ctx.save(); ctx.translate(this.body.view.translation.x, this.body.view.translation.y); @@ -36267,7 +36272,8 @@ return /******/ (function(modules) { // webpackBootstrap }, { key: '_setCameraState', value: function _setCameraState() { - if (this.cameraState.scale !== undefined) { + if (this.cameraState.scale !== undefined && this.frame.canvas.clientWidth !== 0 && this.frame.canvas.clientHeight !== 0 && this.pixelRatio !== 0 && this.cameraState.previousWidth > 0) { + this.body.view.scale = this.cameraState.scale * (this.frame.canvas.width / this.pixelRatio / this.cameraState.previousWidth); // this comes from the view module. diff --git a/lib/network/modules/Canvas.js b/lib/network/modules/Canvas.js index 55acb2df..f13de18a 100644 --- a/lib/network/modules/Canvas.js +++ b/lib/network/modules/Canvas.js @@ -98,7 +98,12 @@ class Canvas { * @private */ _setCameraState() { - if (this.cameraState.scale !== undefined) { + if (this.cameraState.scale !== undefined && + this.frame.canvas.clientWidth !== 0 && + this.frame.canvas.clientHeight !== 0 && + this.pixelRatio !== 0 && + this.cameraState.previousWidth > 0) { + this.body.view.scale = this.cameraState.scale * ((this.frame.canvas.width / this.pixelRatio) / this.cameraState.previousWidth); // this comes from the view module. diff --git a/lib/network/modules/CanvasRenderer.js b/lib/network/modules/CanvasRenderer.js index 9ddbb6a1..b6ec0b86 100644 --- a/lib/network/modules/CanvasRenderer.js +++ b/lib/network/modules/CanvasRenderer.js @@ -160,6 +160,11 @@ class CanvasRenderer { let h = this.canvas.frame.canvas.clientHeight; ctx.clearRect(0, 0, w, h); + // if the div is hidden, we stop the redraw here for performance. + if (this.canvas.frame.clientWidth === 0) { + return; + } + // set scaling and translation ctx.save(); ctx.translate(this.body.view.translation.x, this.body.view.translation.y); diff --git a/test/networkTest.html b/test/networkTest.html index a6627699..9d9d6b67 100644 --- a/test/networkTest.html +++ b/test/networkTest.html @@ -15,11 +15,11 @@ } - - - - - + + + + + @@ -81,7 +80,7 @@

Popup Example

-