Merge pull request #209 from CartoDB/pause-fix
Checks if animator is running before resuming it on rescale
This commit is contained in:
commit
4385c6ad9a
11
.travis.yml
11
.travis.yml
@ -1,6 +1,11 @@
|
|||||||
before_install:
|
|
||||||
- sudo apt-get install -y pkg-config libcairo2-dev libjpeg8-dev libgif-dev
|
|
||||||
|
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- pkg-config
|
||||||
|
- libcairo2-dev
|
||||||
|
- libjpeg8-dev
|
||||||
|
- libgif-dev
|
||||||
|
sudo: false
|
||||||
|
@ -83,7 +83,7 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
this.range = torque.math.linear(0, this.options.steps);
|
this.range = torque.math.linear(0, this.options.steps);
|
||||||
this.rangeInv = this.range.invert();
|
this.rangeInv = this.range.invert();
|
||||||
this.time(this._time);
|
this.time(this._time);
|
||||||
this.start();
|
this.running? this.start(): this.pause();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
* set the cartocss for the current renderer
|
* set the cartocss for the current renderer
|
||||||
*/
|
*/
|
||||||
setCartoCSS: function(cartocss) {
|
setCartoCSS: function(cartocss) {
|
||||||
if (this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
|
if (this.provider && this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
|
||||||
var shader = new carto.RendererJS().render(cartocss);
|
var shader = new carto.RendererJS().render(cartocss);
|
||||||
this.shader = shader;
|
this.shader = shader;
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
|
@ -2,45 +2,51 @@ var torque = require('../lib/torque');
|
|||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
require('phantomjs-polyfill');
|
require('phantomjs-polyfill');
|
||||||
|
|
||||||
var animator;
|
QUnit.module('animator');
|
||||||
|
|
||||||
QUnit.module('animator', {
|
test('time moves', function(assert) {
|
||||||
beforeEach: function() {
|
var done = assert.async();
|
||||||
animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
var animatora = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
}
|
animatora.start();
|
||||||
});
|
|
||||||
|
|
||||||
asyncTest('time moves', function(assert) {
|
|
||||||
animator.start();
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
assert.notEqual(animator._time, 0);
|
assert.notEqual(animatora._time, 0);
|
||||||
QUnit.start();
|
done();
|
||||||
}, 100)
|
}, 20)
|
||||||
animator.pause();
|
animatora.pause();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rescale should resume animation if previously playing", function(assert){
|
test("rescale should resume animation if previously playing", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.toggle();
|
animator.toggle();
|
||||||
animator.rescale();
|
animator.rescale();
|
||||||
assert.ok(animator.running);
|
assert.ok(animator.running);
|
||||||
animator.pause()
|
animator.pause()
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("onStart runs properly", function(assert){
|
test("rescale shouldn't resume animation if previously paused", function(assert){
|
||||||
animator.options.onStart = function(){
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
|
animator.pause();
|
||||||
|
animator.rescale();
|
||||||
|
assert.notOk(animator.running);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("onStart runs properly", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
|
animator.options.onStop = function(){
|
||||||
assert.ok(true);
|
assert.ok(true);
|
||||||
animator.pause();
|
animator.pause();
|
||||||
QUnit.start();
|
|
||||||
};
|
};
|
||||||
animator.start();
|
animator.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stop should take the pointer to position zero", function(assert){
|
test("stop should take the pointer to position zero", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.stop()
|
animator.stop()
|
||||||
assert.equal(animator._time, 0);
|
assert.equal(animator._time, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stop should call onStop", function(assert){
|
test("stop should call onStop", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.options.onStop = function(){
|
animator.options.onStop = function(){
|
||||||
assert.ok(true);
|
assert.ok(true);
|
||||||
animator.pause();
|
animator.pause();
|
||||||
@ -49,29 +55,30 @@ test("stop should call onStop", function(assert){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("altering steps should rescale", function(assert){
|
test("altering steps should rescale", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
sinon.spy(animator, "rescale");
|
sinon.spy(animator, "rescale");
|
||||||
animator.steps(600);
|
animator.steps(600);
|
||||||
assert.ok(animator.rescale.calledOnce);
|
assert.ok(animator.rescale.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("tick should set time to zero if steps are bigger than range", function(assert){
|
test("tick should set time to zero if steps are bigger than range", function(assert){
|
||||||
animator.start();
|
var done = assert.async();
|
||||||
|
var animatorb = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
|
animatorb.start();
|
||||||
|
animatorb.step(800);
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
animator._time = 0;
|
console.log(animatorb.step());
|
||||||
animator.step(800);
|
assert.ok(animatorb.step() < 800);
|
||||||
assert.ok(animator.step() < 800);
|
done();
|
||||||
QUnit.start();
|
}, 20);
|
||||||
}, 200);
|
animatorb.pause();
|
||||||
animator.pause();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("tick should pause animation on end if loop is disabled", function(assert){
|
test("tick should pause animation on end if loop is disabled", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.options.loop = false;
|
animator.options.loop = false;
|
||||||
var done = assert.async();
|
|
||||||
animator.toggle();
|
animator.toggle();
|
||||||
setTimeout(function(){
|
animator.step(600);
|
||||||
assert.notEqual(animator._time, 0);
|
assert.equal(animator._time,animator.options.animationDuration);
|
||||||
done();
|
|
||||||
}, 100)
|
|
||||||
animator.pause();
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user