mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
fixed up unit serialization tests. cleaned up constructor jsdoc comments. fixed Ellipse setRadius method
This commit is contained in:
parent
f235ea032d
commit
759ec116ce
66
dist/kinetic-core.js
vendored
66
dist/kinetic-core.js
vendored
@ -1246,13 +1246,6 @@ requestAnimFrame = (function(callback) {
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
*/
|
*/
|
||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
@ -1277,8 +1270,6 @@ Kinetic.Node.prototype = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
},
|
},
|
||||||
dragConstraint: 'none',
|
|
||||||
dragBounds: {},
|
|
||||||
draggable: false
|
draggable: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2660,13 +2651,7 @@ Kinetic.Global.extend(Kinetic.Container, Kinetic.Node);
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Stage = function(config) {
|
Kinetic.Stage = function(config) {
|
||||||
this._initStage(config);
|
this._initStage(config);
|
||||||
@ -3480,13 +3465,7 @@ Kinetic.Node.addGetters(Kinetic.Stage, ['width', 'height', 'container']);
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Layer = function(config) {
|
Kinetic.Layer = function(config) {
|
||||||
this._initLayer(config);
|
this._initLayer(config);
|
||||||
@ -3745,13 +3724,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Layer, ['clearBeforeDraw']);
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Group = function(config) {
|
Kinetic.Group = function(config) {
|
||||||
this._initGroup(config);
|
this._initGroup(config);
|
||||||
@ -4501,7 +4474,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Circle, ['radius']);
|
|||||||
* @param {Object} config
|
* @param {Object} config
|
||||||
*/
|
*/
|
||||||
Kinetic.Ellipse = function(config) {
|
Kinetic.Ellipse = function(config) {
|
||||||
this._initEllipse(config);
|
this._initEllipse(config);
|
||||||
};
|
};
|
||||||
|
|
||||||
Kinetic.Ellipse.prototype = {
|
Kinetic.Ellipse.prototype = {
|
||||||
@ -4531,25 +4504,28 @@ Kinetic.Ellipse.prototype = {
|
|||||||
context.closePath();
|
context.closePath();
|
||||||
this.fill(context);
|
this.fill(context);
|
||||||
this.stroke(context);
|
this.stroke(context);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* set radius
|
||||||
|
* @name setRadius
|
||||||
|
* @methodOf Kinetic.Ellipse.prototype
|
||||||
|
* @param {Object|Array} radius
|
||||||
|
* radius can be a number, in which the ellipse becomes a circle,
|
||||||
|
* it can be an object with an x and y component, or it
|
||||||
|
* can be an array in which the first element is the x component
|
||||||
|
* and the second element is the y component. The x component
|
||||||
|
* defines the horizontal radius and the y component
|
||||||
|
* defines the vertical radius
|
||||||
|
*/
|
||||||
|
setRadius: function() {
|
||||||
|
var pos = Kinetic.Type._getXY([].slice.call(arguments));
|
||||||
|
this.setAttr('radius', Kinetic.Type._merge(pos, this.getRadius()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
|
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
|
||||||
|
|
||||||
// add getters setters
|
// add getters setters
|
||||||
Kinetic.Node.addGettersSetters(Kinetic.Ellipse, ['radius']);
|
Kinetic.Node.addGetters(Kinetic.Ellipse, ['radius']);
|
||||||
|
|
||||||
/**
|
|
||||||
* set radius
|
|
||||||
* @name setRadius
|
|
||||||
* @methodOf Kinetic.Ellipse.prototype
|
|
||||||
* @param {Object|Array} radius
|
|
||||||
* radius can be a number, in which the ellipse becomes a circle,
|
|
||||||
* it can be an object with an x and y component, or it
|
|
||||||
* can be an array in which the first element is the x component
|
|
||||||
* and the second element is the y component. The x component
|
|
||||||
* defines the horizontal radius and the y component
|
|
||||||
* defines the vertical radius
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get radius
|
* get radius
|
||||||
|
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -22,13 +22,7 @@
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Group = function(config) {
|
Kinetic.Group = function(config) {
|
||||||
this._initGroup(config);
|
this._initGroup(config);
|
||||||
|
@ -25,13 +25,7 @@
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Layer = function(config) {
|
Kinetic.Layer = function(config) {
|
||||||
this._initLayer(config);
|
this._initLayer(config);
|
||||||
|
@ -23,13 +23,6 @@
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
*/
|
*/
|
||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
@ -54,8 +47,6 @@ Kinetic.Node.prototype = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
},
|
},
|
||||||
dragConstraint: 'none',
|
|
||||||
dragBounds: {},
|
|
||||||
draggable: false
|
draggable: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,13 +25,7 @@
|
|||||||
* @param {Number} [config.offset.x]
|
* @param {Number} [config.offset.x]
|
||||||
* @param {Number} [config.offset.y]
|
* @param {Number} [config.offset.y]
|
||||||
* @param {Boolean} [config.draggable]
|
* @param {Boolean} [config.draggable]
|
||||||
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
|
* @param {Function} [config.dragBoundFunc] dragBoundFunc(pos, evt) should return new position
|
||||||
* is none
|
|
||||||
* @param {Object} [config.dragBounds]
|
|
||||||
* @param {Number} [config.dragBounds.top]
|
|
||||||
* @param {Number} [config.dragBounds.right]
|
|
||||||
* @param {Number} [config.dragBounds.bottom]
|
|
||||||
* @param {Number} [config.dragBounds.left]
|
|
||||||
*/
|
*/
|
||||||
Kinetic.Stage = function(config) {
|
Kinetic.Stage = function(config) {
|
||||||
this._initStage(config);
|
this._initStage(config);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* @param {Object} config
|
* @param {Object} config
|
||||||
*/
|
*/
|
||||||
Kinetic.Ellipse = function(config) {
|
Kinetic.Ellipse = function(config) {
|
||||||
this._initEllipse(config);
|
this._initEllipse(config);
|
||||||
};
|
};
|
||||||
|
|
||||||
Kinetic.Ellipse.prototype = {
|
Kinetic.Ellipse.prototype = {
|
||||||
@ -38,25 +38,28 @@ Kinetic.Ellipse.prototype = {
|
|||||||
context.closePath();
|
context.closePath();
|
||||||
this.fill(context);
|
this.fill(context);
|
||||||
this.stroke(context);
|
this.stroke(context);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* set radius
|
||||||
|
* @name setRadius
|
||||||
|
* @methodOf Kinetic.Ellipse.prototype
|
||||||
|
* @param {Object|Array} radius
|
||||||
|
* radius can be a number, in which the ellipse becomes a circle,
|
||||||
|
* it can be an object with an x and y component, or it
|
||||||
|
* can be an array in which the first element is the x component
|
||||||
|
* and the second element is the y component. The x component
|
||||||
|
* defines the horizontal radius and the y component
|
||||||
|
* defines the vertical radius
|
||||||
|
*/
|
||||||
|
setRadius: function() {
|
||||||
|
var pos = Kinetic.Type._getXY([].slice.call(arguments));
|
||||||
|
this.setAttr('radius', Kinetic.Type._merge(pos, this.getRadius()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
|
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
|
||||||
|
|
||||||
// add getters setters
|
// add getters setters
|
||||||
Kinetic.Node.addGettersSetters(Kinetic.Ellipse, ['radius']);
|
Kinetic.Node.addGetters(Kinetic.Ellipse, ['radius']);
|
||||||
|
|
||||||
/**
|
|
||||||
* set radius
|
|
||||||
* @name setRadius
|
|
||||||
* @methodOf Kinetic.Ellipse.prototype
|
|
||||||
* @param {Object|Array} radius
|
|
||||||
* radius can be a number, in which the ellipse becomes a circle,
|
|
||||||
* it can be an object with an x and y component, or it
|
|
||||||
* can be an array in which the first element is the x component
|
|
||||||
* and the second element is the y component. The x component
|
|
||||||
* defines the horizontal radius and the y component
|
|
||||||
* defines the vertical radius
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get radius
|
* get radius
|
||||||
|
136
tests/js/Test.js
136
tests/js/Test.js
@ -3,95 +3,103 @@ var testCounter = null;
|
|||||||
var before, after;
|
var before, after;
|
||||||
|
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
before = date.getTime();
|
before = date.getTime();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function endTimer(str) {
|
function endTimer(str) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
after = date.getTime();
|
after = date.getTime();
|
||||||
var diff = after - before;
|
var diff = after - before;
|
||||||
console.log(str + ': ' + diff + 'ms');
|
console.log(str + ': ' + diff + 'ms');
|
||||||
}
|
}
|
||||||
|
|
||||||
function warn(condition, message) {
|
function warn(condition, message) {
|
||||||
test(condition, message, true);
|
test(condition, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(condition, message, warn) {
|
function test(condition, message, warn) {
|
||||||
if(!condition) {
|
if(!condition) {
|
||||||
if(warn) {
|
if(warn) {
|
||||||
testCounter.style.backgroundColor = 'orange';
|
if(testCounter.style.backgroundColor != 'red') {
|
||||||
testCounter.style.color = 'black';
|
testCounter.style.backgroundColor = 'orange';
|
||||||
console.warn(message + ' (NOTE: use Google Chrome for data url comparisons, run on web server for caching and filtering)');
|
testCounter.style.color = 'black';
|
||||||
}
|
}
|
||||||
else {
|
console.warn(message + ' (NOTE: use Google Chrome for data url comparisons, run on web server for caching and filtering)');
|
||||||
testCounter.style.backgroundColor = 'red';
|
}
|
||||||
testCounter.style.color = 'black';
|
else {
|
||||||
throw new Error(message);
|
testCounter.style.backgroundColor = 'red';
|
||||||
}
|
testCounter.style.color = 'black';
|
||||||
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
numTests++;
|
|
||||||
|
|
||||||
testCounter.innerHTML = numTests;
|
}
|
||||||
|
numTests++;
|
||||||
|
|
||||||
|
testCounter.innerHTML = numTests;
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
console.log("LOG: " + message);
|
console.log("LOG: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constructor
|
* Test constructor
|
||||||
*/
|
*/
|
||||||
function Test() {
|
function Test() {
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
testCounter = document.createElement('div');
|
testCounter = document.createElement('div');
|
||||||
testCounter.id = 'testCounter';
|
testCounter.id = 'testCounter';
|
||||||
document.getElementsByTagName('body')[0].appendChild(testCounter);
|
document.getElementsByTagName('body')[0].appendChild(testCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test methods
|
* Test methods
|
||||||
*/
|
*/
|
||||||
Test.prototype = {
|
Test.prototype = {
|
||||||
addTestContainer: function(key) {
|
addTestContainer: function(key) {
|
||||||
var row = document.createElement('div');
|
var row = document.createElement('div');
|
||||||
var container = document.createElement('div');
|
var container = document.createElement('div');
|
||||||
var testMessage = document.createElement('p');
|
var testMessage = document.createElement('p');
|
||||||
|
|
||||||
container.id = key;
|
container.id = key;
|
||||||
|
|
||||||
document.body.appendChild(testMessage);
|
document.body.appendChild(testMessage);
|
||||||
row.appendChild(container);
|
row.appendChild(container);
|
||||||
row.className = "row";
|
row.className = "row";
|
||||||
document.body.appendChild(row);
|
document.body.appendChild(row);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
testMessage: testMessage
|
testMessage: testMessage
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
run: function() {
|
run: function() {
|
||||||
var tests = this.tests;
|
var tests = this.tests;
|
||||||
|
|
||||||
var testOnlySpecial = false;
|
var testOnlySpecial = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if a test key has a star in front of it, then
|
* if a test key has a star in front of it, then
|
||||||
* only run special tests. This lets us easily run
|
* only run special tests. This lets us easily run
|
||||||
* specific tests without running all of them
|
* specific tests without running all of them
|
||||||
*/
|
*/
|
||||||
for(var key in tests) {
|
for(var key in tests) {
|
||||||
if(key.charAt(0) === '*') {
|
if(key.charAt(0) === '*') {
|
||||||
testOnlySpecial = true;
|
testOnlySpecial = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for(var key in tests) {
|
|
||||||
if(!testOnlySpecial || key.charAt(0) === '*') {
|
|
||||||
var obj = this.addTestContainer(key);
|
|
||||||
this.counter++;
|
|
||||||
console.log(this.counter + ") " + key);
|
|
||||||
tests[key](key);
|
|
||||||
obj.testMessage.innerHTML = this.counter + ") " + key + ': PASSED';
|
|
||||||
obj.testMessage.setAttribute("class", "green");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(var key in tests) {
|
||||||
|
if(!testOnlySpecial || key.charAt(0) === '*') {
|
||||||
|
var obj = this.addTestContainer(key);
|
||||||
|
this.counter++;
|
||||||
|
console.log(this.counter + ") " + key);
|
||||||
|
tests[key](key);
|
||||||
|
obj.testMessage.innerHTML = this.counter + ") " + key + ': PASSED';
|
||||||
|
obj.testMessage.setAttribute("class", "green");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -181,35 +181,6 @@ Test.prototype.tests = {
|
|||||||
group.add(circle);
|
group.add(circle);
|
||||||
layer.draw();
|
layer.draw();
|
||||||
},
|
},
|
||||||
'STAGE - serialize stage': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
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();
|
|
||||||
|
|
||||||
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Group","children":[{"attrs":{"radius":{"x":70,"y":70},"detectionType":"path","visible":true,"listening":true,"name":"myCircle","opacity":1,"x":289,"y":100,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":true,"dragThrottle":80,"fill":"green","stroke":"black","strokeWidth":4},"nodeType":"Shape","shapeType":"Circle"}]}]}]}';
|
|
||||||
|
|
||||||
//console.log(stage.toJSON())
|
|
||||||
//test(stage.toJSON() === expectedJson, 'problem with serialization');
|
|
||||||
},
|
|
||||||
'STAGE - reset stage': function(containerId) {
|
'STAGE - reset stage': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
@ -285,98 +256,6 @@ Test.prototype.tests = {
|
|||||||
|
|
||||||
test(stage.getDOM().className === 'kineticjs-content', 'stage DOM class name is wrong');
|
test(stage.getDOM().className === 'kineticjs-content', 'stage DOM class name is wrong');
|
||||||
},
|
},
|
||||||
'STAGE - load stage using json': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
|
|
||||||
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Group","children":[{"attrs":{"radius":{"x":70,"y":70},"detectionType":"path","visible":true,"listening":true,"name":"myCircle","opacity":1,"x":289,"y":100,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":true,"dragThrottle":80,"fill":"green","stroke":"black","strokeWidth":4},"nodeType":"Shape","shapeType":"Circle"}]}]}]}';
|
|
||||||
//stage.load(json);
|
|
||||||
|
|
||||||
//test(stage.toJSON() === json, "problem loading stage with json");
|
|
||||||
},
|
|
||||||
'STAGE - serialize stage with custom shape': function(containerId) {
|
|
||||||
var urls = dataUrls['STAGE - serialize stage with custom shape'];
|
|
||||||
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer();
|
|
||||||
var group = new Kinetic.Group();
|
|
||||||
|
|
||||||
var drawTriangle = function(context) {
|
|
||||||
context.beginPath();
|
|
||||||
context.moveTo(200, 50);
|
|
||||||
context.lineTo(420, 80);
|
|
||||||
context.quadraticCurveTo(300, 100, 260, 170);
|
|
||||||
context.closePath();
|
|
||||||
this.fill(context);
|
|
||||||
this.stroke(context);
|
|
||||||
};
|
|
||||||
var triangle = new Kinetic.Shape({
|
|
||||||
drawFunc: drawTriangle,
|
|
||||||
fill: "#00D2FF",
|
|
||||||
stroke: "black",
|
|
||||||
strokeWidth: 4,
|
|
||||||
id: 'myTriangle'
|
|
||||||
});
|
|
||||||
|
|
||||||
group.add(triangle);
|
|
||||||
layer.add(group);
|
|
||||||
stage.add(layer);
|
|
||||||
|
|
||||||
var startDataUrl = layer.toDataURL();
|
|
||||||
|
|
||||||
//warn(startDataUrl === urls[0], 'start data url is incorrect');
|
|
||||||
test(triangle.getId() === 'myTriangle', 'triangle id should be myTriangle');
|
|
||||||
|
|
||||||
//console.log(stage.toJSON())
|
|
||||||
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Group","children":[{"attrs":{"detectionType":"path","visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80,"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
|
||||||
|
|
||||||
//console.log(stage.toJSON())
|
|
||||||
//test(stage.toJSON() === expectedJson, "problem serializing stage with custom shape");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* test redrawing layer after serialization
|
|
||||||
* drawing should be the same
|
|
||||||
*/
|
|
||||||
layer.draw();
|
|
||||||
|
|
||||||
var endDataUrl = layer.toDataURL();
|
|
||||||
//warn(endDataUrl === urls[0], 'end data url is incorrect');
|
|
||||||
|
|
||||||
},
|
|
||||||
'STAGE - load stage with custom shape using json': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
|
|
||||||
var drawTriangle = function(context) {
|
|
||||||
context.beginPath();
|
|
||||||
context.moveTo(200, 50);
|
|
||||||
context.lineTo(420, 80);
|
|
||||||
context.quadraticCurveTo(300, 100, 260, 170);
|
|
||||||
context.closePath();
|
|
||||||
this.fill(context);
|
|
||||||
this.stroke(context);
|
|
||||||
};
|
|
||||||
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Group","children":[{"attrs":{"detectionType":"path","visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80,"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
|
||||||
//stage.load(json);
|
|
||||||
|
|
||||||
//var customShape = stage.get('#myTriangle')[0];
|
|
||||||
|
|
||||||
//customShape.setDrawFunc(drawTriangle);
|
|
||||||
|
|
||||||
//stage.draw();
|
|
||||||
//console.log(stage.toJSON());
|
|
||||||
//test(stage.toJSON() === json, "problem loading stage with custom shape json");
|
|
||||||
},
|
|
||||||
'EVENTS - test getIntersections': function(containerId) {
|
'EVENTS - test getIntersections': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
@ -974,51 +853,6 @@ Test.prototype.tests = {
|
|||||||
stage.draw();
|
stage.draw();
|
||||||
|
|
||||||
},
|
},
|
||||||
'STAGE - serialize stage with an image': function(containerId) {
|
|
||||||
var imageObj = new Image();
|
|
||||||
imageObj.onload = function() {
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer();
|
|
||||||
darth = new Kinetic.Image({
|
|
||||||
x: 200,
|
|
||||||
y: 60,
|
|
||||||
image: imageObj,
|
|
||||||
offset: {
|
|
||||||
x: 50,
|
|
||||||
y: imageObj.height / 2
|
|
||||||
},
|
|
||||||
id: 'darth'
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.add(darth);
|
|
||||||
stage.add(layer);
|
|
||||||
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80},"nodeType":"Layer","children":[{"attrs":{"detectionType":"path","visible":true,"listening":true,"opacity":1,"x":200,"y":60,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":50,"y":150},"dragConstraint":"none","dragBounds":{},"draggable":false,"dragThrottle":80,"id":"darth"},"nodeType":"Shape","shapeType":"Image"}]}]}';
|
|
||||||
//console.log(stage.toJSON())
|
|
||||||
//test(stage.toJSON() === expectedJson, 'problem with serializing stage with image');
|
|
||||||
};
|
|
||||||
imageObj.src = '../assets/darth-vader.jpg';
|
|
||||||
},
|
|
||||||
'STAGE - load stage with an image': function(containerId) {
|
|
||||||
var imageObj = new Image();
|
|
||||||
imageObj.onload = function() {
|
|
||||||
var stage = new Kinetic.Stage({
|
|
||||||
container: containerId,
|
|
||||||
width: 578,
|
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
|
|
||||||
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listen":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"visible":true,"listen":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"crop":{"x":0,"y":0},"detectionType":"path","visible":true,"listen":true,"opacity":1,"x":200,"y":60,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":50,"y":150},"dragConstraint":"none","dragBounds":{},"draggable":false,"id":"darth"},"nodeType":"Shape","shapeType":"Image"}]}]}';
|
|
||||||
//stage.load(json);
|
|
||||||
//var image = stage.get('#darth')[0];
|
|
||||||
//image.setImage(imageObj);
|
|
||||||
//stage.draw();
|
|
||||||
};
|
|
||||||
imageObj.src = '../assets/darth-vader.jpg';
|
|
||||||
},
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// LAYERS tests
|
// LAYERS tests
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
@ -1032,7 +866,7 @@ Test.prototype.tests = {
|
|||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
},
|
},
|
||||||
'LAYER - hide layer': function(containerId) {
|
'LAYER - hide show layer': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@ -1562,7 +1396,7 @@ Test.prototype.tests = {
|
|||||||
* methods, such as self, are not serialized, and will therefore avoid
|
* methods, such as self, are not serialized, and will therefore avoid
|
||||||
* circular json errors.
|
* circular json errors.
|
||||||
*/
|
*/
|
||||||
//var json = stage.toJSON();
|
var json = stage.toJSON();
|
||||||
},
|
},
|
||||||
'SHAPE - set fill after instantiation': function(containerId) {
|
'SHAPE - set fill after instantiation': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
@ -5962,5 +5796,171 @@ Test.prototype.tests = {
|
|||||||
imageObj.src = url;
|
imageObj.src = url;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
* Serialization tests
|
||||||
|
*/
|
||||||
|
'SERIALIZATION - serialize stage': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
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();
|
||||||
|
|
||||||
|
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Group","children":[{"attrs":{"radius":70,"visible":true,"listening":true,"name":"myCircle","opacity":1,"x":289,"y":100,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":true,"fill":"green","stroke":"black","strokeWidth":4},"nodeType":"Shape","shapeType":"Circle"}]}]}]}';
|
||||||
|
|
||||||
|
//console.log(stage.toJSON())
|
||||||
|
test(stage.toJSON() === expectedJson, 'problem with serialization');
|
||||||
|
},
|
||||||
|
'SERIALIZATION - load stage using json': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Group","children":[{"attrs":{"radius":70,"visible":true,"listening":true,"name":"myCircle","opacity":1,"x":289,"y":100,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":true,"fill":"green","stroke":"black","strokeWidth":4},"nodeType":"Shape","shapeType":"Circle"}]}]}]}';
|
||||||
|
stage.load(json);
|
||||||
|
|
||||||
|
test(stage.toJSON() === json, "problem loading stage with json");
|
||||||
|
},
|
||||||
|
'SERIALIZATION - serialize stage with custom shape': function(containerId) {
|
||||||
|
var urls = dataUrls['STAGE - serialize stage with custom shape'];
|
||||||
|
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
var group = new Kinetic.Group();
|
||||||
|
|
||||||
|
var drawTriangle = function(context) {
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(200, 50);
|
||||||
|
context.lineTo(420, 80);
|
||||||
|
context.quadraticCurveTo(300, 100, 260, 170);
|
||||||
|
context.closePath();
|
||||||
|
this.fill(context);
|
||||||
|
this.stroke(context);
|
||||||
|
};
|
||||||
|
var triangle = new Kinetic.Shape({
|
||||||
|
drawFunc: drawTriangle,
|
||||||
|
fill: "#00D2FF",
|
||||||
|
stroke: "black",
|
||||||
|
strokeWidth: 4,
|
||||||
|
id: 'myTriangle'
|
||||||
|
});
|
||||||
|
|
||||||
|
group.add(triangle);
|
||||||
|
layer.add(group);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var startDataUrl = layer.toDataURL();
|
||||||
|
|
||||||
|
//warn(startDataUrl === urls[0], 'start data url is incorrect');
|
||||||
|
test(triangle.getId() === 'myTriangle', 'triangle id should be myTriangle');
|
||||||
|
|
||||||
|
//console.log(stage.toJSON());
|
||||||
|
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Group","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false,"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
||||||
|
|
||||||
|
//console.log(stage.toJSON())
|
||||||
|
test(stage.toJSON() === expectedJson, "problem serializing stage with custom shape");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test redrawing layer after serialization
|
||||||
|
* drawing should be the same
|
||||||
|
*/
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
var endDataUrl = layer.toDataURL();
|
||||||
|
//warn(endDataUrl === urls[0], 'end data url is incorrect');
|
||||||
|
|
||||||
|
},
|
||||||
|
'SERIALIZATION - load stage with custom shape using json': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var drawTriangle = function(context) {
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(200, 50);
|
||||||
|
context.lineTo(420, 80);
|
||||||
|
context.quadraticCurveTo(300, 100, 260, 170);
|
||||||
|
context.closePath();
|
||||||
|
this.fill(context);
|
||||||
|
this.stroke(context);
|
||||||
|
};
|
||||||
|
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Group","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false,"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
||||||
|
stage.load(json);
|
||||||
|
|
||||||
|
stage.get('#myTriangle').apply('setDrawFunc', drawTriangle);
|
||||||
|
|
||||||
|
stage.draw();
|
||||||
|
//console.log(stage.toJSON());
|
||||||
|
test(stage.toJSON() === json, "problem loading stage with custom shape json");
|
||||||
|
},
|
||||||
|
'SERIALIZATION - serialize stage with an image': function(containerId) {
|
||||||
|
var imageObj = new Image();
|
||||||
|
imageObj.onload = function() {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
darth = new Kinetic.Image({
|
||||||
|
x: 200,
|
||||||
|
y: 60,
|
||||||
|
image: imageObj,
|
||||||
|
offset: {
|
||||||
|
x: 50,
|
||||||
|
y: imageObj.height / 2
|
||||||
|
},
|
||||||
|
id: 'darth'
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(darth);
|
||||||
|
stage.add(layer);
|
||||||
|
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":200,"y":60,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":50,"y":150},"draggable":false,"id":"darth","width":438,"height":300},"nodeType":"Shape","shapeType":"Image"}]}]}';
|
||||||
|
//console.log(stage.toJSON())
|
||||||
|
test(stage.toJSON() === expectedJson, 'problem with serializing stage with image');
|
||||||
|
};
|
||||||
|
imageObj.src = '../assets/darth-vader.jpg';
|
||||||
|
},
|
||||||
|
'SERIALIZATION - load stage with an image': function(containerId) {
|
||||||
|
var imageObj = new Image();
|
||||||
|
imageObj.onload = function() {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var json = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"clearBeforeDraw":true,"visible":true,"listening":true,"opacity":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"opacity":1,"x":200,"y":60,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":50,"y":150},"draggable":false,"id":"darth","width":438,"height":300},"nodeType":"Shape","shapeType":"Image"}]}]}';
|
||||||
|
stage.load(json);
|
||||||
|
stage.get('#darth').apply('setImage', imageObj);
|
||||||
|
stage.draw();
|
||||||
|
};
|
||||||
|
imageObj.src = '../assets/darth-vader.jpg';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user