mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
ring param sync :neckbeard: fix #987
This commit is contained in:
parent
0ffcdb57a5
commit
4ffa672dce
@ -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
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user