Update site

This commit is contained in:
Brandon Tilley 2013-12-23 22:08:31 -08:00
parent 818e8cc554
commit 480a18602a
10 changed files with 40 additions and 26 deletions

View File

@ -92,6 +92,7 @@
<li><code>color</code>: the default color for pings; defaults to <code>&quot;white&quot;</code></li>
<li><code>ttl</code>: the default TTL for pings in milliseconds (how long they take to fade out); defaults to 2000</li>
<li><code>angle</code>: the maximum angle for the ping (it will grow to this size over the course of its TTL); defaults to <code>5</code></li>
<li><code>latitudeFirst</code>: reverse the order of the latitudinal and longitudinal coordinates passed to the <code>add</code> function (so that the latitudinal coordinate comes first); defaults to false. See the note on <code>add</code>, below, for more information.</li>
</ul>
<div class='ui raise segment'>
<div class='ui red ribbon label'>JavaScript</div>
@ -100,8 +101,15 @@
color: &#39;yellow&#39;, ttl: 5000, angle: 10
});</code></pre>
<p></div></p>
<p><strong><code>planet.plugins.pings.add(lat, lng, [config])</code></strong></p>
<p>Add a new ping to the globe at the latitudinal and longitudinal coordinates specified by <code>lat</code> and <code>lng</code>. <code>config</code> may take all the same keys as the configuration option for the plugin itself; any values will overwrite values from that object, if any were set.</p>
<p><strong><code>planet.plugins.pings.add(lng, lat, [config])</code></strong></p>
<p>Add a new ping to the globe at the longitudinal and latitudinal coordinates specified by <code>lng</code> and <code>lat</code>. Valid keys for <code>config</code> are:</p>
<ul>
<li><code>color</code>: the default color for pings; defaults to <code>&quot;white&quot;</code></li>
<li><code>ttl</code>: the default TTL for pings in milliseconds (how long they take to fade out); defaults to 2000</li>
<li><code>angle</code>: the maximum angle for the ping (it will grow to this size over the course of its TTL); defaults to <code>5</code></li>
</ul>
<p>Any values not set by <code>config</code> will default to the values specified in the plugin&#39;s configuration, if any were set.</p>
<p><strong>Note that the longitudinal coordinate comes first, followed by the latitudinal coordinate, unless you pass <code>latitudeFirst</code> as an option to the plugin configuration function.</strong> This corresponds to the conventions used by D3 (which Planetary.js is based on); for more information on the problem of axis ordering in software, see <a href="http://docs.geotools.org/latest/userguide/library/referencing/order.html">this article at the GeoTools web site</a>.</p>
<div class='ui raise segment'>
<div class='ui red ribbon label'>JavaScript</div>
@ -111,7 +119,7 @@ setInterval(function() {
var lng = Math.random() * 360 - 180;
var color = colors[Math.floor(Math.random() * colors.length)];
var angle = Math.random() * 10;
planet.plugins.pings.add(lat, lng, { color: color, ttl: 2000, angle: angle });
planet.plugins.pings.add(lng, lat, { color: color, ttl: 2000, angle: angle });
}, 250);</code></pre>
<p></div></p>

View File

@ -84,6 +84,12 @@
<div class='twelve wide column'>
<h1>FAQ</h1>
<p><strong>Q:</strong> Why are the pings I add from the <a href="/documentation/builtin_pings.html">Pings plugin</a> in the wrong place?</p>
<p><strong>A:</strong> Like D3 on which it is based, Planetary.js accepts coordinates with the longitudinal coordinate first. You can set the <code>latitudeFirst</code> option in the plugin configuration to change this. There is some additional discussion on the subject in the <a href="/documentation/builtin_pings.html">Pings plugin documentation</a>.</p>
<div class="ui horizontal icon divider">
<i class="globe icon"></i>
</div>
<p><strong>Q:</strong> Why can&#39;t I access my DOM element?</p>
<p><strong>A:</strong> Planetary.js provides no methods for DOM access or for waiting for the DOM ready event; you&#39;ll need to handle this on your own or use a third-party library.</p>
<div class="ui horizontal icon divider">

View File

@ -104,7 +104,7 @@ planet.loadPlugin(somePluginGenerator());</code></pre>
.rotate([60, -10, 0]);</code></pre>
<p></div></p>
<p><strong><code>planet.path</code></strong></p>
<p><code>planet.path</code> is a <a href="https://github.com/mbostock/d3/wiki/Geo-Paths"><code>d3.geo.path</code></a> which uses the planet&#39;s internal projection to generate path data for geographical features. Its <code>context</code> method is commonly used by interal plugins to take a canvas context and return a path generator that can be used to draw on the globe.</p>
<p><code>planet.path</code> is a <a href="https://github.com/mbostock/d3/wiki/Geo-Paths"><code>d3.geo.path</code></a> which uses the planet&#39;s internal projection to generate path data for geographical features. Its <code>context</code> method is commonly used by internal plugins to take a canvas context and return a path generator that can be used to draw on the globe.</p>
<div class='ui raise segment'>
<div class='ui red ribbon label'>JavaScript</div>
@ -145,7 +145,7 @@ planet.onInit(function(done) {
});</code></pre>
<p></div></p>
<p><strong><code>planet.withSavedContext( function(context){} )</code></strong></p>
<p>Calls the function with the current canvas context as a paremter, wrapping the function call in <code>context.save()</code> and <code>context.restore()</code>. Use this function any time you&#39;re going to modify the context to ensure it gets put back to the way it was.</p>
<p>Calls the function with the current canvas context as a parameter, wrapping the function call in <code>context.save()</code> and <code>context.restore()</code>. Use this function any time you&#39;re going to modify the context to ensure it gets put back to the way it was.</p>
<div class='ui raise segment'>
<div class='ui red ribbon label'>JavaScript</div>

View File

@ -48,7 +48,7 @@
<div class='ui blue ribbon label'>HTML</div>
<pre><code class='language-html'>&lt;canvas id='quakeCanvas'&gt;&lt;/canvas&gt;
&lt;h1&gt;Earthquakes: 2013&lt;/h1&gt;
&lt;ul id='magnitues'&gt;&lt;/ul&gt;
&lt;ul id='magnitudes'&gt;&lt;/ul&gt;
&lt;div id='controls'&gt;
&lt;div&gt;
@ -93,21 +93,21 @@
// Create a color scale for the various earthquake magnitudes; the
// mininum magnitude in our data set is 2.5.
// minimum magnitude in our data set is 2.5.
var colors = d3.scale.pow()
.exponent(2)
.domain([2, 6,10])
.range(['rgb(255,255,204)', 'rgb(253,141,60)','rgb(128,0,38)'])
.clamp(true);
// Also create a scale for mapping magnitues to ping angle sizes
// Also create a scale for mapping magnitudes to ping angle sizes
var angles = d3.scale.pow()
.exponent(2)
.domain([2.5, 10])
.range([0.5, 15])
.clamp(true);
// Create a key to show the magnitues and their colors
d3.select('#magnitues').selectAll('li')
// Create a key to show the magnitudes and their colors
d3.select('#magnitudes').selectAll('li')
.data(colors.ticks(9))
.enter()
.append('li')
@ -195,7 +195,7 @@
for (var i = 0; i &lt; toPing.length; i++) {
var ping = toPing[i];
planet.plugins.pings.add(ping.lat, ping.lng, {
planet.plugins.pings.add(ping.lng, ping.lat, {
// Here we use the `angles` and `colors` scales we built earlier
// to convert magnitudes to appropriate angles and colors.
angle: angles(ping.mag),

View File

@ -18,7 +18,7 @@
color: white;
}
ul#magnitues {
ul#magnitudes {
position: absolute;
top: 100px;
left: 30px;
@ -79,7 +79,7 @@
<canvas id='quakeCanvas'></canvas>
<h1>Earthquakes: 2013</h1>
<ul id='magnitues'></ul>
<ul id='magnitudes'></ul>
<div id='controls'>
<div>

View File

@ -30,21 +30,21 @@
// Create a color scale for the various earthquake magnitudes; the
// mininum magnitude in our data set is 2.5.
// minimum magnitude in our data set is 2.5.
var colors = d3.scale.pow()
.exponent(2)
.domain([2, 6,10])
.range(['rgb(255,255,204)', 'rgb(253,141,60)','rgb(128,0,38)'])
.clamp(true);
// Also create a scale for mapping magnitues to ping angle sizes
// Also create a scale for mapping magnitudes to ping angle sizes
var angles = d3.scale.pow()
.exponent(2)
.domain([2.5, 10])
.range([0.5, 15])
.clamp(true);
// Create a key to show the magnitues and their colors
d3.select('#magnitues').selectAll('li')
// Create a key to show the magnitudes and their colors
d3.select('#magnitudes').selectAll('li')
.data(colors.ticks(9))
.enter()
.append('li')
@ -132,7 +132,7 @@
for (var i = 0; i < toPing.length; i++) {
var ping = toPing[i];
planet.plugins.pings.add(ping.lat, ping.lng, {
planet.plugins.pings.add(ping.lng, ping.lat, {
// Here we use the `angles` and `colors` scales we built earlier
// to convert magnitudes to appropriate angles and colors.
angle: angles(ping.mag),

View File

@ -75,7 +75,7 @@
scaleExtent: [100, 300]
}));
globe.loadPlugin(planetaryjs.plugins.drag({
// Dragging the globe shoud pause the
// Dragging the globe should pause the
// automatic rotation until we release the mouse.
onDragStart: function() {
globe.plugins.autorotate.pause();
@ -93,7 +93,7 @@
var lat = Math.random() * 170 - 85;
var lng = Math.random() * 360 - 180;
var color = colors[Math.floor(Math.random() * colors.length)];
globe.plugins.pings.add(lat, lng, { color: color, ttl: 2000, angle: Math.random() * 10 });
globe.plugins.pings.add(lng, lat, { color: color, ttl: 2000, angle: Math.random() * 10 });
}, 250);
var canvas = document.getElementById('rotatingGlobe');

View File

@ -18,7 +18,7 @@
scaleExtent: [100, 300]
}));
globe.loadPlugin(planetaryjs.plugins.drag({
// Dragging the globe shoud pause the
// Dragging the globe should pause the
// automatic rotation until we release the mouse.
onDragStart: function() {
globe.plugins.autorotate.pause();
@ -36,7 +36,7 @@
var lat = Math.random() * 170 - 85;
var lng = Math.random() * 360 - 180;
var color = colors[Math.floor(Math.random() * colors.length)];
globe.plugins.pings.add(lat, lng, { color: color, ttl: 2000, angle: Math.random() * 10 });
globe.plugins.pings.add(lng, lat, { color: color, ttl: 2000, angle: Math.random() * 10 });
}, 250);
var canvas = document.getElementById('rotatingGlobe');

View File

@ -18,7 +18,7 @@
scaleExtent: [100, 300]
}));
globe.loadPlugin(planetaryjs.plugins.drag({
// Dragging the globe shoud pause the
// Dragging the globe should pause the
// automatic rotation until we release the mouse.
onDragStart: function() {
globe.plugins.autorotate.pause();
@ -36,7 +36,7 @@
var lat = Math.random() * 170 - 85;
var lng = Math.random() * 360 - 180;
var color = colors[Math.floor(Math.random() * colors.length)];
globe.plugins.pings.add(lat, lng, { color: color, ttl: 2000, angle: Math.random() * 10 });
globe.plugins.pings.add(lng, lat, { color: color, ttl: 2000, angle: Math.random() * 10 });
}, 250);
var canvas = document.getElementById('homepage-globe-canvas');

View File

@ -1,2 +1,2 @@
/*! Planetary.js 0.2.1 | (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]()})},l=function(n,t){for(var o=0;o<i.length;o++)t.unshift(i[o]);0==t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings()));for(var 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){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=[],e=function(n,e,i){var i=i||{};i.color=i.color||t.color||"white",i.ttl=i.ttl||t.ttl||2e3,i.angle=i.angle||t.angle||5,o.push({lat:n,lng:e,time:new Date,options:i})},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){var t=t||{},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);a?o.scale(a):o.scale(t.projection.scale()),o.on("zoomstart",e).on("zoomend",i).on("zoom",function(){r(),t.projection.scale(n.event.scale),l()}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){var t=t||{},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).on("dragend",i).on("drag",function(){r();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()});n.select(t.canvas).call(o)})}},c});
/*! Planetary.js 0.2.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]()})},l=function(n,t){for(var o=0;o<i.length;o++)t.unshift(i[o]);0==t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings()));for(var 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){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;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){var t=t||{},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);a?o.scale(a):o.scale(t.projection.scale()),o.on("zoomstart",e).on("zoomend",i).on("zoom",function(){r(),t.projection.scale(n.event.scale),l()}),n.select(t.canvas).call(o)})}},c.plugins.drag=function(t){var t=t||{},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).on("dragend",i).on("drag",function(){r();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()});n.select(t.canvas).call(o)})}},c});