mirror of
https://github.com/konvajs/konva.git
synced 2025-08-24 11:36:27 +08:00
added getNodeType() and getShapeType() methods
This commit is contained in:
parent
f0037ce9c6
commit
542f675522
@ -926,6 +926,14 @@
|
|||||||
go._addName(this, name);
|
go._addName(this, name);
|
||||||
this.setAttr(NAME, name);
|
this.setAttr(NAME, name);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* get node type. Returns 'Stage', 'Layer', 'Group', or 'Shape'
|
||||||
|
* @name getNodeType
|
||||||
|
* @methodOf Kinetic.Node.prototype
|
||||||
|
*/
|
||||||
|
getNodeType: function() {
|
||||||
|
return this.nodeType;
|
||||||
|
},
|
||||||
setAttr: function(key, val) {
|
setAttr: function(key, val) {
|
||||||
var oldVal;
|
var oldVal;
|
||||||
if(val !== undefined) {
|
if(val !== undefined) {
|
||||||
|
@ -163,6 +163,14 @@
|
|||||||
disableDashArray: function() {
|
disableDashArray: function() {
|
||||||
this.setAttr('dashArrayEnabled', false);
|
this.setAttr('dashArrayEnabled', false);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* get shape type. Ex. 'Circle', 'Rect', 'Text', etc.
|
||||||
|
* @name getShapeType
|
||||||
|
* @methodOf Kinetic.Shape.prototype
|
||||||
|
*/
|
||||||
|
getShapeType: function() {
|
||||||
|
return this.shapeType;
|
||||||
|
},
|
||||||
remove: function() {
|
remove: function() {
|
||||||
Kinetic.Node.prototype.remove.call(this);
|
Kinetic.Node.prototype.remove.call(this);
|
||||||
delete Kinetic.Global.shapes[this.colorKey];
|
delete Kinetic.Global.shapes[this.colorKey];
|
||||||
|
@ -2654,5 +2654,40 @@ Test.Modules.NODE = {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(layer.toDataURL() === dataUrls['cleared'], 'group is still visible');
|
test(layer.toDataURL() === dataUrls['cleared'], 'group is still visible');
|
||||||
|
},
|
||||||
|
'test getNodeType()': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
var group = new Kinetic.Group();
|
||||||
|
|
||||||
|
var rect = new Kinetic.Rect({
|
||||||
|
x: 200,
|
||||||
|
y: 100,
|
||||||
|
width: 100,
|
||||||
|
height: 50,
|
||||||
|
fill: 'red',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
draggable: true,
|
||||||
|
rotationDeg: 60,
|
||||||
|
scale: {
|
||||||
|
x: 2,
|
||||||
|
y: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
group.add(rect);
|
||||||
|
layer.add(group);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(stage.getNodeType() === 'Stage', 'node type should be Stage');
|
||||||
|
test(layer.getNodeType() === 'Layer', 'node type should be Layer');
|
||||||
|
test(group.getNodeType() === 'Group', 'node type should be Group');
|
||||||
|
test(rect.getNodeType() === 'Shape', 'node type should be Shape');
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -51,5 +51,7 @@ Test.Modules.LABEL = {
|
|||||||
label.getText().setText('Hello big world');
|
label.getText().setText('Hello big world');
|
||||||
|
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
|
test(label.getNodeType() === 'Group', 'label should be a group');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -45,6 +45,8 @@ Test.Modules.PATH = {
|
|||||||
test(path.dataArray.length === 1, 'data array should have 1 element');
|
test(path.dataArray.length === 1, 'data array should have 1 element');
|
||||||
|
|
||||||
path.setData('M200,100h100v50z');
|
path.setData('M200,100h100v50z');
|
||||||
|
|
||||||
|
test(path.getShapeType() === 'Path', 'shape type should be Path');
|
||||||
|
|
||||||
},
|
},
|
||||||
'add path with line cap and line join': function(containerId) {
|
'add path with line cap and line join': function(containerId) {
|
||||||
|
@ -24,6 +24,8 @@ Test.Modules.REGULAR_POLYGON = {
|
|||||||
|
|
||||||
layer.add(poly);
|
layer.add(poly);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(poly.getShapeType() === 'RegularPolygon', 'shape type should be RegularPolygon');
|
||||||
|
|
||||||
},
|
},
|
||||||
'add regular polygon square': function(containerId) {
|
'add regular polygon square': function(containerId) {
|
||||||
|
@ -29,6 +29,8 @@ Test.Modules.STAR = {
|
|||||||
|
|
||||||
layer.add(star);
|
layer.add(star);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(star.getShapeType() === 'Star', 'shape type should be Star');
|
||||||
},
|
},
|
||||||
'add five point star with line join and shadow': function(containerId) {
|
'add five point star with line join and shadow': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -33,6 +33,8 @@ Test.Modules['TEXT PATH'] = {
|
|||||||
|
|
||||||
layer.add(textpath);
|
layer.add(textpath);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(textpath.getShapeType() === 'TextPath', 'shape type should be TextPath');
|
||||||
},
|
},
|
||||||
'Render Text Along two connected Bezier': function(containerId) {
|
'Render Text Along two connected Bezier': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -60,6 +60,8 @@ Test.Modules.BLOB = {
|
|||||||
test(blob1.getTension() === 0.8, 'blob1 tension should be 0.8');
|
test(blob1.getTension() === 0.8, 'blob1 tension should be 0.8');
|
||||||
test(blob2.getTension() === 1.2, 'blob2 tension should be 1.2');
|
test(blob2.getTension() === 1.2, 'blob2 tension should be 1.2');
|
||||||
|
|
||||||
|
test(blob1.getShapeType() === 'Blob', 'shape type should be Blob');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,8 @@ Test.Modules.CIRCLE = {
|
|||||||
test(attrs.strokeWidth === 4, 'strokeWidth attr should be strokeWidth');
|
test(attrs.strokeWidth === 4, 'strokeWidth attr should be strokeWidth');
|
||||||
test(attrs.name === 'myCircle', 'name attr should be myCircle');
|
test(attrs.name === 'myCircle', 'name attr should be myCircle');
|
||||||
test(attrs.draggable === true, 'draggable attr should be true');
|
test(attrs.draggable === true, 'draggable attr should be true');
|
||||||
},
|
test(circle.getShapeType() === 'Circle', 'shape type should be Circle');
|
||||||
|
},
|
||||||
'add circle with pattern fill': function(containerId) {
|
'add circle with pattern fill': function(containerId) {
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = function() {
|
imageObj.onload = function() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Test.Modules.ELLISPE = {
|
Test.Modules.ELLIPSE = {
|
||||||
'add ellipse': function(containerId) {
|
'add ellipse': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
@ -6,7 +6,7 @@ Test.Modules.ELLISPE = {
|
|||||||
height: 200
|
height: 200
|
||||||
});
|
});
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
var circle = new Kinetic.Ellipse({
|
var ellipse = new Kinetic.Ellipse({
|
||||||
x: stage.getWidth() / 2,
|
x: stage.getWidth() / 2,
|
||||||
y: stage.getHeight() / 2,
|
y: stage.getHeight() / 2,
|
||||||
radius: [70, 35],
|
radius: [70, 35],
|
||||||
@ -14,7 +14,8 @@ Test.Modules.ELLISPE = {
|
|||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
strokeWidth: 8
|
strokeWidth: 8
|
||||||
});
|
});
|
||||||
layer.add(circle);
|
layer.add(ellipse);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
test(ellipse.getShapeType() === 'Ellipse', 'shape type should be Ellipse');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -117,6 +117,8 @@ Test.Modules.IMAGE = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//document.body.appendChild(layer.bufferCanvas.element)
|
//document.body.appendChild(layer.bufferCanvas.element)
|
||||||
|
|
||||||
|
test(darth.getShapeType() === 'Image', 'shape type should be Image');
|
||||||
|
|
||||||
};
|
};
|
||||||
imageObj.src = '../assets/darth-vader.jpg';
|
imageObj.src = '../assets/darth-vader.jpg';
|
||||||
|
@ -46,6 +46,8 @@ Test.Modules.LINE = {
|
|||||||
|
|
||||||
line.setPoints([73, 160, 340, 23]);
|
line.setPoints([73, 160, 340, 23]);
|
||||||
test(line.getPoints()[0].x === 73, 'first point x should be 73');
|
test(line.getPoints()[0].x === 73, 'first point x should be 73');
|
||||||
|
|
||||||
|
test(line.getShapeType() === 'Line', 'shape type should be Line');
|
||||||
},
|
},
|
||||||
'add dashed line': function(containerId) {
|
'add dashed line': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -36,6 +36,8 @@ Test.Modules.POLYGON - {
|
|||||||
|
|
||||||
layer.add(poly);
|
layer.add(poly);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(poly.getShapeType() === 'Polygon', 'shape type should be Polygon');
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -24,6 +24,8 @@ Test.Modules.RECT = {
|
|||||||
|
|
||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(rect.getShapeType() === 'Rect', 'shape type should be Rect');
|
||||||
},
|
},
|
||||||
'add stroke rect': function(containerId) {
|
'add stroke rect': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -112,6 +112,8 @@ Test.Modules.SPRITE = {
|
|||||||
sprite.stop();
|
sprite.stop();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
//document.body.appendChild(layer.bufferCanvas.element)
|
//document.body.appendChild(layer.bufferCanvas.element)
|
||||||
|
|
||||||
|
test(sprite.getShapeType() === 'Sprite', 'shape type should be Sprite');
|
||||||
};
|
};
|
||||||
imageObj.src = '../assets/scorpion-sprite.png';
|
imageObj.src = '../assets/scorpion-sprite.png';
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ Test.Modules.Text = {
|
|||||||
group.add(text);
|
group.add(text);
|
||||||
layer.add(group);
|
layer.add(group);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(text.getShapeType() === 'Text', 'shape type should be Text');
|
||||||
},
|
},
|
||||||
'text getters and setters': function(containerId) {
|
'text getters and setters': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -23,6 +23,8 @@ Test.Modules.Wedge = {
|
|||||||
|
|
||||||
//console.log(layer.toDataURL());
|
//console.log(layer.toDataURL());
|
||||||
warn(layer.toDataURL() === dataUrls['wedge'], 'problem rendering wedge');
|
warn(layer.toDataURL() === dataUrls['wedge'], 'problem rendering wedge');
|
||||||
|
|
||||||
|
test(wedge.getShapeType() === 'Wedge', 'shape type should be Wedge');
|
||||||
},
|
},
|
||||||
'set wedge angle using degrees': function(containerId) {
|
'set wedge angle using degrees': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
Loading…
Reference in New Issue
Block a user