mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
fixed #363
This commit is contained in:
@@ -43,16 +43,17 @@
|
|||||||
*/
|
*/
|
||||||
setPoints: function(val) {
|
setPoints: function(val) {
|
||||||
this.setAttr('points', Kinetic.Type._getPoints(val));
|
this.setAttr('points', Kinetic.Type._getPoints(val));
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* get points array
|
||||||
|
* @name getPoints
|
||||||
|
* @methodOf Kinetic.Line.prototype
|
||||||
|
*/
|
||||||
|
// NOTE: cannot use getter method because we need to return a new
|
||||||
|
// default array literal each time because arrays are modified by reference
|
||||||
|
getPoints: function() {
|
||||||
|
return this.attrs.points || [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape);
|
Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape);
|
||||||
|
|
||||||
// add getters setters
|
|
||||||
Kinetic.Node.addGetter(Kinetic.Line, 'points', []);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get points array
|
|
||||||
* @name getPoints
|
|
||||||
* @methodOf Kinetic.Line.prototype
|
|
||||||
*/
|
|
||||||
})();
|
})();
|
||||||
|
@@ -49,6 +49,41 @@ Test.Modules.LINE = {
|
|||||||
|
|
||||||
test(line.getShapeType() === 'Line', 'shape type should be Line');
|
test(line.getShapeType() === 'Line', 'shape type should be Line');
|
||||||
},
|
},
|
||||||
|
'test default ponts array for two lines': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var line = new Kinetic.Line({
|
||||||
|
stroke: 'blue',
|
||||||
|
strokeWidth: 20,
|
||||||
|
lineCap: 'round',
|
||||||
|
lineJoin: 'round',
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var redLine = new Kinetic.Line({
|
||||||
|
x: 50,
|
||||||
|
stroke: 'red',
|
||||||
|
strokeWidth: 20,
|
||||||
|
lineCap: 'round',
|
||||||
|
lineJoin: 'round',
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
line.setPoints([0,1,2,3]);
|
||||||
|
redLine.setPoints([4,5,6,7]);
|
||||||
|
|
||||||
|
layer.add(line).add(redLine);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(line.getPoints()[0].x === 0, 'line points is wrong');
|
||||||
|
test(redLine.getPoints()[0].x === 4, 'redLine points is wrong');
|
||||||
|
|
||||||
|
},
|
||||||
'add dashed line': function(containerId) {
|
'add dashed line': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
Reference in New Issue
Block a user