mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 10:47:59 +08:00
Kinetic.Animation constructor now just requires a function and optional node. No more config object
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
#Building the KineticJS library
|
#Building the KineticJS library
|
||||||
To build the library, you need to have Ruby and Rubygems installed. After that, run `gem install thor`, `gem install json_pure`, and `gem install uglifier` to install the dependencies.
|
To build the library, you need to have Ruby and Rubygems installed. After that, run `gem install thor`, `gem install json_pure`, and `gem install uglifier` to install the dependencies.
|
||||||
|
|
||||||
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev current` will produce `kinetic-current.js`. To build a minified version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012"`).
|
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev current` will produce `kinetic-current.js`. To build a minified version of the library, run `thor build:prod VERSION`.
|
||||||
|
|
||||||
If you add a file in the src directory, be sure to add the filename to the filename array in the Thorfile.
|
If you add a file in the src directory, be sure to add the filename to the filename array in the Thorfile.
|
||||||
|
|
||||||
#Tests
|
#Testing
|
||||||
To run unit tests, you'll need to build the `unitTests.js` file by running `thor build:test` and then opening `unitTests.html` in the `tests/html` directory. The other tests can be ran directly by opening `functionalTests.html`, `manualTests.html`, or `performanceTests.html` in the `tests/html` directory. Unit, functional, and performance tests output the results to the console via `console.log()` so be sure to have it open.
|
To run unit tests, you'll need to build the `unitTests.js` file by running `thor build:test` and then opening `unitTests.html` in the `tests/html` directory. The other tests can be ran directly by opening `functionalTests.html`, `manualTests.html`, or `performanceTests.html` in the `tests/html` directory. Unit, functional, and performance tests output the results to the console via `console.log()` so be sure to have it open.
|
||||||
|
|
||||||
To add / modify unit tests, be sure to do so in the `tests/js/unit` directory, because these are the source test files that are concatenated together when building `unitTests.js`. Use `test()` for hard tests which will throw an error if something fails, and use `warn()` for soft tests that will allow the tests to continue if the test condition fails. The `warn()` method is great for tests that will have different results in different browsers, such as canvas data url comparisons, text metric dimensions, etc. All tests should pass in Google Chrome with no warnings, and all tests should pass with some warnings in other browsers.
|
To add / modify unit tests, be sure to do so in the `tests/js/unit` directory, because these are the source test files that are concatenated together when building `unitTests.js`. Use `test()` for hard tests which will throw an error if something fails, and use `warn()` for soft tests that will allow the tests to continue if the test condition fails. The `warn()` method is great for tests that will have different results in different browsers, such as canvas data url comparisons, text metric dimensions, etc. All tests should pass in Google Chrome with no warnings, and all tests should pass with some warnings in other browsers.
|
||||||
|
|
||||||
|
TIP: prepend a test name with a `*` to only run that particular test, or prepend a test name with `x` to omit that test.
|
||||||
|
|
||||||
#Pull Requests
|
#Pull Requests
|
||||||
I'd be happy to review any pull requests that may better the KineticJS project, in particular if you have a bug fix, enhancement, or a new shape (see `src/shapes` for examples). Before doing so, please first make sure that all of the unit tests and functional tests pass.
|
I'd be happy to review any pull requests that may better the KineticJS project, in particular if you have a bug fix, enhancement, or a new shape (see `src/shapes` for examples). Before doing so, please first make sure that all of the unit tests and functional tests pass.
|
||||||
|
@@ -3,17 +3,13 @@
|
|||||||
* animations
|
* animations
|
||||||
* @constructor
|
* @constructor
|
||||||
* @augments Kinetic.Container
|
* @augments Kinetic.Container
|
||||||
* @param {Object} config
|
* @param {Function} func function executed on each animation frame
|
||||||
* @param {Function} config.func function to be executed on each animation frame
|
* @param {Kinetic.Node} [node] node to be redrawn. Specifying a node will improve
|
||||||
|
* draw performance. This can be a shape, a group, a layer, or the stage.
|
||||||
*/
|
*/
|
||||||
Kinetic.Animation = function(config) {
|
Kinetic.Animation = function(func, node) {
|
||||||
if(!config) {
|
this.func = func;
|
||||||
config = {};
|
this.node = node;
|
||||||
}
|
|
||||||
for(var key in config) {
|
|
||||||
this[key] = config[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.id = Kinetic.Animation.animIdCounter++;
|
this.id = Kinetic.Animation.animIdCounter++;
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
|
@@ -94,7 +94,7 @@ Test.prototype = {
|
|||||||
|
|
||||||
// loop through tests
|
// loop through tests
|
||||||
for(var key in tests) {
|
for(var key in tests) {
|
||||||
if(!testOnlySpecial || key.charAt(0) === '*') {
|
if(key.charAt(0) !== 'x' && (!testOnlySpecial || key.charAt(0) === '*')) {
|
||||||
var obj = this.addTestContainer(key);
|
var obj = this.addTestContainer(key);
|
||||||
this.counter++;
|
this.counter++;
|
||||||
console.log(this.counter + ') ' + key);
|
console.log(this.counter + ') ' + key);
|
||||||
|
@@ -167,12 +167,9 @@ Test.Modules.MANUAL = {
|
|||||||
// in ms
|
// in ms
|
||||||
var centerX = stage.getWidth() / 2 - 100 / 2;
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
||||||
|
|
||||||
var anim = new Kinetic.Animation({
|
var anim = new Kinetic.Animation(function(frame) {
|
||||||
func: function(frame) {
|
|
||||||
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
|
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
|
||||||
layer.draw();
|
}, layer);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
anim.start();
|
anim.start();
|
||||||
|
|
||||||
@@ -1292,12 +1289,10 @@ Test.Modules.MANUAL = {
|
|||||||
layer.add(group);
|
layer.add(group);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
var anim = new Kinetic.Animation({
|
var anim = new Kinetic.Animation(function() {
|
||||||
func: function() {
|
|
||||||
rect.rotate(0.01);
|
rect.rotate(0.01);
|
||||||
layer.draw();
|
|
||||||
}
|
}, layer);
|
||||||
});
|
|
||||||
anim.start();
|
anim.start();
|
||||||
},
|
},
|
||||||
'STAGE - hide stage': function(containerId) {
|
'STAGE - hide stage': function(containerId) {
|
||||||
|
@@ -50,13 +50,11 @@ Test.Modules.PERFORMANCE = {
|
|||||||
// in ms
|
// in ms
|
||||||
var centerX = stage.getWidth() / 2 - 100 / 2;
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
||||||
|
|
||||||
var anim = new Kinetic.Animation({
|
var anim = new Kinetic.Animation(function(frame) {
|
||||||
func: function(frame) {
|
|
||||||
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
|
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
|
||||||
layer.draw();
|
|
||||||
//console.log(frame.timeDiff)
|
//console.log(frame.timeDiff)
|
||||||
}
|
}, layer);
|
||||||
});
|
|
||||||
|
|
||||||
anim.start();
|
anim.start();
|
||||||
|
|
||||||
@@ -67,7 +65,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,
|
||||||
|
@@ -29,12 +29,9 @@ Test.Modules.ANIMATION = {
|
|||||||
// in ms
|
// in ms
|
||||||
var centerX = stage.getWidth() / 2 - 100 / 2;
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
||||||
|
|
||||||
var anim = new Kinetic.Animation({
|
var anim = new Kinetic.Animation(function(frame) {
|
||||||
func: function(frame) {
|
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
||||||
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
}, layer);
|
||||||
layer.draw();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var a = Kinetic.Animation;
|
var a = Kinetic.Animation;
|
||||||
|
|
||||||
test(a.animations.length === 0, 'should be no animations running');
|
test(a.animations.length === 0, 'should be no animations running');
|
||||||
|
@@ -23,12 +23,9 @@ Test.Modules.TRANSITION = {
|
|||||||
var period = 1000;
|
var period = 1000;
|
||||||
var centerX = 0;
|
var centerX = 0;
|
||||||
|
|
||||||
var anim = new Kinetic.Animation({
|
var anim = new Kinetic.Animation(function(frame) {
|
||||||
func: function(frame) {
|
|
||||||
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
||||||
layer.draw();
|
}, layer);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
anim.start();
|
anim.start();
|
||||||
anim.stop();
|
anim.stop();
|
||||||
|
Reference in New Issue
Block a user