svg: removed support for non-standard %x and %y units; fixed layout update when resized;

This commit is contained in:
bordun 2020-08-28 13:39:07 +02:00
parent 6913860d68
commit b4bbed8bdb
2 changed files with 13 additions and 10 deletions

View file

@ -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

View file

@ -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',
'- `<path>` 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)
}