first pass at removing setDefaultAttrs logic to speed up node instantation performance

This commit is contained in:
Eric Rowell
2013-03-15 08:33:05 -07:00
parent 5c590bb88f
commit 69f9374c8e
28 changed files with 250 additions and 333 deletions

View File

@@ -242,7 +242,7 @@
Kinetic.Global.extend(Kinetic.Container, Kinetic.Node); Kinetic.Global.extend(Kinetic.Container, Kinetic.Node);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Container, ['clipFunc']); Kinetic.Node.addGetterSetter(Kinetic.Container, 'clipFunc');
/** /**
* set clipping function * set clipping function

View File

@@ -148,14 +148,7 @@
this.setAttr('draggable', draggable); this.setAttr('draggable', draggable);
this._dragChange(); this._dragChange();
}; };
/**
* get draggable
* @name getDraggable
* @methodOf Kinetic.Node.prototype
*/
Kinetic.Node.prototype.getDraggable = function() {
return this.attrs.draggable;
};
/** /**
* determine if node is currently in drag and drop mode * determine if node is currently in drag and drop mode
* @name isDragging * @name isDragging
@@ -200,14 +193,11 @@
this.off('mousedown.kinetic'); this.off('mousedown.kinetic');
this.off('touchstart.kinetic'); this.off('touchstart.kinetic');
}; };
/**
* get draggable. Alias of getDraggable()
* @name isDraggable
* @methodOf Kinetic.Node.prototype
*/
Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
Kinetic.Node.addGettersSetters(Kinetic.Node, ['dragBoundFunc', 'dragOnTop']); Kinetic.Node.addGetterSetter(Kinetic.Node, 'dragBoundFunc');
Kinetic.Node.addGetterSetter(Kinetic.Node, 'dragOnTop', true);
Kinetic.Node.addGetter(Kinetic.Node, 'draggable', false);
/** /**
* set drag bound function. This is used to override the default * set drag bound function. This is used to override the default
@@ -237,7 +227,20 @@
* @name getDragOnTop * @name getDragOnTop
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
/**
* get draggable
* @name getDraggable
* @methodOf Kinetic.Node.prototype
*/
/**
* get draggable. Alias of getDraggable()
* @name isDraggable
* @methodOf Kinetic.Node.prototype
*/
Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
// listen for capturing phase so that the _endDrag method is // listen for capturing phase so that the _endDrag method is
// called before the stage mouseup event is triggered in order // called before the stage mouseup event is triggered in order
// to render the hit graph just in time to pick up the event // to render the hit graph just in time to pick up the event

View File

@@ -14,7 +14,7 @@
Kinetic.Group.prototype = { Kinetic.Group.prototype = {
_initGroup: function(config) { _initGroup: function(config) {
this.nodeType = 'Group'; this.nodeType = 'Group';
this.createAttrs();
// call super constructor // call super constructor
Kinetic.Container.call(this, config); Kinetic.Container.call(this, config);
} }

View File

@@ -16,10 +16,6 @@
Kinetic.Layer.prototype = { Kinetic.Layer.prototype = {
_initLayer: function(config) { _initLayer: function(config) {
this.setDefaultAttrs({
clearBeforeDraw: true
});
this.nodeType = 'Layer'; this.nodeType = 'Layer';
this.beforeDrawFunc = undefined; this.beforeDrawFunc = undefined;
this.afterDrawFunc = undefined; this.afterDrawFunc = undefined;
@@ -27,6 +23,7 @@
this.canvas.getElement().style.position = 'absolute'; this.canvas.getElement().style.position = 'absolute';
this.hitCanvas = new Kinetic.HitCanvas(); this.hitCanvas = new Kinetic.HitCanvas();
this.createAttrs();
// call super constructor // call super constructor
Kinetic.Container.call(this, config); Kinetic.Container.call(this, config);
}, },
@@ -70,14 +67,18 @@
*/ */
drawScene: function(canvas) { drawScene: function(canvas) {
canvas = canvas || this.getCanvas(); canvas = canvas || this.getCanvas();
if(this.attrs.clearBeforeDraw) { if(this.getClearBeforeDraw()) {
canvas.clear(); canvas.clear();
} }
Kinetic.Container.prototype.drawScene.call(this, canvas); Kinetic.Container.prototype.drawScene.call(this, canvas);
}, },
toDataURL: function(config) { toDataURL: function(config) {
config = config || {}; config = config || {};
var mimeType = config.mimeType || null, quality = config.quality || null, canvas, context, x = config.x || 0, y = config.y || 0; var mimeType = config.mimeType || null,
quality = config.quality || null,
canvas, context,
x = config.x || 0,
y = config.y || 0;
// if dimension or position is defined, use Node toDataURL // if dimension or position is defined, use Node toDataURL
if(config.width || config.height || config.x || config.y) { if(config.width || config.height || config.x || config.y) {
@@ -87,6 +88,7 @@
else { else {
return this.getCanvas().toDataURL(mimeType, quality); return this.getCanvas().toDataURL(mimeType, quality);
} }
}, },
/** /**
* set before draw handler * set before draw handler
@@ -217,7 +219,7 @@
Kinetic.Global.extend(Kinetic.Layer, Kinetic.Container); Kinetic.Global.extend(Kinetic.Layer, Kinetic.Container);
// add getters and setters // add getters and setters
Kinetic.Node.addGettersSetters(Kinetic.Layer, ['clearBeforeDraw']); Kinetic.Node.addGetterSetter(Kinetic.Layer, 'clearBeforeDraw', true);
/** /**
* set flag which determines if the layer is cleared or not * set flag which determines if the layer is cleared or not

View File

@@ -13,28 +13,6 @@
Kinetic.Node.prototype = { Kinetic.Node.prototype = {
_nodeInit: function(config) { _nodeInit: function(config) {
this._id = Kinetic.Global.idCounter++; this._id = Kinetic.Global.idCounter++;
this.defaultNodeAttrs = {
visible: true,
listening: true,
name: undefined,
opacity: 1,
x: 0,
y: 0,
scale: {
x: 1,
y: 1
},
rotation: 0,
offset: {
x: 0,
y: 0
},
draggable: false,
dragOnTop: true
};
this.setDefaultAttrs(this.defaultNodeAttrs);
this.eventListeners = {}; this.eventListeners = {};
this.setAttrs(config); this.setAttrs(config);
}, },
@@ -91,7 +69,6 @@
var len = types.length; var len = types.length;
for(var n = 0; n < len; n++) { for(var n = 0; n < len; n++) {
var type = types[n]; var type = types[n];
//var event = (type.indexOf('touch') === -1) ? 'on' + type : type;
var event = type; var event = type;
var parts = event.split('.'); var parts = event.split('.');
var baseEvent = parts[0]; var baseEvent = parts[0];
@@ -155,42 +132,33 @@
this.remove(); this.remove();
}, },
/**
* get attr
* @name getAttr
* @methodOf Kinetic.Node.prototype
*/
getAttr: function(attr) {
var method = 'get' + attr.charAt(0).toUpperCase() + attr.slice(1);
return method();
},
/** /**
* get attrs * get attrs
* @name getAttrs * @name getAttrs
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
getAttrs: function() { getAttrs: function() {
return this.attrs; return this.attrs || {};
}, },
/** /**
* set default attrs. This method should only be used if * @name createAttrs
* you're creating a custom node
* @name setDefaultAttrs
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
* @param {Object} confic
*/ */
setDefaultAttrs: function(config) { createAttrs: function() {
// create attrs object if undefined
if(this.attrs === undefined) { if(this.attrs === undefined) {
this.attrs = {}; this.attrs = {};
} }
if(config) {
for(var key in config) {
/*
* only set the attr if it's undefined in case
* a developer writes a custom class that extends
* a Kinetic Class such that their default property
* isn't overwritten by the Kinetic Class default
* property
*/
if(this.attrs[key] === undefined) {
this.attrs[key] = config[key];
}
}
}
}, },
/** /**
* set attrs * set attrs
* @name setAttrs * @name setAttrs
@@ -220,7 +188,14 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
getVisible: function() { getVisible: function() {
var visible = this.attrs.visible, parent = this.getParent(); var visible = this.attrs.visible,
parent = this.getParent();
// default
if (visible === undefined) {
visible = true;
}
if(visible && parent && !parent.getVisible()) { if(visible && parent && !parent.getVisible()) {
return false; return false;
} }
@@ -234,7 +209,14 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
getListening: function() { getListening: function() {
var listening = this.attrs.listening, parent = this.getParent(); var listening = this.attrs.listening,
parent = this.getParent();
// default
if (listening === undefined) {
listening = true;
}
if(listening && parent && !parent.getListening()) { if(listening && parent && !parent.getListening()) {
return false; return false;
} }
@@ -262,7 +244,7 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
getZIndex: function() { getZIndex: function() {
return this.index; return this.index || 0;
}, },
/** /**
* get absolute z-index which takes into account sibling * get absolute z-index which takes into account sibling
@@ -335,10 +317,9 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
getPosition: function() { getPosition: function() {
var attrs = this.attrs;
return { return {
x: attrs.x, x: this.getX(),
y: attrs.y y: this.getY()
}; };
}, },
/** /**
@@ -630,14 +611,13 @@
*/ */
getTransform: function() { getTransform: function() {
var m = new Kinetic.Transform(), var m = new Kinetic.Transform(),
attrs = this.attrs, x = this.getX(),
x = attrs.x, y = this.getY(),
y = attrs.y, rotation = this.getRotation(),
rotation = attrs.rotation, scale = this.getScale(),
scale = attrs.scale,
scaleX = scale.x, scaleX = scale.x,
scaleY = scale.y, scaleY = scale.y,
offset = attrs.offset, offset = this.getOffset(),
offsetX = offset.x, offsetX = offset.x,
offsetY = offset.y; offsetY = offset.y;
@@ -811,13 +791,12 @@
} }
}, },
_clearTransform: function() { _clearTransform: function() {
var attrs = this.attrs, var scale = this.getScale(),
scale = attrs.scale, offset = this.getOffset(),
offset = attrs.offset,
trans = { trans = {
x: attrs.x, x: this.getX(),
y: attrs.y, y: this.getY(),
rotation: attrs.rotation, rotation: this.getRotation(),
scale: { scale: {
x: scale.x, x: scale.x,
y: scale.y y: scale.y
@@ -932,65 +911,37 @@
}; };
// add getter and setter methods // add getter and setter methods
Kinetic.Node.addSetters = function(constructor, arr) {
var len = arr.length; Kinetic.Node.addGetterSetter = function(constructor, arr, def) {
for(var n = 0; n < len; n++) { this.addGetter(constructor, arr, def);
var attr = arr[n]; this.addSetter(constructor, arr);
this._addSetter(constructor, attr);
}
}; };
Kinetic.Node.addPointSetters = function(constructor, arr) { Kinetic.Node.addPointGetterSetter = function(constructor, arr, def) {
var len = arr.length; this.addGetter(constructor, arr, def);
for(var n = 0; n < len; n++) { this.addPointSetter(constructor, arr);
var attr = arr[n];
this._addPointSetter(constructor, attr);
}
}; };
Kinetic.Node.addRotationSetters = function(constructor, arr) { Kinetic.Node.addRotationGetterSetter = function(constructor, arr, def) {
var len = arr.length; this.addRotationGetter(constructor, arr, def);
for(var n = 0; n < len; n++) { this.addRotationSetter(constructor, arr);
var attr = arr[n];
this._addRotationSetter(constructor, attr);
}
}; };
Kinetic.Node.addGetters = function(constructor, arr) { Kinetic.Node.addSetter = function(constructor, attr) {
var len = arr.length;
for(var n = 0; n < len; n++) {
var attr = arr[n];
this._addGetter(constructor, attr);
}
};
Kinetic.Node.addRotationGetters = function(constructor, arr) {
var len = arr.length;
for(var n = 0; n < len; n++) {
var attr = arr[n];
this._addRotationGetter(constructor, attr);
}
};
Kinetic.Node.addGettersSetters = function(constructor, arr) {
this.addSetters(constructor, arr);
this.addGetters(constructor, arr);
};
Kinetic.Node.addPointGettersSetters = function(constructor, arr) {
this.addPointSetters(constructor, arr);
this.addGetters(constructor, arr);
};
Kinetic.Node.addRotationGettersSetters = function(constructor, arr) {
this.addRotationSetters(constructor, arr);
this.addRotationGetters(constructor, arr);
};
Kinetic.Node._addSetter = function(constructor, attr) {
var that = this; var that = this;
var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1);
constructor.prototype[method] = function(val) { constructor.prototype[method] = function(val) {
this.setAttr(attr, val); this.setAttr(attr, val);
}; };
}; };
Kinetic.Node._addPointSetter = function(constructor, attr) { Kinetic.Node.addPointSetter = function(constructor, attr) {
var that = this; var that = this;
var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1);
constructor.prototype[method] = function() { constructor.prototype[method] = function() {
var pos = Kinetic.Type._getXY([].slice.call(arguments)); var pos = Kinetic.Type._getXY([].slice.call(arguments));
// default
if (!this.attrs[attr]) {
this.attrs[attr] = {x:1,y:1};
}
if(pos && pos.x === undefined) { if(pos && pos.x === undefined) {
pos.x = this.attrs[attr].x; pos.x = this.attrs[attr].x;
} }
@@ -1000,7 +951,7 @@
this.setAttr(attr, pos); this.setAttr(attr, pos);
}; };
}; };
Kinetic.Node._addRotationSetter = function(constructor, attr) { Kinetic.Node.addRotationSetter = function(constructor, attr) {
var that = this; var that = this;
var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1);
// radians // radians
@@ -1012,23 +963,35 @@
this.setAttr(attr, Kinetic.Type._degToRad(deg)); this.setAttr(attr, Kinetic.Type._degToRad(deg));
}; };
}; };
Kinetic.Node._addGetter = function(constructor, attr) { Kinetic.Node.addGetter = function(constructor, attr, def) {
var that = this; var that = this;
var method = 'get' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'get' + attr.charAt(0).toUpperCase() + attr.slice(1);
constructor.prototype[method] = function(arg) { constructor.prototype[method] = function(arg) {
return this.attrs[attr]; var val = this.attrs[attr];
if (val === undefined) {
val = def;
}
return val;
}; };
}; };
Kinetic.Node._addRotationGetter = function(constructor, attr) { Kinetic.Node.addRotationGetter = function(constructor, attr, def) {
var that = this; var that = this;
var method = 'get' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'get' + attr.charAt(0).toUpperCase() + attr.slice(1);
// radians // radians
constructor.prototype[method] = function() { constructor.prototype[method] = function() {
return this.attrs[attr]; var val = this.attrs[attr];
if (val === undefined) {
val = def;
}
return val;
}; };
// degrees // degrees
constructor.prototype[method + 'Deg'] = function() { constructor.prototype[method + 'Deg'] = function() {
return Kinetic.Type._radToDeg(this.attrs[attr]) var val = this.attrs[attr];
if (val === undefined) {
val = def;
}
return Kinetic.Type._radToDeg(val);
}; };
}; };
/** /**
@@ -1081,7 +1044,9 @@
return no; return no;
}; };
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Node, ['x', 'y', 'opacity']); Kinetic.Node.addGetterSetter(Kinetic.Node, 'x', 0);
Kinetic.Node.addGetterSetter(Kinetic.Node, 'y', 0);
Kinetic.Node.addGetterSetter(Kinetic.Node, 'opacity', 1);
/** /**
* set x position * set x position
@@ -1124,7 +1089,8 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
Kinetic.Node.addGetters(Kinetic.Node, ['name', 'id']); Kinetic.Node.addGetter(Kinetic.Node, 'name');
Kinetic.Node.addGetter(Kinetic.Node, 'id');
/** /**
* get name * get name
@@ -1138,7 +1104,7 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
Kinetic.Node.addRotationGettersSetters(Kinetic.Node, ['rotation']); Kinetic.Node.addRotationGetterSetter(Kinetic.Node, 'rotation', 0);
/** /**
* set rotation in radians * set rotation in radians
@@ -1166,7 +1132,8 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
Kinetic.Node.addPointGettersSetters(Kinetic.Node, ['scale', 'offset']); Kinetic.Node.addPointGetterSetter(Kinetic.Node, 'scale', {x:1,y:1});
Kinetic.Node.addPointGetterSetter(Kinetic.Node, 'offset', {x:0,y:0});
/** /**
* set scale * set scale
@@ -1196,7 +1163,10 @@
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
*/ */
Kinetic.Node.addSetters(Kinetic.Node, ['width', 'height', 'listening', 'visible']); Kinetic.Node.addSetter(Kinetic.Node, 'width');
Kinetic.Node.addSetter(Kinetic.Node, 'height');
Kinetic.Node.addSetter(Kinetic.Node, 'listening');
Kinetic.Node.addSetter(Kinetic.Node, 'visible');
/** /**
* set width * set width

View File

@@ -26,15 +26,6 @@
Kinetic.Shape.prototype = { Kinetic.Shape.prototype = {
_initShape: function(config) { _initShape: function(config) {
this.setDefaultAttrs({
fillEnabled: true,
strokeEnabled: true,
shadowEnabled: true,
dashArrayEnabled: true,
fillPriority: 'color',
strokeScaleEnabled: true
});
this.nodeType = 'Shape'; this.nodeType = 'Shape';
this._fillFunc = _fillFunc; this._fillFunc = _fillFunc;
this._strokeFunc = _strokeFunc; this._strokeFunc = _strokeFunc;
@@ -55,6 +46,7 @@
this.colorKey = key; this.colorKey = key;
shapes[key] = this; shapes[key] = this;
this.createAttrs();
// call super constructor // call super constructor
Kinetic.Node.call(this, config); Kinetic.Node.call(this, config);
}, },
@@ -211,7 +203,31 @@
Kinetic.Global.extend(Kinetic.Shape, Kinetic.Node); Kinetic.Global.extend(Kinetic.Shape, Kinetic.Node);
// add getters and setters // add getters and setters
Kinetic.Node.addGettersSetters(Kinetic.Shape, ['stroke', 'lineJoin', 'lineCap', 'strokeWidth', 'drawFunc', 'drawHitFunc', 'dashArray', 'shadowColor', 'shadowBlur', 'shadowOpacity', 'fillPatternImage', 'fill', 'fillPatternX', 'fillPatternY', 'fillLinearGradientColorStops', 'fillRadialGradientStartRadius', 'fillRadialGradientEndRadius', 'fillRadialGradientColorStops', 'fillPatternRepeat', 'fillEnabled', 'strokeEnabled', 'shadowEnabled', 'dashArrayEnabled', 'fillPriority', 'strokeScaleEnabled']); Kinetic.Node.addGetterSetter(Kinetic.Shape, 'stroke');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'lineJoin');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'lineCap');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'strokeWidth');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'drawFunc');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'drawHitFunc');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'dashArray');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'shadowColor');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'shadowBlur');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'shadowOpacity');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillPatternImage');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fill');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillPatternX');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillPatternY');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillLinearGradientColorStops');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillRadialGradientStartRadius');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillRadialGradientEndRadius');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillRadialGradientColorStops');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillPatternRepeat');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillEnabled', true);
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'strokeEnabled', true);
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'shadowEnabled', true);
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'dashArrayEnabled', true);
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'fillPriority', 'color');
Kinetic.Node.addGetterSetter(Kinetic.Shape, 'strokeScaleEnabled', true);
/** /**
* set stroke color * set stroke color
@@ -482,7 +498,13 @@
* @methodOf Kinetic.Shape.prototype * @methodOf Kinetic.Shape.prototype
*/ */
Kinetic.Node.addPointGettersSetters(Kinetic.Shape, ['fillPatternOffset', 'fillPatternScale', 'fillLinearGradientStartPoint', 'fillLinearGradientEndPoint', 'fillRadialGradientStartPoint', 'fillRadialGradientEndPoint', 'shadowOffset']); Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillPatternOffset');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillPatternScale');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillLinearGradientStartPoint');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillLinearGradientEndPoint');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillRadialGradientStartPoint');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'fillRadialGradientEndPoint');
Kinetic.Node.addPointGetterSetter(Kinetic.Shape, 'shadowOffset');
/** /**
* set fill pattern offset * set fill pattern offset
@@ -575,7 +597,7 @@
* @methodOf Kinetic.Shape.prototype * @methodOf Kinetic.Shape.prototype
*/ */
Kinetic.Node.addRotationGettersSetters(Kinetic.Shape, ['fillPatternRotation']); Kinetic.Node.addRotationGetterSetter(Kinetic.Shape, 'fillPatternRotation', 0);
/** /**
* set fill pattern rotation in radians * set fill pattern rotation in radians

View File

@@ -14,15 +14,11 @@
Kinetic.Stage.prototype = { Kinetic.Stage.prototype = {
_initStage: function(config) { _initStage: function(config) {
var dd = Kinetic.DD; var dd = Kinetic.DD;
this.setDefaultAttrs({
width: 400, this.createAttrs();
height: 200
});
// call super constructor // call super constructor
Kinetic.Container.call(this, config); Kinetic.Container.call(this, config);
this._setStageDefaultProperties(); this._setStageDefaultProperties();
this._id = Kinetic.Global.idCounter++; this._id = Kinetic.Global.idCounter++;
this._buildDOM(); this._buildDOM();
@@ -103,19 +99,6 @@
this.attrs.container.removeChild(content); this.attrs.container.removeChild(content);
} }
}, },
/**
* reset stage to default state
* @name reset
* @methodOf Kinetic.Stage.prototype
*/
reset: function() {
// remove children
this.removeChildren();
// defaults
this._setStageDefaultProperties();
this.setAttrs(this.defaultNodeAttrs);
},
/** /**
* get mouse position for desktop apps * get mouse position for desktop apps
* @name getMousePosition * @name getMousePosition
@@ -170,7 +153,13 @@
*/ */
toDataURL: function(config) { toDataURL: function(config) {
config = config || {}; config = config || {};
var mimeType = config.mimeType || null, quality = config.quality || null, x = config.x || 0, y = config.y || 0, canvas = new Kinetic.SceneCanvas(config.width || this.getWidth(), config.height || this.getHeight()), context = canvas.getContext(), layers = this.children; var mimeType = config.mimeType || null,
quality = config.quality || null,
x = config.x || 0,
y = config.y || 0,
canvas = new Kinetic.SceneCanvas(config.width || this.getWidth(), config.height || this.getHeight()),
context = canvas.getContext(),
layers = this.children;
if(x || y) { if(x || y) {
context.translate(-1 * x, -1 * y); context.translate(-1 * x, -1 * y);
@@ -568,7 +557,7 @@
Kinetic.Global.extend(Kinetic.Stage, Kinetic.Container); Kinetic.Global.extend(Kinetic.Stage, Kinetic.Container);
// add getters and setters // add getters and setters
Kinetic.Node.addGetters(Kinetic.Stage, ['container']); Kinetic.Node.addGetter(Kinetic.Stage, 'container');
/** /**
* get container DOM element * get container DOM element

View File

@@ -15,10 +15,7 @@
Kinetic.Plugins.RegularPolygon.prototype = { Kinetic.Plugins.RegularPolygon.prototype = {
_initRegularPolygon: function(config) { _initRegularPolygon: function(config) {
this.setDefaultAttrs({ this.createAttrs();
radius: 0,
sides: 0
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -42,7 +39,8 @@
Kinetic.Global.extend(Kinetic.Plugins.RegularPolygon, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Plugins.RegularPolygon, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Plugins.RegularPolygon, ['radius', 'sides']); Kinetic.Node.addGetterSetter(Kinetic.Plugins.RegularPolygon, 'radius', 0);
Kinetic.Node.addGetterSetter(Kinetic.Plugins.RegularPolygon, 'sides', 0);
/** /**
* set radius * set radius

View File

@@ -16,11 +16,7 @@
Kinetic.Plugins.Star.prototype = { Kinetic.Plugins.Star.prototype = {
_initStar: function(config) { _initStar: function(config) {
this.setDefaultAttrs({ this.createAttrs();
numPoints: 0,
innerRadius: 0,
outerRadius: 0
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -47,7 +43,9 @@
Kinetic.Global.extend(Kinetic.Plugins.Star, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Plugins.Star, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Plugins.Star, ['numPoints', 'innerRadius', 'outerRadius']); Kinetic.Node.addGetterSetter(Kinetic.Plugins.Star, 'numPoints', 0);
Kinetic.Node.addGetterSetter(Kinetic.Plugins.Star, 'innerRadius', 0);
Kinetic.Node.addGetterSetter(Kinetic.Plugins.Star, 'outerRadius', 0);
/** /**
* set number of points * set number of points

View File

@@ -1,4 +1,8 @@
(function() { (function() {
var EMPTY_STRING = '',
CALIBRI = 'Calibri',
NORMAL = 'normal';
/** /**
* Path constructor. * Path constructor.
* @author Jason Follas * @author Jason Follas
@@ -25,13 +29,7 @@
Kinetic.Plugins.TextPath.prototype = { Kinetic.Plugins.TextPath.prototype = {
_initTextPath: function(config) { _initTextPath: function(config) {
this.setDefaultAttrs({ this.createAttrs();
fontFamily: 'Calibri',
fontSize: 12,
fontStyle: 'normal',
text: ''
});
this.dummyCanvas = document.createElement('canvas'); this.dummyCanvas = document.createElement('canvas');
this.dataArray = []; this.dataArray = [];
var that = this; var that = this;
@@ -307,8 +305,11 @@
Kinetic.Global.extend(Kinetic.Plugins.TextPath, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Plugins.TextPath, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.Node.addGettersSetters(Kinetic.Plugins.TextPath, ['fontFamily', 'fontSize', 'fontStyle']); Kinetic.Node.addGetterSetter(Kinetic.Plugins.TextPath, 'fontFamily', CALIBRI);
Kinetic.Node.addGetters(Kinetic.Plugins.TextPath, ['text']); Kinetic.Node.addGetterSetter(Kinetic.Plugins.TextPath, 'fontSize', 12);
Kinetic.Node.addGetterSetter(Kinetic.Plugins.TextPath, 'fontStyle', NORMAL);
Kinetic.Node.addGetter(Kinetic.Plugins.TextPath, 'text', EMPTY_STRING);
/** /**
* set font family * set font family

View File

@@ -14,17 +14,14 @@
Kinetic.Circle.prototype = { Kinetic.Circle.prototype = {
_initCircle: function(config) { _initCircle: function(config) {
this.setDefaultAttrs({ this.createAttrs();
radius: 0
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
this.shapeType = 'Circle'; this.shapeType = 'Circle';
this._setDrawFuncs(); this._setDrawFuncs();
}, },
drawFunc: function(canvas) { drawFunc: function(canvas) {
var context = canvas.getContext(); var context = canvas.getContext();
context.beginPath(); context.beginPath();
context.arc(0, 0, this.getRadius(), 0, Math.PI * 2, true); context.arc(0, 0, this.getRadius(), 0, Math.PI * 2, true);
context.closePath(); context.closePath();
@@ -48,7 +45,7 @@
Kinetic.Global.extend(Kinetic.Circle, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Circle, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Circle, ['radius']); Kinetic.Node.addGetterSetter(Kinetic.Circle, 'radius', 0);
/** /**
* set radius * set radius

View File

@@ -14,12 +14,7 @@
Kinetic.Ellipse.prototype = { Kinetic.Ellipse.prototype = {
_initEllipse: function(config) { _initEllipse: function(config) {
this.setDefaultAttrs({ this.createAttrs();
radius: {
x: 0,
y: 0
}
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -60,7 +55,7 @@
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addPointGettersSetters(Kinetic.Ellipse, ['radius']); Kinetic.Node.addPointGetterSetter(Kinetic.Ellipse, 'radius', {x:0,y:0});
/** /**
* set radius * set radius

View File

@@ -191,8 +191,8 @@
Kinetic.Global.extend(Kinetic.Image, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Image, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Image, ['image']); Kinetic.Node.addGetterSetter(Kinetic.Image, 'image');
Kinetic.Node.addGetters(Kinetic.Image, ['crop']); Kinetic.Node.addGetter(Kinetic.Image, 'crop');
/** /**
* set image * set image

View File

@@ -15,10 +15,7 @@
Kinetic.Line.prototype = { Kinetic.Line.prototype = {
_initLine: function(config) { _initLine: function(config) {
this.setDefaultAttrs({ this.createAttrs();
points: [],
lineCap: 'butt'
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -51,7 +48,7 @@
Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGetters(Kinetic.Line, ['points']); Kinetic.Node.addGetter(Kinetic.Line, 'points', []);
/** /**
* get points array * get points array

View File

@@ -543,7 +543,7 @@
return [cx, cy, rx, ry, theta, dTheta, psi, fs]; return [cx, cy, rx, ry, theta, dTheta, psi, fs];
}; };
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Path, ['data']); Kinetic.Node.addGetterSetter(Kinetic.Path, 'data');
/** /**
* set SVG path data string. This method * set SVG path data string. This method

View File

@@ -15,9 +15,7 @@
Kinetic.Polygon.prototype = { Kinetic.Polygon.prototype = {
_initPolygon: function(config) { _initPolygon: function(config) {
this.setDefaultAttrs({ this.createAttrs();
points: []
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -48,7 +46,7 @@
Kinetic.Global.extend(Kinetic.Polygon, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Polygon, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGetters(Kinetic.Polygon, ['points']); Kinetic.Node.addGetter(Kinetic.Polygon, 'points', []);
/** /**
* get points array * get points array

View File

@@ -14,21 +14,20 @@
Kinetic.Rect.prototype = { Kinetic.Rect.prototype = {
_initRect: function(config) { _initRect: function(config) {
this.setDefaultAttrs({ this.createAttrs();
width: 0,
height: 0,
cornerRadius: 0
});
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
this.shapeType = 'Rect'; this.shapeType = 'Rect';
this._setDrawFuncs(); this._setDrawFuncs();
}, },
drawFunc: function(canvas) { drawFunc: function(canvas) {
var context = canvas.getContext(); var context = canvas.getContext(),
cornerRadius = this.getCornerRadius(),
width = this.getWidth(),
height = this.getHeight();
context.beginPath(); context.beginPath();
var cornerRadius = this.getCornerRadius(), width = this.getWidth(), height = this.getHeight();
if(cornerRadius === 0) { if(!cornerRadius) {
// simple rect - don't bother doing all that complicated maths stuff. // simple rect - don't bother doing all that complicated maths stuff.
context.rect(0, 0, width, height); context.rect(0, 0, width, height);
} }
@@ -51,7 +50,7 @@
Kinetic.Global.extend(Kinetic.Rect, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Rect, Kinetic.Shape);
Kinetic.Node.addGettersSetters(Kinetic.Rect, ['cornerRadius']); Kinetic.Node.addGetterSetter(Kinetic.Rect, 'cornerRadius', 0);
/** /**
* set corner radius * set corner radius

View File

@@ -40,10 +40,7 @@
Kinetic.Spline.prototype = { Kinetic.Spline.prototype = {
_initSpline: function(config) { _initSpline: function(config) {
this.setDefaultAttrs({ this.createAttrs();
tension: 1
});
// call super constructor // call super constructor
Kinetic.Line.call(this, config); Kinetic.Line.call(this, config);
this.shapeType = 'Spline'; this.shapeType = 'Spline';
@@ -106,7 +103,7 @@
Kinetic.Global.extend(Kinetic.Spline, Kinetic.Line); Kinetic.Global.extend(Kinetic.Spline, Kinetic.Line);
// add getters setters // add getters setters
Kinetic.Node.addGetters(Kinetic.Spline, ['tension']); Kinetic.Node.addGetter(Kinetic.Spline, 'tension', 1);
/** /**
* get tension * get tension

View File

@@ -16,10 +16,7 @@
Kinetic.Sprite.prototype = { Kinetic.Sprite.prototype = {
_initSprite: function(config) { _initSprite: function(config) {
this.setDefaultAttrs({ this.createAttrs();
index: 0,
frameRate: 17
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -111,7 +108,10 @@
Kinetic.Global.extend(Kinetic.Sprite, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Sprite, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Sprite, ['animation', 'animations', 'index']); Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'animation');
Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'animations');
Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'index', 0);
Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'frameRate', 17);
/** /**
* set animation key * set animation key

View File

@@ -53,24 +53,18 @@
Kinetic.Text.prototype = { Kinetic.Text.prototype = {
_initText: function(config) { _initText: function(config) {
var that = this; var that = this;
this.setDefaultAttrs({
fontFamily: CALIBRI,
text: EMPTY_STRING,
fontSize: 12,
align: LEFT,
verticalAlign: TOP,
fontStyle: NORMAL,
padding: 0,
width: AUTO,
height: AUTO,
lineHeight: 1
});
this.dummyCanvas = document.createElement(CANVAS); this.dummyCanvas = document.createElement(CANVAS);
this.createAttrs();
// since width and height work a bit different for Text,
// we need to default the values here
this.attrs.width = AUTO;
this.attrs.height = AUTO;
// 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.shapeType = TEXT_UPPER;
@@ -158,7 +152,7 @@
* @methodOf Kinetic.Text.prototype * @methodOf Kinetic.Text.prototype
*/ */
getHeight: function() { getHeight: function() {
return this.attrs.height === AUTO ? (this.getTextHeight() * this.textArr.length * this.attrs.lineHeight) + this.attrs.padding * 2 : this.attrs.height; return this.attrs.height === AUTO ? (this.getTextHeight() * this.textArr.length * this.getLineHeight()) + this.attrs.padding * 2 : this.attrs.height;
}, },
/** /**
* get text width * get text width
@@ -280,10 +274,19 @@
} }
}; };
Kinetic.Global.extend(Kinetic.Text, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Text, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'align', 'lineHeight']); Kinetic.Node.addGetterSetter(Kinetic.Text, 'fontFamily', CALIBRI);
Kinetic.Node.addGetters(Kinetic.Text, [TEXT]); Kinetic.Node.addGetterSetter(Kinetic.Text, 'fontSize', 12);
Kinetic.Node.addGetterSetter(Kinetic.Text, 'fontStyle', NORMAL);
Kinetic.Node.addGetterSetter(Kinetic.Text, 'padding', 0);
Kinetic.Node.addGetterSetter(Kinetic.Text, 'align', LEFT);
Kinetic.Node.addGetterSetter(Kinetic.Text, 'lineHeight', 1);
Kinetic.Node.addGetter(Kinetic.Text, TEXT, EMPTY_STRING);
Kinetic.Node.addSetter(Kinetic.Text, 'width');
Kinetic.Node.addSetter(Kinetic.Text, 'height');
/** /**
* set font family * set font family
* @name setFontFamily * @name setFontFamily

View File

@@ -16,11 +16,7 @@
Kinetic.Wedge.prototype = { Kinetic.Wedge.prototype = {
_initWedge: function(config) { _initWedge: function(config) {
this.setDefaultAttrs({ this.createAttrs();
radius: 0,
angle: 0,
clockwise: false
});
// call super constructor // call super constructor
Kinetic.Shape.call(this, config); Kinetic.Shape.call(this, config);
@@ -56,7 +52,9 @@
Kinetic.Global.extend(Kinetic.Wedge, Kinetic.Shape); Kinetic.Global.extend(Kinetic.Wedge, Kinetic.Shape);
// add getters setters // add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Wedge, ['radius', 'angle', 'clockwise']); Kinetic.Node.addGetterSetter(Kinetic.Wedge, 'radius', 0);
Kinetic.Node.addGetterSetter(Kinetic.Wedge, 'angle', 0);
Kinetic.Node.addGetterSetter(Kinetic.Wedge, 'clockwise', false);
/** /**
* set radius * set radius

View File

@@ -400,7 +400,7 @@ Test.Modules.PERFORMANCE = {
anim.start(); anim.start();
}, 4000); }, 4000);
}, },
'DRAWING - draw 10,000 small circles with tooltips': function(containerId) { '*DRAWING - draw 10,000 small circles with tooltips': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,
width: 578, width: 578,
@@ -408,7 +408,7 @@ Test.Modules.PERFORMANCE = {
}); });
var circlesLayer = new Kinetic.Layer(); var circlesLayer = new Kinetic.Layer();
var tooltipLayer = new Kinetic.Layer();
var colors = ["red", "orange", "yellow", "green", "blue", "cyan", "purple"]; var colors = ["red", "orange", "yellow", "green", "blue", "cyan", "purple"];
var colorIndex = 0; var colorIndex = 0;
@@ -425,47 +425,19 @@ Test.Modules.PERFORMANCE = {
var randX = Math.random() * stage.getWidth(); var randX = Math.random() * stage.getWidth();
var randY = Math.random() * stage.getHeight(); var randY = Math.random() * stage.getHeight();
var circle = new Kinetic.Ellipse({ var circle = new Kinetic.Circle({
x: randX, x: randX,
y: randY, y: randY,
radius: 2, radius: 2,
fill: color fill: color
}); });
circle.on("mousemove", function() {
// update tooltip
console.log('mouseover')
var mousePos = stage.getMousePosition();
tooltip.setPosition(mousePos.x + 5, mousePos.y + 5);
tooltip.setText("node: " + i + ", color: " + color);
tooltip.show();
tooltipLayer.draw();
});
circle.on("mouseout", function() {
tooltip.hide();
tooltipLayer.draw();
});
circlesLayer.add(circle); circlesLayer.add(circle);
}()); }());
} }
var tooltip = new Kinetic.Text({
text: "",
fontFamily: "Calibri",
fontSize: 12,
padding: 5,
visible: false,
fill: "black",
alpha: 0.75,
textFill: "white"
});
tooltipLayer.add(tooltip);
stage.add(circlesLayer); stage.add(circlesLayer);
stage.add(tooltipLayer);
endTimer('drew 10,000 circles'); endTimer('drew 10,000 circles');

View File

@@ -855,6 +855,8 @@ Test.Modules.CONTAINER = {
stage.add(greenLayer); stage.add(greenLayer);
blueLayer.setZIndex(1); blueLayer.setZIndex(1);
console.log(greenLayer.getZIndex());
test(greenLayer.getZIndex() === 0, 'green layer should have z index of 0'); test(greenLayer.getZIndex() === 0, 'green layer should have z index of 0');
test(blueLayer.getZIndex() === 1, 'blue layer should have z index of 1'); test(blueLayer.getZIndex() === 1, 'blue layer should have z index of 1');

View File

@@ -21,13 +21,13 @@ Test.Modules.DD = {
layer.draw(); layer.draw();
// test defaults // test defaults
test(circle.attrs.draggable === false, 'draggable should be false'); test(circle.isDraggable() === false, 'draggable should be false');
//change properties //change properties
circle.setDraggable(true); circle.setDraggable(true);
// test new properties // test new properties
test(circle.attrs.draggable === true, 'draggable should be true'); test(circle.getDraggable() === true, 'draggable should be true');
}, },
'DRAG AND DROP - multiple drag and drop sets with setDraggable()': function(containerId) { 'DRAG AND DROP - multiple drag and drop sets with setDraggable()': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({

View File

@@ -852,7 +852,7 @@ Test.Modules.NODE = {
showHit(layer); showHit(layer);
}, },
'hide group': function(containerId) { 'hide group 2': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,
width: 578, width: 578,
@@ -2611,6 +2611,9 @@ Test.Modules.NODE = {
layer.hide(); layer.hide();
layer.draw(); layer.draw();
console.log(layer.toDataURL());
test(layer.toDataURL() === dataUrls['cleared'], 'layer is still visible'); test(layer.toDataURL() === dataUrls['cleared'], 'layer is still visible');
}, },
'hide group': function(containerId) { 'hide group': function(containerId) {

View File

@@ -561,7 +561,7 @@ Test.Modules.SHAPE = {
test(circle.getDashArrayEnabled() === true, 'dashArrayEnabled should be true'); test(circle.getDashArrayEnabled() === true, 'dashArrayEnabled should be true');
circle.disableFill(); circle.disableFill();
test(circle.getFillEnabled() === false, 'fillEnabled should be false'); test(circle.getFillEnabled() === false, 'fillEnabled should be false');
test(circle.getStrokeEnabled() === true, 'strokeEnabled should be true'); test(circle.getStrokeEnabled() === true, 'strokeEnabled should be true');
test(circle.getShadowEnabled() === true, 'shadowEnabled should be true'); test(circle.getShadowEnabled() === true, 'shadowEnabled should be true');

View File

@@ -256,12 +256,16 @@ Test.Modules.Text = {
var width = text.getWidth(); var width = text.getWidth();
var height = text.getHeight(); var height = text.getHeight();
layer.add(text); layer.add(text);
stage.add(layer); stage.add(layer);
text.setFontSize(30); text.setFontSize(30);
layer.draw(); layer.draw();
//console.log(text.getHeight() + ',' + height);
test(text.getWidth() > width, 'text box width should have increased.'); test(text.getWidth() > width, 'text box width should have increased.');
test(text.getHeight() > height, 'text box height should have increased.'); test(text.getHeight() > height, 'text box height should have increased.');

View File

@@ -67,37 +67,6 @@ Test.Modules.STAGE = {
test(layer.getCanvas().element.width === 333, 'layer canvas element width should be 333'); test(layer.getCanvas().element.width === 333, 'layer canvas element width should be 333');
test(layer.getCanvas().element.height === 155, 'layer canvas element width should be 155'); test(layer.getCanvas().element.height === 155, 'layer canvas element width should be 155');
}, },
'reset stage': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200,
x: 100
});
var layer = new Kinetic.Layer();
var group = new Kinetic.Group();
var circle = new Kinetic.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle',
draggable: true
});
stage.add(layer);
layer.add(group);
group.add(circle);
layer.draw();
test(stage.getChildren().length === 1, 'stage should have one child');
test(stage.getX() === 100, 'stage x should be 100');
stage.reset();
test(stage.getChildren().length === 0, 'stage should have no children');
test(stage.getX() === 0, 'stage x should be 0');
},
'get stage DOM': function(containerId) { 'get stage DOM': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,