Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
838bf92265 | ||
|
|
24ad38a824 | ||
|
|
1a388e7c4a | ||
|
|
801ccb28e5 | ||
|
|
52716cba5b | ||
|
|
80ef60d6cf | ||
|
|
f4d9536f17 | ||
|
|
9344299298 | ||
|
|
3d6ca445f8 | ||
|
|
c86479db1f | ||
|
|
5e807f52e0 | ||
|
|
cfb059369e | ||
|
|
4edb647564 | ||
|
|
74013bde29 | ||
|
|
62e8d08bd9 | ||
|
|
f5bf0743fb |
23
CHANGELOG.md
23
CHANGELOG.md
@ -1,3 +1,26 @@
|
||||
v1.1.2 (2015/11/22)
|
||||
-------------------
|
||||
|
||||
* Update LICENSE and copyright notices
|
||||
|
||||
v1.1.1 (2014/05/18)
|
||||
-------------------
|
||||
|
||||
* Set `planetaryjs` on root when using AMD
|
||||
|
||||
v1.1.0 (2014/02/03)
|
||||
-------------------
|
||||
|
||||
**Core**
|
||||
|
||||
* Add `stop` method
|
||||
* Add `onStop` hooks
|
||||
|
||||
v1.0.3 (2014/01/23)
|
||||
-------------------
|
||||
|
||||
* Don't disable adaptive resampling on the projection
|
||||
|
||||
v1.0.2 (2014/01/16)
|
||||
-------------------
|
||||
|
||||
|
||||
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2013 Brandon Tilley
|
||||
Copyright (c) 2013 Michelle Tilley
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "planetary.js",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.2",
|
||||
"main": "dist/planetaryjs.min.js",
|
||||
"description": "Awesome interactive globes for the web",
|
||||
"homepage": "http://planetaryjs.com",
|
||||
"authors": [
|
||||
"Brandon Tilley <brandon@brandontilley.com>"
|
||||
"Michelle Tilley <michelle@michelletilley.net>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
|
||||
38
dist/planetaryjs-noplugins.js
vendored
38
dist/planetaryjs-noplugins.js
vendored
@ -1,12 +1,14 @@
|
||||
/*! Planetary.js v1.0.2
|
||||
* Copyright (c) 2013 Brandon Tilley
|
||||
/*! Planetary.js v1.1.3
|
||||
* Copyright (c) 2013 Michelle Tilley
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Date: 2014-01-16T05:32:02.925Z
|
||||
* Date: 2018-10-30T18:49:58.804Z
|
||||
*/
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['d3', 'topojson'], factory);
|
||||
define(['d3', 'topojson'], function(d3, topojson) {
|
||||
return (root.planetaryjs = factory(d3, topojson, root));
|
||||
});
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory(require('d3'), require('topojson'));
|
||||
} else {
|
||||
@ -21,6 +23,10 @@
|
||||
|
||||
var doDrawLoop = function(planet, canvas, hooks) {
|
||||
d3.timer(function() {
|
||||
if (planet.stopped) {
|
||||
return true;
|
||||
}
|
||||
|
||||
planet.context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
for (var i = 0; i < hooks.onDraw.length; i++) {
|
||||
hooks.onDraw[i]();
|
||||
@ -76,11 +82,14 @@
|
||||
};
|
||||
|
||||
var startDraw = function(planet, canvas, localPlugins, hooks) {
|
||||
initPlugins(planet, localPlugins);
|
||||
|
||||
planet.canvas = canvas;
|
||||
planet.context = canvas.getContext('2d');
|
||||
|
||||
if (planet.stopped !== true) {
|
||||
initPlugins(planet, localPlugins);
|
||||
}
|
||||
|
||||
planet.stopped = false;
|
||||
runOnInitHooks(planet, canvas, hooks);
|
||||
};
|
||||
|
||||
@ -100,7 +109,8 @@
|
||||
var localPlugins = [];
|
||||
var hooks = {
|
||||
onInit: [],
|
||||
onDraw: []
|
||||
onDraw: [],
|
||||
onStop: []
|
||||
};
|
||||
|
||||
var planet = {
|
||||
@ -118,10 +128,21 @@
|
||||
hooks.onDraw.push(fn);
|
||||
},
|
||||
|
||||
onStop: function(fn) {
|
||||
hooks.onStop.push(fn);
|
||||
},
|
||||
|
||||
loadPlugin: function(plugin) {
|
||||
localPlugins.push(plugin);
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
planet.stopped = true;
|
||||
for (var i = 0; i < hooks.onStop.length; i++) {
|
||||
hooks.onStop[i](planet);
|
||||
}
|
||||
},
|
||||
|
||||
withSavedContext: function(fn) {
|
||||
if (!this.context) {
|
||||
throw new Error("No canvas to fetch context for");
|
||||
@ -134,8 +155,7 @@
|
||||
};
|
||||
|
||||
planet.projection = d3.geo.orthographic()
|
||||
.clipAngle(90)
|
||||
.precision(0);
|
||||
.clipAngle(90);
|
||||
planet.path = d3.geo.path().projection(planet.projection);
|
||||
|
||||
return planet;
|
||||
|
||||
4
dist/planetaryjs-noplugins.min.js
vendored
4
dist/planetaryjs-noplugins.min.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! Planetary.js 1.0.2 | (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<e.onDraw.length;n++)e.onDraw[n]()})},u=function(n,t){for(var o=i.length-1;o>=0;o--)t.unshift(i[o]);for(0===t.length&&(s.plugins.earth&&n.loadPlugin(s.plugins.earth()),s.plugins.pings&&n.loadPlugin(s.plugins.pings())),o=0;o<t.length;o++)t[o](n)},c=function(n,t,o){if(o.onInit.length){var e=0,i=function(n){var t=o.onInit[e];t.length?t(function(){e++,n()}):(t(),e++,setTimeout(n,0))},u=function(){e>=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});
|
||||
/*! Planetary.js 1.1.3 | (c) 2013 Michelle Tilley | Released under MIT License */
|
||||
!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],function(o,e){return n.planetaryjs=t(o,e,n)}):"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(){if(t.stopped)return!0;t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<e.onDraw.length;n++)e.onDraw[n]()})},u=function(n,t){for(var o=i.length-1;o>=0;o--)t.unshift(i[o]);for(0===t.length&&(s.plugins.earth&&n.loadPlugin(s.plugins.earth()),s.plugins.pings&&n.loadPlugin(s.plugins.pings())),o=0;o<t.length;o++)t[o](n)},p=function(n,t,o){if(o.onInit.length){var e=0,i=function(n){var t=o.onInit[e];t.length?t(function(){e++,n()}):(t(),e++,setTimeout(n,0))},u=function(){e>=o.onInit.length?r(n,t,o):i(u)};i(u)}else r(n,t,o)},c=function(n,t,o,e){n.canvas=t,n.context=t.getContext("2d"),n.stopped!==!0&&u(n,o),n.stopped=!1,p(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:[],onStop:[]},e={plugins:{},draw:function(n){c(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},onStop:function(n){o.onStop.push(n)},loadPlugin:function(n){t.push(n)},stop:function(){e.stopped=!0;for(var n=0;n<o.onStop.length;n++)o.onStop[n](e)},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),e.path=n.geo.path().projection(e.projection),e}};return s});
|
||||
38
dist/planetaryjs.js
vendored
38
dist/planetaryjs.js
vendored
@ -1,12 +1,14 @@
|
||||
/*! Planetary.js v1.0.2
|
||||
* Copyright (c) 2013 Brandon Tilley
|
||||
/*! Planetary.js v1.1.3
|
||||
* Copyright (c) 2013 Michelle Tilley
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Date: 2014-01-16T05:32:02.988Z
|
||||
* Date: 2018-10-30T18:49:58.667Z
|
||||
*/
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['d3', 'topojson'], factory);
|
||||
define(['d3', 'topojson'], function(d3, topojson) {
|
||||
return (root.planetaryjs = factory(d3, topojson, root));
|
||||
});
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory(require('d3'), require('topojson'));
|
||||
} else {
|
||||
@ -21,6 +23,10 @@
|
||||
|
||||
var doDrawLoop = function(planet, canvas, hooks) {
|
||||
d3.timer(function() {
|
||||
if (planet.stopped) {
|
||||
return true;
|
||||
}
|
||||
|
||||
planet.context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
for (var i = 0; i < hooks.onDraw.length; i++) {
|
||||
hooks.onDraw[i]();
|
||||
@ -76,11 +82,14 @@
|
||||
};
|
||||
|
||||
var startDraw = function(planet, canvas, localPlugins, hooks) {
|
||||
initPlugins(planet, localPlugins);
|
||||
|
||||
planet.canvas = canvas;
|
||||
planet.context = canvas.getContext('2d');
|
||||
|
||||
if (planet.stopped !== true) {
|
||||
initPlugins(planet, localPlugins);
|
||||
}
|
||||
|
||||
planet.stopped = false;
|
||||
runOnInitHooks(planet, canvas, hooks);
|
||||
};
|
||||
|
||||
@ -100,7 +109,8 @@
|
||||
var localPlugins = [];
|
||||
var hooks = {
|
||||
onInit: [],
|
||||
onDraw: []
|
||||
onDraw: [],
|
||||
onStop: []
|
||||
};
|
||||
|
||||
var planet = {
|
||||
@ -118,10 +128,21 @@
|
||||
hooks.onDraw.push(fn);
|
||||
},
|
||||
|
||||
onStop: function(fn) {
|
||||
hooks.onStop.push(fn);
|
||||
},
|
||||
|
||||
loadPlugin: function(plugin) {
|
||||
localPlugins.push(plugin);
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
planet.stopped = true;
|
||||
for (var i = 0; i < hooks.onStop.length; i++) {
|
||||
hooks.onStop[i](planet);
|
||||
}
|
||||
},
|
||||
|
||||
withSavedContext: function(fn) {
|
||||
if (!this.context) {
|
||||
throw new Error("No canvas to fetch context for");
|
||||
@ -134,8 +155,7 @@
|
||||
};
|
||||
|
||||
planet.projection = d3.geo.orthographic()
|
||||
.clipAngle(90)
|
||||
.precision(0);
|
||||
.clipAngle(90);
|
||||
planet.path = d3.geo.path().projection(planet.projection);
|
||||
|
||||
return planet;
|
||||
|
||||
4
dist/planetaryjs.min.js
vendored
4
dist/planetaryjs.min.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! Planetary.js 1.0.2 | (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 i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<i.onDraw.length;n++)i.onDraw[n]()})},l=function(n,t){for(var o=e.length-1;o>=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var i=0,e=function(n){var t=o.onInit[i];t.length?t(function(){i++,n()}):(t(),i++,setTimeout(n,0))},l=function(){i>=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},c={plugins:{},noConflict:function(){return o.planetaryjs=i,c},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){u(i,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 i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},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 i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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 i=null,e={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";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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||{},i=n.land||{},e=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(i)(n),c.plugins.borders(e)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l<o.length;l++){var a=o[l],u=i-a.time;u<a.options.ttl&&(e.push(a),r(n,t,i,u,a))}o=e},r=function(t,o,i,e,r){var l=1-e/r.options.ttl,a=n.rgb(r.options.color);a="rgba("+a.r+","+a.g+","+a.b+","+l+")",o.strokeStyle=a;var u=n.geo.circle().origin([r.lng,r.lat]).angle(e/r.options.ttl*r.options.angle)();o.beginPath(),t.path.context(o)(u),o.stroke()};return function(n){n.plugins.pings={add:i},n.onDraw(function(){var t=new Date;n.withSavedContext(function(o){e(n,o,t)})})}},c.plugins.zoom=function(t){t=t||{};var o=function(){},i=t.onZoomStart||o,e=t.onZoomEnd||o,r=t.onZoom||o,l=t.afterZoom||o,a=t.initialScale,u=t.scaleExtent||[50,2e3];return function(t){t.onInit(function(){var o=n.behavior.zoom().scaleExtent(u);o.scale(null!==a&&void 0!==a?a:t.projection.scale()),o.on("zoomstart",i.bind(t)).on("zoomend",e.bind(t)).on("zoom",function(){r.call(t),t.projection.scale(n.event.scale),l.call(t)}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){t=t||{};var o=function(){},i=t.onDragStart||o,e=t.onDragEnd||o,r=t.onDrag||o,l=t.afterDrag||o;return function(t){t.onInit(function(){var o=n.behavior.drag().on("dragstart",i.bind(t)).on("dragend",e.bind(t)).on("drag",function(){r.call(t);var o=n.event.dx,i=n.event.dy,e=t.projection.rotate(),a=t.projection.scale(),u=n.scale.linear().domain([-1*a,a]).range([-90,90]),c=u(o),s=u(i);e[0]+=c,e[1]-=s,e[1]>90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l.call(t)});n.select(t.canvas).call(o)})}},c});
|
||||
/*! Planetary.js 1.1.3 | (c) 2013 Michelle Tilley | Released under MIT License */
|
||||
!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],function(o,e){return n.planetaryjs=t(o,e,n)}):"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(){if(t.stopped)return!0;t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<e.onDraw.length;n++)e.onDraw[n]()})},l=function(n,t){for(var o=i.length-1;o>=0;o--)t.unshift(i[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var e=0,i=function(n){var t=o.onInit[e];t.length?t(function(){e++,n()}):(t(),e++,setTimeout(n,0))},l=function(){e>=o.onInit.length?r(n,t,o):i(l)};i(l)}else r(n,t,o)},u=function(n,t,o,e){n.canvas=t,n.context=t.getContext("2d"),n.stopped!==!0&&l(n,o),n.stopped=!1,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:[],onStop:[]},e={plugins:{},draw:function(n){u(e,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},onStop:function(n){o.onStop.push(n)},loadPlugin:function(n){t.push(n)},stop:function(){e.stopped=!0;for(var n=0;n<o.onStop.length;n++)o.onStop[n](e)},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),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;l<o.length;l++){var a=o[l],u=e-a.time;u<a.options.ttl&&(i.push(a),r(n,t,e,u,a))}o=i},r=function(t,o,e,i,r){var l=1-i/r.options.ttl,a=n.rgb(r.options.color);a="rgba("+a.r+","+a.g+","+a.b+","+l+")",o.strokeStyle=a;var u=n.geo.circle().origin([r.lng,r.lat]).angle(i/r.options.ttl*r.options.angle)();o.beginPath(),t.path.context(o)(u),o.stroke()};return function(n){n.plugins.pings={add:e},n.onDraw(function(){var t=new Date;n.withSavedContext(function(o){i(n,o,t)})})}},c.plugins.zoom=function(t){t=t||{};var o=function(){},e=t.onZoomStart||o,i=t.onZoomEnd||o,r=t.onZoom||o,l=t.afterZoom||o,a=t.initialScale,u=t.scaleExtent||[50,2e3];return function(t){t.onInit(function(){var o=n.behavior.zoom().scaleExtent(u);null!==a&&void 0!==a?o.scale(a):o.scale(t.projection.scale()),o.on("zoomstart",e.bind(t)).on("zoomend",i.bind(t)).on("zoom",function(){r.call(t),t.projection.scale(n.event.scale),l.call(t)}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){t=t||{};var o=function(){},e=t.onDragStart||o,i=t.onDragEnd||o,r=t.onDrag||o,l=t.afterDrag||o;return function(t){t.onInit(function(){var o=n.behavior.drag().on("dragstart",e.bind(t)).on("dragend",i.bind(t)).on("drag",function(){r.call(t);var o=n.event.dx,e=n.event.dy,i=t.projection.rotate(),a=t.projection.scale(),u=n.scale.linear().domain([-1*a,a]).range([-90,90]),c=u(o),s=u(e);i[0]+=c,i[1]-=s,i[1]>90&&(i[1]=90),i[1]<-90&&(i[1]=-90),i[0]>=180&&(i[0]-=360),t.projection.rotate(i),l.call(t)});n.select(t.canvas).call(o)})}},c});
|
||||
16
gulpfile.js
16
gulpfile.js
@ -7,14 +7,15 @@ var jshint = require('gulp-jshint');
|
||||
var replace = require('gulp-replace');
|
||||
var metadata = require('./package.json');
|
||||
|
||||
var shortHeader = "/*! Planetary.js {{version}} | (c) 2013 Brandon Tilley | Released under MIT License */"
|
||||
var shortHeader = "/*! Planetary.js <%= version %> | (c) 2013 Michelle Tilley | Released under MIT License */\n"
|
||||
var fullHeader = [
|
||||
"/*! Planetary.js v{{version}}",
|
||||
" * Copyright (c) 2013 Brandon Tilley",
|
||||
"/*! Planetary.js v<%= version %>",
|
||||
" * Copyright (c) 2013 Michelle Tilley",
|
||||
" *",
|
||||
" * Released under the MIT license",
|
||||
" * Date: {{now}}",
|
||||
" */"
|
||||
" * Date: <%= new Date().toISOString() %>",
|
||||
" */",
|
||||
""
|
||||
].join("\n");
|
||||
|
||||
var fullSource = gulp.src(['./src/_umd_header.js', './src/body.js', './src/plugins.js', './src/_umd_footer.js']);
|
||||
@ -42,7 +43,4 @@ gulp.task('build', function() {
|
||||
gulp.src('./src/world-110m.json').pipe(gulp.dest('./dist'));
|
||||
});
|
||||
|
||||
gulp.task('default', function() {
|
||||
gulp.run('jshint');
|
||||
gulp.run('build');
|
||||
});
|
||||
gulp.task('default', ['jshint', 'build']);
|
||||
|
||||
4222
package-lock.json
generated
Normal file
4222
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planetary.js",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.3",
|
||||
"description": "Awesome interactive globes for the web",
|
||||
"main": "dist/planetaryjs",
|
||||
"scripts": {
|
||||
@ -12,24 +12,24 @@
|
||||
"type": "git",
|
||||
"url": "git://github.com/BinaryMuse/planetary.js.git"
|
||||
},
|
||||
"author": "Brandon Tilley <brandon@brandontilley.com>",
|
||||
"author": "Michelle Tilley <michelle@michelletilley.net>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/BinaryMuse/planetary.js/issues"
|
||||
},
|
||||
"homepage": "http://planetaryjs.com",
|
||||
"devDependencies": {
|
||||
"gulp": "~3.2.0",
|
||||
"gulp": "~3.6.2",
|
||||
"gulp-concat": "BinaryMuse/gulp-concat",
|
||||
"gulp-header": "~0.4.0",
|
||||
"gulp-uglify": "~0.1.0",
|
||||
"gulp-rename": "~0.2.1",
|
||||
"gulp-header": "~1.0.2",
|
||||
"gulp-uglify": "~0.3.0",
|
||||
"gulp-rename": "~1.2.0",
|
||||
"bower": "~1.2.8",
|
||||
"gulp-jshint": "~1.3.1",
|
||||
"gulp-replace": "~0.2.0"
|
||||
"gulp-jshint": "~1.6.1",
|
||||
"gulp-replace": "~0.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"topojson": ">=1.4.6",
|
||||
"d3": ">=3.3.13"
|
||||
"topojson": "^1.4.6",
|
||||
"d3": "^3.3.13"
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
"start": "harp server",
|
||||
"compile": "harp compile"
|
||||
},
|
||||
"author": "Brandon Tilley <brandon@brandontilley.com>",
|
||||
"author": "Michelle Tilley <michelle@michelletilley.net>",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
||||
@ -94,6 +94,24 @@ planet.onDraw(function() {
|
||||
```
|
||||
</div>
|
||||
|
||||
**`planet.onStop( function(){} )`**
|
||||
|
||||
Registers a function to be called when the planet is stopped with the `stop` method. This can be used to clean up timers and remove references to internal planet properties and plugins, if necessary, so that it can be property garbage collected.
|
||||
|
||||
<div class='ui raised segment'>
|
||||
<div class='ui red ribbon label'>JavaScript</div>
|
||||
|
||||
```javascript
|
||||
var interval = setInterval(function() {
|
||||
addRandomPing(planet); // uses `planet.plugins.pings`
|
||||
}, 150);
|
||||
|
||||
planet.onStop(function() {
|
||||
clearInterval(interval);
|
||||
});
|
||||
```
|
||||
</div>
|
||||
|
||||
**`planet.withSavedContext( function(context){} )`**
|
||||
|
||||
Calls the function with the current canvas context as a parameter, wrapping the function call in `context.save()` and `context.restore()`. Use this function any time you're going to modify the context to ensure it gets put back to the way it was.
|
||||
@ -119,7 +137,7 @@ Begins drawing the globe onto the given canvas. `canvas` should be a raw DOM ele
|
||||
|
||||
Calling `draw` will perform the following operations:
|
||||
|
||||
1. Initialize each loaded plugin by calling the plugin function.
|
||||
1. Initialize each loaded plugin by calling the plugin function (note: this only happens the first time you call `draw`).
|
||||
2. Set `planet.canvas` and `planet.context` to the canvas and the canvas' context, respectively.
|
||||
3. Run each registered `onInit` hook in the order it was registered (note that `onInit` calls made by plugins will not be made until step 1, after `draw` has been called).
|
||||
4. Start the animation loop, each tick clearing the canvas and calling any registered `onDraw` hooks in order.
|
||||
@ -138,3 +156,21 @@ var canvas = document.getElementById('myCanvas');
|
||||
planet.draw(canvas);
|
||||
```
|
||||
</div>
|
||||
|
||||
Once you've called `draw()` on a planet, you should not call it again unless you first call `stop()`.
|
||||
|
||||
**`planet.stop()`**
|
||||
|
||||
Stop drawing the planet to the canvas. This disables the internal draw loop. You can register functions to call when the planet is stopped using the `onStop` method; if you don't plan on reusing the planet, be sure to clean up timers and references to internal properties, if necessary, so that it can be garbage collected.
|
||||
|
||||
You can draw the planet to a new (or the same) canvas using the `draw` method as normal. All your plugins' `onInit` functions will fire, although the plugin function itself will not be called again.
|
||||
|
||||
Keep in mind that, since the internal draw loop is stopped, your plugins' `onDraw` functions are not being called. If you have timers or other mechanisms that continually push data into a data structure that an `onDraw` method cleans up, you should disable or pause it.
|
||||
|
||||
<div class='ui raised segment'>
|
||||
<div class='ui red ribbon label'>JavaScript</div>
|
||||
|
||||
```javascript
|
||||
planet.stop();
|
||||
```
|
||||
</div>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"stable": {
|
||||
"latest": {
|
||||
"version": "v1.0.2"
|
||||
"version": "v1.1.2"
|
||||
}
|
||||
},
|
||||
"unstable": {
|
||||
|
||||
@ -92,7 +92,7 @@
|
||||
Source Code
|
||||
</a>
|
||||
<p class='section-description'>Take a look at the source on GitHub and contribute to the project</p>
|
||||
<p><a class='ui purple button' href='https://github.com/BinaryMuse/planetary.js' onclick="_gaq.push(['_trackPageview', '/redirect-to-github-project-page']);>Examine the Source</a></p>
|
||||
<p><a class='ui purple button' href='https://github.com/BinaryMuse/planetary.js' onclick="_gaq.push(['_trackPageview', '/redirect-to-github-project-page']);">Examine the Source</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
4
site/public/js/lib/planetaryjs.min.js
vendored
4
site/public/js/lib/planetaryjs.min.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! Planetary.js 1.0.2 | (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 i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<i.onDraw.length;n++)i.onDraw[n]()})},l=function(n,t){for(var o=e.length-1;o>=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var i=0,e=function(n){var t=o.onInit[i];t.length?t(function(){i++,n()}):(t(),i++,setTimeout(n,0))},l=function(){i>=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},c={plugins:{},noConflict:function(){return o.planetaryjs=i,c},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){u(i,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 i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},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 i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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 i=null,e={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";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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||{},i=n.land||{},e=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(i)(n),c.plugins.borders(e)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l<o.length;l++){var a=o[l],u=i-a.time;u<a.options.ttl&&(e.push(a),r(n,t,i,u,a))}o=e},r=function(t,o,i,e,r){var l=1-e/r.options.ttl,a=n.rgb(r.options.color);a="rgba("+a.r+","+a.g+","+a.b+","+l+")",o.strokeStyle=a;var u=n.geo.circle().origin([r.lng,r.lat]).angle(e/r.options.ttl*r.options.angle)();o.beginPath(),t.path.context(o)(u),o.stroke()};return function(n){n.plugins.pings={add:i},n.onDraw(function(){var t=new Date;n.withSavedContext(function(o){e(n,o,t)})})}},c.plugins.zoom=function(t){t=t||{};var o=function(){},i=t.onZoomStart||o,e=t.onZoomEnd||o,r=t.onZoom||o,l=t.afterZoom||o,a=t.initialScale,u=t.scaleExtent||[50,2e3];return function(t){t.onInit(function(){var o=n.behavior.zoom().scaleExtent(u);o.scale(null!==a&&void 0!==a?a:t.projection.scale()),o.on("zoomstart",i.bind(t)).on("zoomend",e.bind(t)).on("zoom",function(){r.call(t),t.projection.scale(n.event.scale),l.call(t)}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){t=t||{};var o=function(){},i=t.onDragStart||o,e=t.onDragEnd||o,r=t.onDrag||o,l=t.afterDrag||o;return function(t){t.onInit(function(){var o=n.behavior.drag().on("dragstart",i.bind(t)).on("dragend",e.bind(t)).on("drag",function(){r.call(t);var o=n.event.dx,i=n.event.dy,e=t.projection.rotate(),a=t.projection.scale(),u=n.scale.linear().domain([-1*a,a]).range([-90,90]),c=u(o),s=u(i);e[0]+=c,e[1]-=s,e[1]>90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l.call(t)});n.select(t.canvas).call(o)})}},c});
|
||||
/*! Planetary.js 1.1.2 | (c) 2013 Michelle Tilley | Released under MIT License */
|
||||
!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],function(o,i){return n.planetaryjs=t(o,i,n)}):"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 i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){if(t.stopped)return!0;t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<i.onDraw.length;n++)i.onDraw[n]()})},l=function(n,t){for(var o=e.length-1;o>=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var i=0,e=function(n){var t=o.onInit[i];t.length?t(function(){i++,n()}):(t(),i++,setTimeout(n,0))},l=function(){i>=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){n.canvas=t,n.context=t.getContext("2d"),n.stopped!==!0&&l(n,o),n.stopped=!1,a(n,t,i)},c={plugins:{},noConflict:function(){return o.planetaryjs=i,c},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[],onStop:[]},i={plugins:{},draw:function(n){u(i,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},onStop:function(n){o.onStop.push(n)},loadPlugin:function(n){t.push(n)},stop:function(){i.stopped=!0;for(var n=0;n<o.onStop.length;n++)o.onStop[n](i)},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 i.projection=n.geo.orthographic().clipAngle(90),i.path=n.geo.path().projection(i.projection),i}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},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 i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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 i=null,e={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";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),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||{},i=n.land||{},e=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(i)(n),c.plugins.borders(e)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l<o.length;l++){var a=o[l],u=i-a.time;u<a.options.ttl&&(e.push(a),r(n,t,i,u,a))}o=e},r=function(t,o,i,e,r){var l=1-e/r.options.ttl,a=n.rgb(r.options.color);a="rgba("+a.r+","+a.g+","+a.b+","+l+")",o.strokeStyle=a;var u=n.geo.circle().origin([r.lng,r.lat]).angle(e/r.options.ttl*r.options.angle)();o.beginPath(),t.path.context(o)(u),o.stroke()};return function(n){n.plugins.pings={add:i},n.onDraw(function(){var t=new Date;n.withSavedContext(function(o){e(n,o,t)})})}},c.plugins.zoom=function(t){t=t||{};var o=function(){},i=t.onZoomStart||o,e=t.onZoomEnd||o,r=t.onZoom||o,l=t.afterZoom||o,a=t.initialScale,u=t.scaleExtent||[50,2e3];return function(t){t.onInit(function(){var o=n.behavior.zoom().scaleExtent(u);o.scale(null!==a&&void 0!==a?a:t.projection.scale()),o.on("zoomstart",i.bind(t)).on("zoomend",e.bind(t)).on("zoom",function(){r.call(t),t.projection.scale(n.event.scale),l.call(t)}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){t=t||{};var o=function(){},i=t.onDragStart||o,e=t.onDragEnd||o,r=t.onDrag||o,l=t.afterDrag||o;return function(t){t.onInit(function(){var o=n.behavior.drag().on("dragstart",i.bind(t)).on("dragend",e.bind(t)).on("drag",function(){r.call(t);var o=n.event.dx,i=n.event.dy,e=t.projection.rotate(),a=t.projection.scale(),u=n.scale.linear().domain([-1*a,a]).range([-90,90]),c=u(o),s=u(i);e[0]+=c,e[1]-=s,e[1]>90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l.call(t)});n.select(t.canvas).call(o)})}},c});
|
||||
@ -1,6 +1,8 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['d3', 'topojson'], factory);
|
||||
define(['d3', 'topojson'], function(d3, topojson) {
|
||||
return (root.planetaryjs = factory(d3, topojson, root));
|
||||
});
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory(require('d3'), require('topojson'));
|
||||
} else {
|
||||
|
||||
28
src/body.js
28
src/body.js
@ -4,6 +4,10 @@
|
||||
|
||||
var doDrawLoop = function(planet, canvas, hooks) {
|
||||
d3.timer(function() {
|
||||
if (planet.stopped) {
|
||||
return true;
|
||||
}
|
||||
|
||||
planet.context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
for (var i = 0; i < hooks.onDraw.length; i++) {
|
||||
hooks.onDraw[i]();
|
||||
@ -59,11 +63,14 @@
|
||||
};
|
||||
|
||||
var startDraw = function(planet, canvas, localPlugins, hooks) {
|
||||
initPlugins(planet, localPlugins);
|
||||
|
||||
planet.canvas = canvas;
|
||||
planet.context = canvas.getContext('2d');
|
||||
|
||||
if (planet.stopped !== true) {
|
||||
initPlugins(planet, localPlugins);
|
||||
}
|
||||
|
||||
planet.stopped = false;
|
||||
runOnInitHooks(planet, canvas, hooks);
|
||||
};
|
||||
|
||||
@ -83,7 +90,8 @@
|
||||
var localPlugins = [];
|
||||
var hooks = {
|
||||
onInit: [],
|
||||
onDraw: []
|
||||
onDraw: [],
|
||||
onStop: []
|
||||
};
|
||||
|
||||
var planet = {
|
||||
@ -101,10 +109,21 @@
|
||||
hooks.onDraw.push(fn);
|
||||
},
|
||||
|
||||
onStop: function(fn) {
|
||||
hooks.onStop.push(fn);
|
||||
},
|
||||
|
||||
loadPlugin: function(plugin) {
|
||||
localPlugins.push(plugin);
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
planet.stopped = true;
|
||||
for (var i = 0; i < hooks.onStop.length; i++) {
|
||||
hooks.onStop[i](planet);
|
||||
}
|
||||
},
|
||||
|
||||
withSavedContext: function(fn) {
|
||||
if (!this.context) {
|
||||
throw new Error("No canvas to fetch context for");
|
||||
@ -117,8 +136,7 @@
|
||||
};
|
||||
|
||||
planet.projection = d3.geo.orthographic()
|
||||
.clipAngle(90)
|
||||
.precision(0);
|
||||
.clipAngle(90);
|
||||
planet.path = d3.geo.path().projection(planet.projection);
|
||||
|
||||
return planet;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user