Permalink
Browse files

Fixed problem with dashOffset

  • Loading branch information...
nvh committed Jan 31, 2018
1 parent 77dbf87 commit 8b1c6f380892b4824404ab5e7c63b86c8bb48e2c
Showing with 16 additions and 5 deletions.
  1. +12 −4 framer/SVGPath.coffee
  2. +4 −1 test/tests/SVGPathTest.coffee
View
@@ -3,17 +3,25 @@
{SVGBaseLayer} = require "./SVGBaseLayer"
{SVG} = require "./SVG"
dashArrayTransform = (value) ->
dasharrayTransform = (value) ->
if _.isString value
values = []
if value.indexOf(",") isnt -1
values = value.split(',')
else
values = value.split(" ")
values = values.filter((v) -> v.length > 0).map((v) -> parseFloat(v.trim()))
values = values.map((v) -> v.trim())
.filter((v) -> v.length > 0)
.map((v) -> parseFloat(v))
return values
return value
dashoffsetTransform = (value) ->
v = parseFloat(value)
if isNaN(v)
return null
return value
class exports.SVGPath extends SVGBaseLayer
constructor: (path, options) ->
@@ -38,8 +46,8 @@ class exports.SVGPath extends SVGBaseLayer
@define "strokeLinejoin", layerProperty(@, "strokeLinejoin", "strokeLinejoin", null, _.isString)
@define "strokeMiterlimit", layerProperty(@, "strokeMiterlimit", "strokeMiterlimit", null, _.isNumber, parseFloat)
@define "strokeOpacity", layerProperty(@, "strokeOpacity", "strokeOpacity", null, _.isNumber, parseFloat)
@define "strokeDasharray", layerProperty(@, "strokeDasharray", "strokeDasharray", [], _.isArray, dashArrayTransform)
@define "strokeDashoffset", layerProperty(@, "strokeDashoffset", "strokeDashoffset", null, _.isNumber, parseFloat)
@define "strokeDasharray", layerProperty(@, "strokeDasharray", "strokeDasharray", [], _.isArray, dasharrayTransform)
@define "strokeDashoffset", layerProperty(@, "strokeDashoffset", "strokeDashoffset", null, _.isNumber, dashoffsetTransform)
@define "strokeLength", layerProperty @, "strokeLength", null, undefined, _.isNumber, null, {}, (path, value) ->
path._properties.strokeFraction = value / path.length
if _.isEmpty path.strokeDasharray
@@ -1,3 +1,5 @@
{expect} = require "chai"
describe "SVGPath", ->
svg = null
path = null
@@ -34,9 +36,10 @@ describe "SVGPath", ->
describe "storkeDasharray", ->
it "should work when the dashArray is an empty string", ->
layer = new SVGLayer
svg: """<svg><path stroke-dasharray="" id='test' name='path' d='M 0 0 L 100 200'/>"""
svg: """<svg><path stroke-dasharray="" stroke-dashoffset="" id='test' name='path' d='M 0 0 L 100 200'/>"""
stroke: '#000'
layer.elements.test.strokeDasharray.should.eql []
expect(layer.elements.test.strokeDashoffset).to.be.null
describe "positioning", ->
it "should proxy the transform property to the SVGLayer if that is it's direct parent", ->

0 comments on commit 8b1c6f3

Please sign in to comment.