From b4bbed8bdbdcecd751763fcc91dde10fd0ce5c08 Mon Sep 17 00:00:00 2001 From: bordun Date: Fri, 28 Aug 2020 13:39:07 +0200 Subject: [PATCH] svg: removed support for non-standard `%x` and `%y` units; fixed layout update when resized; --- CHANGELOG.md | 3 +++ src/client/widgets/frames/svg.js | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 928696b5..14b1f715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - midi - added support for channel pressure and key pressure messages +- widgets + - svg: removed support for non-standard `%x` and `%y` units; fixed layout update when resized; + ## 1.0.4 - bug fixes diff --git a/src/client/widgets/frames/svg.js b/src/client/widgets/frames/svg.js index fbe417c7..0f7bc433 100644 --- a/src/client/widgets/frames/svg.js +++ b/src/client/widgets/frames/svg.js @@ -19,9 +19,7 @@ class Svg extends StaticProperties(Widget, {bypass: true}) { _class_specific: 'svg', svg: {type: 'string', value: '', help: [ - 'Svg xml definition:', - '- will be wrapped in a `< svg />` element', - '- `` commands support a special percent notation (`%x` and `%y`)' + 'Svg xml definition (will be wrapped in a `< svg />` element)', ]}, }, ['decimals', 'bypass'], {}) @@ -47,22 +45,24 @@ class Svg extends StaticProperties(Widget, {bypass: true}) { } - updateSvg(){ + updateSvg(force){ if (!this.width || !this.height) return var svg = this.getProp('svg') - svg = svg.replace(/<\/svg>/gi, 'x') - svg = svg.replace(/([0-9.]+%x)/gi, m=>(parseFloat(m) * this.width / 100).toFixed(2)) - svg = svg.replace(/([0-9.]+%y)/gi, m=>(parseFloat(m) * this.height / 100).toFixed(2)) - + this.frame.setAttribute('width', this.width) + this.frame .setAttribute('height', this.height) var node = this.frame.cloneNode(false) node.innerHTML = svg - morph(this.frame, node) + if (force) { + this.frame.innerHTML = node.innerHTML + } else { + morph(this.frame, node) + } } @@ -79,7 +79,7 @@ class Svg extends StaticProperties(Widget, {bypass: true}) { this.height = height this.width = width - this.updateSvg() + this.updateSvg(true) }