mirror of
https://github.com/konvajs/konva.git
synced 2025-07-15 09:53:04 +08:00
tied className into toJSON and create. deprecated shapeType property and getShapeType method
This commit is contained in:
parent
7069bf9e0c
commit
35b1f61bda
35
src/Node.js
35
src/Node.js
@ -661,8 +661,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj.className = this.className;
|
||||||
obj.nodeType = this.nodeType;
|
obj.nodeType = this.nodeType;
|
||||||
obj.shapeType = this.shapeType;
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
@ -817,8 +817,8 @@
|
|||||||
*/
|
*/
|
||||||
clone: function(obj) {
|
clone: function(obj) {
|
||||||
// instantiate new node
|
// instantiate new node
|
||||||
var classType = this.shapeType || this.nodeType,
|
var className = this.getClassName(),
|
||||||
node = new Kinetic[classType](this.attrs),
|
node = new Kinetic[className](this.attrs),
|
||||||
key, allListeners, len, n, listener;
|
key, allListeners, len, n, listener;
|
||||||
|
|
||||||
// copy over listeners
|
// copy over listeners
|
||||||
@ -963,7 +963,7 @@
|
|||||||
* @memberof Kinetic.Node.prototype
|
* @memberof Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
getClassName: function() {
|
getClassName: function() {
|
||||||
return this.className || this.shapeType || this.nodeType;
|
return this.className || this.nodeType;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* get the node type, which may return Stage, Layer, Group, or Node
|
* get the node type, which may return Stage, Layer, Group, or Node
|
||||||
@ -1324,33 +1324,20 @@
|
|||||||
return this._createNode(JSON.parse(json), container);
|
return this._createNode(JSON.parse(json), container);
|
||||||
};
|
};
|
||||||
Kinetic.Node._createNode = function(obj, container) {
|
Kinetic.Node._createNode = function(obj, container) {
|
||||||
var type, no, len, n;
|
var className = Kinetic.Node.prototype.getClassName.call(obj),
|
||||||
|
children = obj.children,
|
||||||
// determine type
|
no, len, n;
|
||||||
if(obj.nodeType === SHAPE) {
|
|
||||||
// add custom shape
|
|
||||||
if(obj.shapeType === undefined) {
|
|
||||||
type = SHAPE;
|
|
||||||
}
|
|
||||||
// add standard shape
|
|
||||||
else {
|
|
||||||
type = obj.shapeType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
type = obj.nodeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if container was passed in, add it to attrs
|
// if container was passed in, add it to attrs
|
||||||
if(container) {
|
if(container) {
|
||||||
obj.attrs.container = container;
|
obj.attrs.container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
no = new Kinetic[type](obj.attrs);
|
no = new Kinetic[className](obj.attrs);
|
||||||
if(obj.children) {
|
if(children) {
|
||||||
len = obj.children.length;
|
len = children.length;
|
||||||
for(n = 0; n < len; n++) {
|
for(n = 0; n < len; n++) {
|
||||||
no.add(this._createNode(obj.children[n]));
|
no.add(this._createNode(children[n]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/Shape.js
10
src/Shape.js
@ -71,7 +71,7 @@
|
|||||||
return !!(this.getFill() || this.getFillPatternImage() || this.getFillLinearGradientColorStops() || this.getFillRadialGradientColorStops());
|
return !!(this.getFill() || this.getFillPatternImage() || this.getFillLinearGradientColorStops() || this.getFillRadialGradientColorStops());
|
||||||
},
|
},
|
||||||
_get: function(selector) {
|
_get: function(selector) {
|
||||||
return this.nodeType === selector || this.shapeType === selector ? [this] : [];
|
return this.className === selector || this.nodeType === selector ? [this] : [];
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
|
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
|
||||||
@ -174,14 +174,6 @@
|
|||||||
disableDashArray: function() {
|
disableDashArray: function() {
|
||||||
this._setAttr('dashArrayEnabled', false);
|
this._setAttr('dashArrayEnabled', false);
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* get shape type. Ex. 'Circle', 'Rect', 'Text', etc.
|
|
||||||
* @method
|
|
||||||
* @memberof Kinetic.Shape.prototype
|
|
||||||
*/
|
|
||||||
getShapeType: function() {
|
|
||||||
return this.shapeType;
|
|
||||||
},
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
Kinetic.Node.prototype.destroy.call(this);
|
Kinetic.Node.prototype.destroy.call(this);
|
||||||
delete Kinetic.Global.shapes[this.colorKey];
|
delete Kinetic.Global.shapes[this.colorKey];
|
||||||
|
@ -187,7 +187,7 @@
|
|||||||
_initTag: function(config) {
|
_initTag: function(config) {
|
||||||
this.createAttrs();
|
this.createAttrs();
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Tag';
|
this.className = 'Tag';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Path';
|
this.className = 'Path';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
|
|
||||||
this.dataArray = Kinetic.Path.parsePathData(this.getData());
|
this.dataArray = Kinetic.Path.parsePathData(this.getData());
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'RegularPolygon';
|
this.className = 'RegularPolygon';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Star';
|
this.className = 'Star';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
this._fillFunc = _fillFunc;
|
this._fillFunc = _fillFunc;
|
||||||
this._strokeFunc = _strokeFunc;
|
this._strokeFunc = _strokeFunc;
|
||||||
|
|
||||||
this.shapeType = 'TextPath';
|
this.className = 'TextPath';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
|
|
||||||
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
|
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
_initBlob: function(config) {
|
_initBlob: function(config) {
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Spline.call(this, config);
|
Kinetic.Spline.call(this, config);
|
||||||
this.shapeType = 'Blob';
|
this.className = 'Blob';
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();
|
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
this.createAttrs();
|
this.createAttrs();
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Circle';
|
this.className = 'Circle';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = IMAGE;
|
this.className = IMAGE;
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Line';
|
this.className = 'Line';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Polygon';
|
this.className = 'Polygon';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
_initRect: function(config) {
|
_initRect: function(config) {
|
||||||
this.createAttrs();
|
this.createAttrs();
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Rect';
|
this.className = 'Rect';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
this.createAttrs();
|
this.createAttrs();
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Line.call(this, config);
|
Kinetic.Line.call(this, config);
|
||||||
this.shapeType = 'Spline';
|
this.className = 'Spline';
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();
|
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Sprite';
|
this.className = 'Sprite';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
|
|
||||||
this.anim = new Kinetic.Animation();
|
this.anim = new Kinetic.Animation();
|
||||||
|
@ -78,10 +78,9 @@
|
|||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
|
|
||||||
this.shapeType = TEXT;
|
|
||||||
this._fillFunc = _fillFunc;
|
this._fillFunc = _fillFunc;
|
||||||
this._strokeFunc = _strokeFunc;
|
this._strokeFunc = _strokeFunc;
|
||||||
this.shapeType = TEXT_UPPER;
|
this.className = TEXT_UPPER;
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
|
|
||||||
// update text data for certain attr changes
|
// update text data for certain attr changes
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
// call super constructor
|
// call super constructor
|
||||||
Kinetic.Shape.call(this, config);
|
Kinetic.Shape.call(this, config);
|
||||||
this.shapeType = 'Wedge';
|
this.className = 'Wedge';
|
||||||
this._setDrawFuncs();
|
this._setDrawFuncs();
|
||||||
},
|
},
|
||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
|
@ -111,9 +111,9 @@ Test.Modules.CONTAINER = {
|
|||||||
|
|
||||||
var node;
|
var node;
|
||||||
node = stage.get('#myCircle')[0];
|
node = stage.get('#myCircle')[0];
|
||||||
test(node.shapeType === 'Circle', 'shape type should be Circle');
|
test(node.className === 'Circle', 'className should be Circle');
|
||||||
node = layer.get('.myRect')[0];
|
node = layer.get('.myRect')[0];
|
||||||
test(node.shapeType === 'Rect', 'shape type should be rect');
|
test(node.className === 'Rect', 'className should be rect');
|
||||||
node = layer.get('#myLayer')[0];
|
node = layer.get('#myLayer')[0];
|
||||||
test(node === undefined, 'node should be undefined');
|
test(node === undefined, 'node should be undefined');
|
||||||
node = stage.get('#myLayer')[0];
|
node = stage.get('#myLayer')[0];
|
||||||
|
@ -46,7 +46,7 @@ Test.Modules.PATH = {
|
|||||||
|
|
||||||
path.setData('M200,100h100v50z');
|
path.setData('M200,100h100v50z');
|
||||||
|
|
||||||
test(path.getShapeType() === 'Path', 'shape type should be Path');
|
test(path.getClassName() === 'Path', 'getClassName should be Path');
|
||||||
|
|
||||||
},
|
},
|
||||||
'add path with line cap and line join': function(containerId) {
|
'add path with line cap and line join': function(containerId) {
|
||||||
|
@ -25,7 +25,7 @@ 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');
|
test(poly.getClassName() === 'RegularPolygon', 'sgetClassName should be RegularPolygon');
|
||||||
|
|
||||||
},
|
},
|
||||||
'add regular polygon square': function(containerId) {
|
'add regular polygon square': function(containerId) {
|
||||||
|
@ -30,7 +30,7 @@ Test.Modules.STAR = {
|
|||||||
layer.add(star);
|
layer.add(star);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(star.getShapeType() === 'Star', 'shape type should be Star');
|
test(star.getClassName() === 'Star', 'getClassName 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({
|
||||||
|
@ -34,7 +34,7 @@ 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');
|
test(textpath.getClassName() === 'TextPath', 'getClassName 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,7 +60,7 @@ 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');
|
test(blob1.getClassName() === 'Blob', 'getClassName should be Blob');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ 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');
|
test(circle.getClassName() === 'Circle', 'getClassName 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();
|
||||||
|
@ -118,7 +118,7 @@ Test.Modules.IMAGE = {
|
|||||||
|
|
||||||
//document.body.appendChild(layer.bufferCanvas.element)
|
//document.body.appendChild(layer.bufferCanvas.element)
|
||||||
|
|
||||||
test(darth.getShapeType() === 'Image', 'shape type should be Image');
|
test(darth.getClassName() === 'Image', 'getClassName should be Image');
|
||||||
|
|
||||||
};
|
};
|
||||||
imageObj.src = '../assets/darth-vader.jpg';
|
imageObj.src = '../assets/darth-vader.jpg';
|
||||||
|
@ -47,7 +47,7 @@ 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');
|
test(line.getClassName() === 'Line', 'getClassName should be Line');
|
||||||
},
|
},
|
||||||
'test default ponts array for two lines': function(containerId) {
|
'test default ponts array for two lines': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -37,7 +37,7 @@ Test.Modules.POLYGON - {
|
|||||||
layer.add(poly);
|
layer.add(poly);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(poly.getShapeType() === 'Polygon', 'shape type should be Polygon');
|
test(poly.getClassName() === 'Polygon', 'getClassName should be Polygon');
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ Test.Modules.RECT = {
|
|||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(rect.getShapeType() === 'Rect', 'shape type should be Rect');
|
test(rect.getClassName() === 'Rect', 'className should be Rect');
|
||||||
},
|
},
|
||||||
'add stroke rect': function(containerId) {
|
'add stroke rect': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
@ -79,7 +79,7 @@ Test.Modules.SPLINE = {
|
|||||||
//console.log(layer.toDataURL());
|
//console.log(layer.toDataURL());
|
||||||
testDataUrl(layer.toDataURL(), 'curvy lines', 'problem with curvy lines');
|
testDataUrl(layer.toDataURL(), 'curvy lines', 'problem with curvy lines');
|
||||||
|
|
||||||
test(line1.getShapeType() === 'Spline', 'shape type should be Spline');
|
test(line1.getClassName() === 'Spline', 'getClassName should be Spline');
|
||||||
|
|
||||||
},
|
},
|
||||||
'create from points represented as a flat array': function(containerId) {
|
'create from points represented as a flat array': function(containerId) {
|
||||||
|
@ -112,7 +112,7 @@ Test.Modules.SPRITE = {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
//document.body.appendChild(layer.bufferCanvas.element)
|
//document.body.appendChild(layer.bufferCanvas.element)
|
||||||
|
|
||||||
test(sprite.getShapeType() === 'Sprite', 'shape type should be Sprite');
|
test(sprite.getClassName() === 'Sprite', 'getClassName should be Sprite');
|
||||||
|
|
||||||
test(sprite.getIndex() === 0, 'sprite index should default to 0');
|
test(sprite.getIndex() === 0, 'sprite index should default to 0');
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ Test.Modules.Text = {
|
|||||||
layer.add(group);
|
layer.add(group);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(text.getShapeType() === 'Text', 'shape type should be Text');
|
test(text.getClassName() === 'Text', 'getClassName 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({
|
||||||
|
@ -24,7 +24,7 @@ Test.Modules.Wedge = {
|
|||||||
//console.log(layer.toDataURL());
|
//console.log(layer.toDataURL());
|
||||||
testDataUrl(layer.toDataURL(), 'wedge', 'problem rendering wedge');
|
testDataUrl(layer.toDataURL(), 'wedge', 'problem rendering wedge');
|
||||||
|
|
||||||
test(wedge.getShapeType() === 'Wedge', 'shape type should be Wedge');
|
test(wedge.getClassName() === 'Wedge', 'getClassName 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