From d98545fdeec25a658f3cefd0fdc9d41a83fecb90 Mon Sep 17 00:00:00 2001 From: Jordi Tost Date: Thu, 2 Jun 2016 12:16:06 +0200 Subject: [PATCH] Path conversion for open paths Only add Z at the end of the new shape if the input shape also has it. --- polymorph.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/polymorph.js b/polymorph.js index 1f941c6..d45743c 100644 --- a/polymorph.js +++ b/polymorph.js @@ -12,7 +12,7 @@ polymorph = { ## transpose Duplicate node positioning from one shape onto another @param from {string} SVG shape containing the nodes to be copied - @param to {string} Resulting SVG shape which will contain a + @param to {string} Resulting SVG shape which will contain a representation of the nodes from the first shape. */ polymorph.transpose = function(from, to){ @@ -88,5 +88,13 @@ polymorph.transpose = function(from, to){ measures = getMeasures(from); newShape = transpose(measures, to); svg.parentNode.removeChild(svg); - return "M" + newShape.join('L') + "Z"; -}; \ No newline at end of file + + var newPath = "M" + newShape.join('L'); + + // Close shape if input shape is closed + if (from.indexOf("Z") > -1) { + newPath += "Z"; + } + + return newPath; +};