From 0f21fd2aead7b6c409d0fb36cce55c56e9529a1a Mon Sep 17 00:00:00 2001 From: Rémi Tétreault Date: Thu, 16 Feb 2017 20:35:05 -0500 Subject: Sort out leftovers from the old fx module This commit is mostly to clean up the implementation of the initAnimation method of the Fx Module (issue #547). It also fixes these issues: #552, #582 and #584. Here is a list of the changes and fixes that are made: * Add a plot and array method to SVG.TextPath (issue #582) * Make the method plot a getter when no parameter is passed for SVG.Polyline, SVG.Polygon, SVG.Line, SVG.Path (this idea come from issue #547) * Allow SVG.PointArray to be passed flat array * Change the regexp SVG.PointArray use to parse string to allow more flexibility in the way spaces and commas can be used to separate points (something like this is now accepted: '1, 2, 3, 4') * Allow plot to be called with 4 parameters when animating an SVG.Line * Fix a bug in the plain morphing part of SVG.MorphObj that is in the FX module * Relative value for SVG.Number are now calculated in its morph method (idea from issue #547) * Clean up the implementation of the initAnimation method of the FX module (issues #547, #552, #584) --- src/pointarray.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/pointarray.js') diff --git a/src/pointarray.js b/src/pointarray.js index c1e4c86..0a4401a 100644 --- a/src/pointarray.js +++ b/src/pointarray.js @@ -38,17 +38,22 @@ SVG.extend(SVG.PointArray, { return new SVG.PointArray(array) } - // Parse point string + // Parse point string and flat array , parse: function(array) { var points = [] array = array.valueOf() - // if already is an array, no need to parse it - if (Array.isArray(array)) return array - - // parse points - array = array.trim().split(/\s+|,/) + // if it is an array + if (Array.isArray(array)) { + // and it is not flat, there is no need to parse it + if(Array.isArray(array[0])) { + return array + } + } else { // Else, it is considered as a string + // parse points + array = array.trim().split(/[\s,]+/) + } // validate points - https://svgwg.org/svg2-draft/shapes.html#DataTypePoints // Odd number of coordinates is an error. In such cases, drop the last odd coordinate. @@ -94,4 +99,4 @@ SVG.extend(SVG.PointArray, { return SVG.parser.poly.getBBox() } -}) \ No newline at end of file +}) -- cgit v1.2.3