From 9badda730fb8afb1eefd9a776eec645eee936a60 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 13 Feb 2018 10:59:54 +0100 Subject: [PATCH] svg: change path percents support to use unambiguous notation: %x and %y --- resources/docs/widgets/plots.md | 2 +- src/browser/js/app/widgets/plots/svg.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/docs/widgets/plots.md b/resources/docs/widgets/plots.md index d99d051b..1cebf0c4 100644 --- a/resources/docs/widgets/plots.md +++ b/resources/docs/widgets/plots.md @@ -281,4 +281,4 @@ Image displays an image from a file path/url or from a base64 encoded image stri - default: `''` - usage : svg xml definition - will be wrapped in a `` element - - `` commands support percent notation + - `` commands support a special percent notation (`%x` and `%y`) diff --git a/src/browser/js/app/widgets/plots/svg.js b/src/browser/js/app/widgets/plots/svg.js index fc46691a..1b0586d3 100644 --- a/src/browser/js/app/widgets/plots/svg.js +++ b/src/browser/js/app/widgets/plots/svg.js @@ -60,8 +60,8 @@ class Svg extends Widget { var svg = this.getProp('svg') svg = svg.replace(/<\/svg>/gi, 'x') - svg = svg.replace(/([0-9\.]+%)[\s\n]*,/g, m => (parseFloat(m) * this.width / 100).toFixed(2) + ',') - svg = svg.replace(/,[\s\n]*([0-9\.]+%)/g, m => ',' + (parseFloat(m.slice(1)) * this.height / 100).toFixed(2)) + 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)) morph(this.widget, DOM.create('
' + svg + '
'))