From 4cfcc9a7f9f61406c565e24b87d4cc83cc9a1ccf Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Fri, 18 Jan 2019 19:52:12 +0100 Subject: speed up zoom function for non-FF Browser --- src/types/Box.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/types') diff --git a/src/types/Box.js b/src/types/Box.js index 90979d2..190d60d 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -159,30 +159,32 @@ registerMethods({ }, zoom (level, point) { - var style = window.getComputedStyle(this.node) - - var width = parseFloat(style.getPropertyValue('width')) - - var height = parseFloat(style.getPropertyValue('height')) - - var v = this.viewbox() - - var zoomX = width / v.width - - var zoomY = height / v.height + let width = this.node.clientWidth + let height = this.node.clientHeight + const v = this.viewbox() + + // Firefox does not support clientHeight and returns 0 + // https://bugzilla.mozilla.org/show_bug.cgi?id=874811 + if (!width && !height) { + var style = window.getComputedStyle(this.node) + width = parseFloat(style.getPropertyValue('width')) + height = parseFloat(style.getPropertyValue('height')) + } - var zoom = Math.min(zoomX, zoomY) + const zoomX = width / v.width + const zoomY = height / v.height + const zoom = Math.min(zoomX, zoomY) if (level == null) { return zoom } - var zoomAmount = zoom / level + let zoomAmount = zoom / level if (zoomAmount === Infinity) zoomAmount = Number.MIN_VALUE point = point || new Point(width / 2 / zoomX + v.x, height / 2 / zoomY + v.y) - var box = new Box(v).transform( + const box = new Box(v).transform( new Matrix({ scale: zoomAmount, origin: point }) ) -- cgit v1.2.3