Permalink
Browse files

Trying an experiment with parentAlias

  • Loading branch information...
nvh committed Jan 19, 2018
1 parent 875e2ba commit 55a881b9724a53f744fe4daa453bbd6cfd5022e5
Showing with 41 additions and 7 deletions.
  1. +23 −0 framer/SVGBaseLayer.coffee
  2. +18 −7 test/tests/SVGPathTest.coffee
View
@@ -23,6 +23,29 @@ class exports.SVGBaseLayer extends Layer
get: ->
@_parent or null
@define "html", get: -> @_element.outerHTML or ""
@parentAlias = (name, defaultValue = 0) ->
originalDescriptor = Object.getOwnPropertyDescriptor(Layer::, name)
@define name,
default: defaultValue
get: ->
if @_parent instanceof SVGLayer
return @_parent[name]
else
return originalDescriptor.get.call(@)
set: (value) ->
if @_parent instanceof SVGLayer
if @__applyingDefaults
@_properties[name] = value
else
@_parent[name] = value
else
originalDescriptor.set?.call(@, value)
@parentAlias "x"
@parentAlias "y"
@parentAlias "z"
@define "width", get: -> @_width
@define "height", get: -> @_height
@define "originX", layerProperty(@, "originX", "webkitTransformOrigin", 0.5, _.isNumber, originTransform)
@@ -1,12 +1,14 @@
describe "SVGPath", ->
svg = null
path = null
beforeEach ->
svg = new SVGLayer
x: 123
y: 456
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><path d="M 100 50 C 100 77.614 77.614 100 50 100 C 22.386 100 0 77.614 0 50 C 0 22.386 22.386 0 50 0" id="path" name="path" fill="transparent" stroke="#0AF"></path></svg>'
path = svg.elements.path
describe "pointAtFraction", ->
path = null
beforeEach ->
svg = new SVGLayer
x: 123
y: 456
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><path d="M 100 50 C 100 77.614 77.614 100 50 100 C 22.386 100 0 77.614 0 50 C 0 22.386 22.386 0 50 0" id="path" name="path" fill="transparent" stroke="#0AF"></path></svg>'
path = svg.elements.path
it "should get the beginning", ->
point = path.pointAtFraction(0)
@@ -25,3 +27,12 @@ describe "SVGPath", ->
point = path.pointAtFraction(2/3)
point.x.should.be.closeTo 0, 0.01
point.y.should.be.closeTo 50, 0.01
describe "positioning", ->
it "should proxy the x and y property to the SVGLayer if that is it's direct parent", ->
path.x.should.equal 123
path.y.should.equal 456
path.x = 23
path.y = 17
svg.x.should.equal 23
svg.y.should.equal 17

0 comments on commit 55a881b

Please sign in to comment.