From deb0caff448c8fcaa583b3b1cf5683eb345abf70 Mon Sep 17 00:00:00 2001 From: Brandon Tilley Date: Tue, 24 Dec 2013 08:28:19 -0800 Subject: [PATCH] Add jshint and gulp task; implement hints --- dist/planetaryjs-noplugins.js | 12 +++++------ dist/planetaryjs-noplugins.min.js | 2 +- dist/planetaryjs.js | 30 ++++++++++++++------------- dist/planetaryjs.min.js | 2 +- gulpfile.js | 8 +++++++ package.json | 4 +++- site/public/js/lib/planetaryjs.min.js | 2 +- src/body.js | 10 ++++----- src/plugins.js | 18 +++++++++------- 9 files changed, 51 insertions(+), 37 deletions(-) diff --git a/dist/planetaryjs-noplugins.js b/dist/planetaryjs-noplugins.js index d15a48b..bdb5ad6 100644 --- a/dist/planetaryjs-noplugins.js +++ b/dist/planetaryjs-noplugins.js @@ -2,7 +2,7 @@ * Copyright (c) 2013 Brandon Tilley * * Released under the MIT license - * Date: 2013-12-24T06:08:52.591Z + * Date: 2013-12-24T16:27:25.392Z */ (function (root, factory) { if (typeof define === 'function' && define.amd) { @@ -21,7 +21,7 @@ var doDrawLoop = function(planet, canvas, hooks) { d3.timer(function() { - planet.context.clearRect(0, 0, canvas.width, canvas.height) + planet.context.clearRect(0, 0, canvas.width, canvas.height); for (var i = 0; i < hooks.onDraw.length; i++) { hooks.onDraw[i](); } @@ -35,14 +35,14 @@ } // Load the default plugins if none have been loaded so far - if (localPlugins.length == 0) { + if (localPlugins.length === 0) { if (planetaryjs.plugins.earth) planet.loadPlugin(planetaryjs.plugins.earth()); if (planetaryjs.plugins.pings) planet.loadPlugin(planetaryjs.plugins.pings()); } - for (var i = 0; i < localPlugins.length; i++) { + for (i = 0; i < localPlugins.length; i++) { localPlugins[i](planet); } }; @@ -68,7 +68,7 @@ var check = function() { if (completed >= hooks.onInit.length) doDrawLoop(planet, canvas, hooks); else doNext(check); - } + }; doNext(check); } else { doDrawLoop(planet, canvas, hooks); @@ -124,7 +124,7 @@ withSavedContext: function(fn) { if (!this.context) { - throw new Error("No canvas to fetch context for") + throw new Error("No canvas to fetch context for"); } this.context.save(); diff --git a/dist/planetaryjs-noplugins.min.js b/dist/planetaryjs-noplugins.min.js index 77bf653..d74c18b 100644 --- a/dist/planetaryjs-noplugins.min.js +++ b/dist/planetaryjs-noplugins.min.js @@ -1,2 +1,2 @@ /*! Planetary.js 0.3.0 | (c) 2013 Brandon Tilley | Released under MIT License */ -!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(u)};i(u)}else r(n,t,o)},a=function(n,t,o,e){u(n,o),n.canvas=t,n.context=t.getContext("2d"),c(n,t,e)},s={plugins:{},noConflict:function(){return o.planetaryjs=e,s},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){a(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return s}); \ No newline at end of file +!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(u)};i(u)}else r(n,t,o)},a=function(n,t,o,e){u(n,o),n.canvas=t,n.context=t.getContext("2d"),c(n,t,e)},s={plugins:{},noConflict:function(){return o.planetaryjs=e,s},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){a(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return s}); \ No newline at end of file diff --git a/dist/planetaryjs.js b/dist/planetaryjs.js index 59916f0..d76f052 100644 --- a/dist/planetaryjs.js +++ b/dist/planetaryjs.js @@ -2,7 +2,7 @@ * Copyright (c) 2013 Brandon Tilley * * Released under the MIT license - * Date: 2013-12-24T06:08:52.665Z + * Date: 2013-12-24T16:27:25.159Z */ (function (root, factory) { if (typeof define === 'function' && define.amd) { @@ -21,7 +21,7 @@ var doDrawLoop = function(planet, canvas, hooks) { d3.timer(function() { - planet.context.clearRect(0, 0, canvas.width, canvas.height) + planet.context.clearRect(0, 0, canvas.width, canvas.height); for (var i = 0; i < hooks.onDraw.length; i++) { hooks.onDraw[i](); } @@ -35,14 +35,14 @@ } // Load the default plugins if none have been loaded so far - if (localPlugins.length == 0) { + if (localPlugins.length === 0) { if (planetaryjs.plugins.earth) planet.loadPlugin(planetaryjs.plugins.earth()); if (planetaryjs.plugins.pings) planet.loadPlugin(planetaryjs.plugins.pings()); } - for (var i = 0; i < localPlugins.length; i++) { + for (i = 0; i < localPlugins.length; i++) { localPlugins[i](planet); } }; @@ -68,7 +68,7 @@ var check = function() { if (completed >= hooks.onInit.length) doDrawLoop(planet, canvas, hooks); else doNext(check); - } + }; doNext(check); } else { doDrawLoop(planet, canvas, hooks); @@ -124,7 +124,7 @@ withSavedContext: function(fn) { if (!this.context) { - throw new Error("No canvas to fetch context for") + throw new Error("No canvas to fetch context for"); } this.context.save(); @@ -151,7 +151,7 @@ planet.plugins.topojson.world = config.world; setTimeout(done, 0); } else { - var file = config.file || 'world-110m.json' + var file = config.file || 'world-110m.json'; d3.json(file, function(err, world) { if (err) { throw new Error("Could not load JSON " + file); @@ -185,14 +185,14 @@ planet.onInit(function() { var world = planet.plugins.topojson.world; land = topojson.feature(world, world.objects.land); - }) + }); planet.onDraw(function() { planet.withSavedContext(function(context) { context.beginPath(); planet.path.context(context)(land); - if (config.fill != false) { + if (config.fill !== false) { context.fillStyle = config.fill || 'white'; context.fill(); } @@ -242,7 +242,7 @@ }; planetaryjs.plugins.earth = function(config) { - var config = config || {}; + config = config || {}; var topojsonOptions = config.topojson || {}; var oceanOptions = config.oceans || {}; var landOptions = config.land || {}; @@ -258,10 +258,10 @@ planetaryjs.plugins.pings = function(config) { var pings = []; - var config = config || {}; + config = config || {}; var addPing = function(lng, lat, options) { - var options = options || {}; + options = options || {}; options.color = options.color || config.color || 'white'; options.angle = options.angle || config.angle || 5; options.ttl = options.ttl || config.ttl || 2000; @@ -316,7 +316,7 @@ }; planetaryjs.plugins.zoom = function (options) { - var options = options || {}; + options = options || {}; var noop = function() {}; var onZoomStart = options.onZoomStart || noop; var onZoomEnd = options.onZoomEnd || noop; @@ -329,11 +329,13 @@ planet.onInit(function() { var zoom = d3.behavior.zoom() .scaleExtent(scaleExtent); + if (startScale) { zoom.scale(startScale); } else { zoom.scale(planet.projection.scale()); } + zoom .on('zoomstart', onZoomStart) .on('zoomend', onZoomEnd) @@ -348,7 +350,7 @@ }; planetaryjs.plugins.drag = function(options) { - var options = options || {}; + options = options || {}; var noop = function() {}; var onDragStart = options.onDragStart || noop; var onDragEnd = options.onDragEnd || noop; diff --git a/dist/planetaryjs.min.js b/dist/planetaryjs.min.js index 66417ed..aa73ac8 100644 --- a/dist/planetaryjs.min.js +++ b/dist/planetaryjs.min.js @@ -1,2 +1,2 @@ /*! Planetary.js 0.3.0 | (c) 2013 Brandon Tilley | Released under MIT License */ -!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(l)};i(l)}else r(n,t,o)},u=function(n,t,o,e){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,e)},c={plugins:{},noConflict:function(){return o.planetaryjs=e,c},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){u(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(e){if(t.world)o.plugins.topojson.world=t.world,setTimeout(e,0);else{var i=t.file||"world-110m.json";n.json(i,function(n,t){if(n)throw new Error("Could not load JSON "+i);o.plugins.topojson.world=t,e()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var e=null;o.onInit(function(){var n=o.plugins.topojson.world;e=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),0!=n.fill&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var e=null,i={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";e=t.mesh(r,l,i[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){var n=n||{},t=n.topojson||{},o=n.oceans||{},e=n.land||{},i=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(e)(n),c.plugins.borders(i)(n)}},c.plugins.pings=function(t){var o=[],t=t||{},e=function(n,e,i){var i=i||{};i.color=i.color||t.color||"white",i.angle=i.angle||t.angle||5,i.ttl=i.ttl||t.ttl||2e3;var r={time:new Date,options:i};t.latitudeFirst?(r.lat=n,r.lng=e):(r.lng=n,r.lat=e),o.push(r)},i=function(n,t,e){for(var i=[],l=0;l90&&(i[1]=90),i[1]<-90&&(i[1]=-90),i[0]>=180&&(i[0]-=360),t.projection.rotate(i),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file +!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(l)};i(l)}else r(n,t,o)},u=function(n,t,o,e){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,e)},c={plugins:{},noConflict:function(){return o.planetaryjs=e,c},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){u(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(e){if(t.world)o.plugins.topojson.world=t.world,setTimeout(e,0);else{var i=t.file||"world-110m.json";n.json(i,function(n,t){if(n)throw new Error("Could not load JSON "+i);o.plugins.topojson.world=t,e()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var e=null;o.onInit(function(){var n=o.plugins.topojson.world;e=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var e=null,i={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";e=t.mesh(r,l,i[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},e=n.land||{},i=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(e)(n),c.plugins.borders(i)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var e=function(n,e,i){i=i||{},i.color=i.color||t.color||"white",i.angle=i.angle||t.angle||5,i.ttl=i.ttl||t.ttl||2e3;var r={time:new Date,options:i};t.latitudeFirst?(r.lat=n,r.lng=e):(r.lng=n,r.lat=e),o.push(r)},i=function(n,t,e){for(var i=[],l=0;l90&&(i[1]=90),i[1]<-90&&(i[1]=-90),i[0]>=180&&(i[0]-=360),t.projection.rotate(i),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index ec6306b..3ad5182 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,6 +3,7 @@ var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); var rename = require('gulp-rename'); var header = require('gulp-header'); +var jshint = require('gulp-jshint'); var metadata = require('./package.json'); var shortHeader = "/*! Planetary.js {{version}} | (c) 2013 Brandon Tilley | Released under MIT License */" @@ -25,6 +26,12 @@ function build(source, name, headerText, minify) { js.pipe(gulp.dest('./dist')); } +gulp.task('jshint', function() { + gulp.src(['./src/body.js', './src/plugins.js']) + .pipe(jshint()) + .pipe(jshint.reporter('default')); +}); + gulp.task('build', function() { build(fullSource, 'planetaryjs.js', fullHeader, false); build(fullSource, 'planetaryjs.min.js', shortHeader, true); @@ -35,5 +42,6 @@ gulp.task('build', function() { }); gulp.task('default', function() { + gulp.run('jshint'); gulp.run('build'); }); diff --git a/package.json b/package.json index 9c17f23..fe3a2b9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Awesome interactive globes for the web", "scripts": { "build": "rm -r dist/ ; gulp && cp dist/planetaryjs.min.js site/public/js/lib", + "jshint": "gulp jshint", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -22,6 +23,7 @@ "gulp-header": "~0.4.0", "gulp-uglify": "~0.1.0", "gulp-rename": "~0.2.1", - "bower": "~1.2.8" + "bower": "~1.2.8", + "gulp-jshint": "~1.3.1" } } diff --git a/site/public/js/lib/planetaryjs.min.js b/site/public/js/lib/planetaryjs.min.js index 66417ed..aa73ac8 100644 --- a/site/public/js/lib/planetaryjs.min.js +++ b/site/public/js/lib/planetaryjs.min.js @@ -1,2 +1,2 @@ /*! Planetary.js 0.3.0 | (c) 2013 Brandon Tilley | Released under MIT License */ -!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(l)};i(l)}else r(n,t,o)},u=function(n,t,o,e){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,e)},c={plugins:{},noConflict:function(){return o.planetaryjs=e,c},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){u(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(e){if(t.world)o.plugins.topojson.world=t.world,setTimeout(e,0);else{var i=t.file||"world-110m.json";n.json(i,function(n,t){if(n)throw new Error("Could not load JSON "+i);o.plugins.topojson.world=t,e()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var e=null;o.onInit(function(){var n=o.plugins.topojson.world;e=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),0!=n.fill&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var e=null,i={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";e=t.mesh(r,l,i[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){var n=n||{},t=n.topojson||{},o=n.oceans||{},e=n.land||{},i=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(e)(n),c.plugins.borders(i)(n)}},c.plugins.pings=function(t){var o=[],t=t||{},e=function(n,e,i){var i=i||{};i.color=i.color||t.color||"white",i.angle=i.angle||t.angle||5,i.ttl=i.ttl||t.ttl||2e3;var r={time:new Date,options:i};t.latitudeFirst?(r.lat=n,r.lng=e):(r.lng=n,r.lat=e),o.push(r)},i=function(n,t,e){for(var i=[],l=0;l90&&(i[1]=90),i[1]<-90&&(i[1]=-90),i[0]>=180&&(i[0]-=360),t.projection.rotate(i),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file +!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var e=null;o&&(e=o.planetaryjs);var i=[],r=function(t,o,e){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=o.onInit.length?r(n,t,o):i(l)};i(l)}else r(n,t,o)},u=function(n,t,o,e){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,e)},c={plugins:{},noConflict:function(){return o.planetaryjs=e,c},loadPlugin:function(n){i.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},e={plugins:{},draw:function(n){u(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return e.projection=n.geo.orthographic().clipAngle(90).precision(0),e.path=n.geo.path().projection(e.projection),e}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(e){if(t.world)o.plugins.topojson.world=t.world,setTimeout(e,0);else{var i=t.file||"world-110m.json";n.json(i,function(n,t){if(n)throw new Error("Could not load JSON "+i);o.plugins.topojson.world=t,e()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var e=null;o.onInit(function(){var n=o.plugins.topojson.world;e=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var e=null,i={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";e=t.mesh(r,l,i[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},e=n.land||{},i=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(e)(n),c.plugins.borders(i)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var e=function(n,e,i){i=i||{},i.color=i.color||t.color||"white",i.angle=i.angle||t.angle||5,i.ttl=i.ttl||t.ttl||2e3;var r={time:new Date,options:i};t.latitudeFirst?(r.lat=n,r.lng=e):(r.lng=n,r.lat=e),o.push(r)},i=function(n,t,e){for(var i=[],l=0;l90&&(i[1]=90),i[1]<-90&&(i[1]=-90),i[0]>=180&&(i[0]-=360),t.projection.rotate(i),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file diff --git a/src/body.js b/src/body.js index 656dd6e..19fb383 100644 --- a/src/body.js +++ b/src/body.js @@ -4,7 +4,7 @@ var doDrawLoop = function(planet, canvas, hooks) { d3.timer(function() { - planet.context.clearRect(0, 0, canvas.width, canvas.height) + planet.context.clearRect(0, 0, canvas.width, canvas.height); for (var i = 0; i < hooks.onDraw.length; i++) { hooks.onDraw[i](); } @@ -18,14 +18,14 @@ } // Load the default plugins if none have been loaded so far - if (localPlugins.length == 0) { + if (localPlugins.length === 0) { if (planetaryjs.plugins.earth) planet.loadPlugin(planetaryjs.plugins.earth()); if (planetaryjs.plugins.pings) planet.loadPlugin(planetaryjs.plugins.pings()); } - for (var i = 0; i < localPlugins.length; i++) { + for (i = 0; i < localPlugins.length; i++) { localPlugins[i](planet); } }; @@ -51,7 +51,7 @@ var check = function() { if (completed >= hooks.onInit.length) doDrawLoop(planet, canvas, hooks); else doNext(check); - } + }; doNext(check); } else { doDrawLoop(planet, canvas, hooks); @@ -107,7 +107,7 @@ withSavedContext: function(fn) { if (!this.context) { - throw new Error("No canvas to fetch context for") + throw new Error("No canvas to fetch context for"); } this.context.save(); diff --git a/src/plugins.js b/src/plugins.js index 6933827..a2bce49 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -7,7 +7,7 @@ planet.plugins.topojson.world = config.world; setTimeout(done, 0); } else { - var file = config.file || 'world-110m.json' + var file = config.file || 'world-110m.json'; d3.json(file, function(err, world) { if (err) { throw new Error("Could not load JSON " + file); @@ -41,14 +41,14 @@ planet.onInit(function() { var world = planet.plugins.topojson.world; land = topojson.feature(world, world.objects.land); - }) + }); planet.onDraw(function() { planet.withSavedContext(function(context) { context.beginPath(); planet.path.context(context)(land); - if (config.fill != false) { + if (config.fill !== false) { context.fillStyle = config.fill || 'white'; context.fill(); } @@ -98,7 +98,7 @@ }; planetaryjs.plugins.earth = function(config) { - var config = config || {}; + config = config || {}; var topojsonOptions = config.topojson || {}; var oceanOptions = config.oceans || {}; var landOptions = config.land || {}; @@ -114,10 +114,10 @@ planetaryjs.plugins.pings = function(config) { var pings = []; - var config = config || {}; + config = config || {}; var addPing = function(lng, lat, options) { - var options = options || {}; + options = options || {}; options.color = options.color || config.color || 'white'; options.angle = options.angle || config.angle || 5; options.ttl = options.ttl || config.ttl || 2000; @@ -172,7 +172,7 @@ }; planetaryjs.plugins.zoom = function (options) { - var options = options || {}; + options = options || {}; var noop = function() {}; var onZoomStart = options.onZoomStart || noop; var onZoomEnd = options.onZoomEnd || noop; @@ -185,11 +185,13 @@ planet.onInit(function() { var zoom = d3.behavior.zoom() .scaleExtent(scaleExtent); + if (startScale) { zoom.scale(startScale); } else { zoom.scale(planet.projection.scale()); } + zoom .on('zoomstart', onZoomStart) .on('zoomend', onZoomEnd) @@ -204,7 +206,7 @@ }; planetaryjs.plugins.drag = function(options) { - var options = options || {}; + options = options || {}; var noop = function() {}; var onDragStart = options.onDragStart || noop; var onDragEnd = options.onDragEnd || noop;