Merge pull request #209 from CartoDB/pause-fix

Checks if animator is running before resuming it on rescale
This commit is contained in:
Francisco Dans 2015-08-05 14:49:14 +02:00
commit 4385c6ad9a
4 changed files with 49 additions and 37 deletions

View File

@ -1,6 +1,11 @@
before_install:
- sudo apt-get install -y pkg-config libcairo2-dev libjpeg8-dev libgif-dev
language: node_js
node_js:
- "0.10"
addons:
apt:
packages:
- pkg-config
- libcairo2-dev
- libjpeg8-dev
- libgif-dev
sudo: false

View File

@ -83,7 +83,7 @@ var cancelAnimationFrame = global.cancelAnimationFrame
this.range = torque.math.linear(0, this.options.steps);
this.rangeInv = this.range.invert();
this.time(this._time);
this.start();
this.running? this.start(): this.pause();
return this;
},

View File

@ -270,7 +270,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
* set the cartocss for the current renderer
*/
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);
this.shader = shader;
if (this.renderer) {

View File

@ -2,45 +2,51 @@ var torque = require('../lib/torque');
var sinon = require('sinon');
require('phantomjs-polyfill');
var animator;
QUnit.module('animator');
QUnit.module('animator', {
beforeEach: function() {
animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
}
});
asyncTest('time moves', function(assert) {
animator.start();
test('time moves', function(assert) {
var done = assert.async();
var animatora = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
animatora.start();
setTimeout(function(){
assert.notEqual(animator._time, 0);
QUnit.start();
}, 100)
animator.pause();
assert.notEqual(animatora._time, 0);
done();
}, 20)
animatora.pause();
});
test("rescale should resume animation if previously playing", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
animator.toggle();
animator.rescale();
assert.ok(animator.running);
animator.pause()
});
asyncTest("onStart runs properly", function(assert){
animator.options.onStart = function(){
test("rescale shouldn't resume animation if previously paused", function(assert){
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);
animator.pause();
QUnit.start();
};
animator.start();
animator.stop();
});
test("stop should take the pointer to position zero", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
animator.stop()
assert.equal(animator._time, 0);
});
test("stop should call onStop", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
animator.options.onStop = function(){
assert.ok(true);
animator.pause();
@ -49,29 +55,30 @@ test("stop should call onStop", function(assert){
});
test("altering steps should rescale", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
sinon.spy(animator, "rescale");
animator.steps(600);
assert.ok(animator.rescale.calledOnce);
});
asyncTest("tick should set time to zero if steps are bigger than range", function(assert){
animator.start();
test("tick should set time to zero if steps are bigger than range", function(assert){
var done = assert.async();
var animatorb = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
animatorb.start();
animatorb.step(800);
setTimeout(function(){
animator._time = 0;
animator.step(800);
assert.ok(animator.step() < 800);
QUnit.start();
}, 200);
animator.pause();
console.log(animatorb.step());
assert.ok(animatorb.step() < 800);
done();
}, 20);
animatorb.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;
var done = assert.async();
animator.toggle();
setTimeout(function(){
assert.notEqual(animator._time, 0);
done();
}, 100)
animator.pause();
animator.step(600);
assert.equal(animator._time,animator.options.animationDuration);
});