From 4ffa672dce14318c7678b4159ed15543234ae0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B2=D1=80=D1=91=D0=BD=D0=BE=D0=B2=20=D0=90?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=BD?= Date: Mon, 11 Aug 2014 23:56:13 +0800 Subject: [PATCH] ring param sync :neckbeard: fix #987 --- src/shapes/Ring.js | 16 +++++++++++++--- test/unit/shapes/Ring-test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/shapes/Ring.js b/src/shapes/Ring.js index 87dfe092..1c6ffda6 100644 --- a/src/shapes/Ring.js +++ b/src/shapes/Ring.js @@ -51,12 +51,21 @@ // implements Shape.prototype.setWidth() setWidth: function(width) { Kinetic.Node.prototype.setWidth.call(this, width); - this.setOuterRadius(width / 2); + if (this.outerRadius() !== width / 2) { + this.setOuterRadius(width / 2); + } }, // implements Shape.prototype.setHeight() setHeight: function(height) { Kinetic.Node.prototype.setHeight.call(this, height); - this.setOuterRadius(height / 2); + if (this.outerRadius() !== height / 2) { + this.setOuterRadius(height / 2); + } + }, + setOuterRadius : function(val) { + this._setAttr('outerRadius', val); + this.setWidth(val * 2); + this.setHeight(val * 2); } }; Kinetic.Util.extend(Kinetic.Ring, Kinetic.Shape); @@ -79,7 +88,8 @@ * ring.innerRadius(20); */ - Kinetic.Factory.addGetterSetter(Kinetic.Ring, 'outerRadius', 0); + Kinetic.Factory.addGetter(Kinetic.Ring, 'outerRadius', 0); + Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Ring, 'outerRadius'); /** * get/set outerRadius diff --git a/test/unit/shapes/Ring-test.js b/test/unit/shapes/Ring-test.js index 5f8cf51e..25698421 100644 --- a/test/unit/shapes/Ring-test.js +++ b/test/unit/shapes/Ring-test.js @@ -21,4 +21,33 @@ suite('Ring', function() { var trace = layer.getContext().getTrace(); assert.equal(trace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,50,0,6.283,false);moveTo(90,0);arc(0,0,90,6.283,0,true);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();'); }); + + // ====================================================== + // test for https://github.com/ericdrowell/KineticJS/issues/987 + test('ring attrs sync', function() { + var stage = addStage(); + var layer = new Kinetic.Layer(); + var ring = new Kinetic.Ring({ + name: 'ring', + x: 30, + y: 50, + width: 50, + height: 50, + innerRadius: 15, + outerRadius: 30, + fill: 'green', + stroke: 'black', + strokeWidth: 4, + draggable: true + }); + layer.add(ring); + stage.add(layer); + + + var cring = ring.clone(); + assert.equal(cring.outerRadius(), ring.outerRadius()); + + assert.equal(ring.attrs.width, ring.outerRadius() * 2); + }); + }); \ No newline at end of file