diff --git a/.travis.yml b/.travis.yml index 1ab0bcd..036dc72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/torque/animator.js b/lib/torque/animator.js index f908bc6..3ea8da0 100644 --- a/lib/torque/animator.js +++ b/lib/torque/animator.js @@ -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; }, diff --git a/lib/torque/gmaps/torque.js b/lib/torque/gmaps/torque.js index deb8deb..bee897c 100644 --- a/lib/torque/gmaps/torque.js +++ b/lib/torque/gmaps/torque.js @@ -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) { diff --git a/lib/torque/provider/json.js b/lib/torque/provider/json.js index a554958..967bf0d 100644 --- a/lib/torque/provider/json.js +++ b/lib/torque/provider/json.js @@ -472,7 +472,7 @@ var Profiler = require('../profiler'); torque.net.jsonp(url, function (data) { var query = format("select * from ({sql}) __torque_wrap_sql limit 0", { sql: self.getSQL() }); self.sql(query, function (queryData) { - if (data) { + if (data && queryData) { callback({ updated_at: data.last_updated, fields: queryData.fields diff --git a/package.json b/package.json index 8da4429..6ea0dcd 100644 --- a/package.json +++ b/package.json @@ -23,24 +23,27 @@ ], "licenses": [{ "type": "BSD" - }], - "dependencies": { - "carto": "https://github.com/CartoDB/carto/archive/master.tar.gz" - }, - "devDependencies": { - "leaflet": "0.7.3", - "underscore": "^1.6.0", - "node-qunit-phantomjs": "^1.0.0", - "browserify": "^7.0.0", - "mapnik": "https://github.com/CartoDB/node-mapnik/tarball/1.4.15-cdb1", - "canvas": "~1.2.1", - "request": "^2.53.0", - "qunit": "~0.7.5", - "qunitjs": "1.x", - "uglify-js": "1.3.3" - }, - "scripts": { - "test": "make test-all" - }, - "main": "./lib/torque/index.js" + } + ], + "dependencies": { + "carto": "https://github.com/CartoDB/carto/archive/master.tar.gz" + }, + "devDependencies": { + "browserify": "^7.0.0", + "canvas": "~1.2.1", + "leaflet": "0.7.3", + "mapnik": "https://github.com/CartoDB/node-mapnik/tarball/1.4.15-cdb1", + "node-qunit-phantomjs": "^1.0.0", + "phantomjs-polyfill": "0.0.1", + "qunit": "~0.7.5", + "qunitjs": "1.x", + "request": "^2.53.0", + "uglify-js": "1.3.3", + "underscore": "^1.6.0", + "sinon": "^1.15.4" + }, + "scripts": { + "test": "make test-all" + }, + "main": "./lib/torque/index.js" } diff --git a/test/animator.js b/test/animator.js new file mode 100644 index 0000000..4c6eeaf --- /dev/null +++ b/test/animator.js @@ -0,0 +1,84 @@ +var torque = require('../lib/torque'); +var sinon = require('sinon'); +require('phantomjs-polyfill'); + +QUnit.module('animator'); + +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(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() +}); + +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(); + }; + 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(); + }; + animator.stop(); +}); + +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); +}); + +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(){ + console.log(animatorb.step()); + assert.ok(animatorb.step() < 800); + done(); + }, 20); + animatorb.pause(); +}); + +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.toggle(); + animator.step(600); + assert.equal(animator._time,animator.options.animationDuration); + +}); diff --git a/test/suite.js b/test/suite.js index b761591..1898b94 100644 --- a/test/suite.js +++ b/test/suite.js @@ -7,3 +7,4 @@ require('./provider.jsonarray'); require('./provider.windshaft.test'); require('./provider.json'); require('./request'); +require('./animator');