Mercurial > gemma
changeset 3478:afab8d87932c
mixin: assume when element not in DOM width and height are 0
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 27 May 2019 15:08:44 +0200 |
parents | 4eefeeae03fc |
children | 83b58f6356e7 965b2fbb1890 ba26adce0ce8 |
files | client/src/lib/mixins.js |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/lib/mixins.js Mon May 27 13:58:19 2019 +0200 +++ b/client/src/lib/mixins.js Mon May 27 15:08:44 2019 +0200 @@ -35,10 +35,9 @@ methods: { getDimensions({ main, nav }) { //dimensions and margins - const svgWidth = document.querySelector("#" + this.containerId) - .clientWidth; - const svgHeight = document.querySelector("#" + this.containerId) - .clientHeight; + const elem = document.querySelector("#" + this.containerId); + const svgWidth = elem ? elem.clientWidth : 0; + const svgHeight = elem ? elem.clientHeight : 0; const mainMargin = main || { top: 20, right: 20, bottom: 110, left: 80 }; const navMargin = nav || { top: svgHeight - mainMargin.top - 65, @@ -46,9 +45,9 @@ bottom: 30, left: 80 }; - const width = +svgWidth - mainMargin.left - mainMargin.right; - const mainHeight = +svgHeight - mainMargin.top - mainMargin.bottom; - const navHeight = +svgHeight - navMargin.top - navMargin.bottom; + const width = Number(svgWidth) - mainMargin.left - mainMargin.right; + const mainHeight = Number(svgHeight) - mainMargin.top - mainMargin.bottom; + const navHeight = Number(svgHeight) - navMargin.top - navMargin.bottom; return { width, mainHeight, navHeight, mainMargin, navMargin }; } }