Update site

This commit is contained in:
Brandon Tilley 2013-12-21 12:10:12 -08:00
parent ac6efe21f8
commit b021e5789e
7 changed files with 80 additions and 111 deletions

View File

@ -1 +1 @@
html,body{font-size:15px;font-family:"Open Sans","Helvetica Neue","Helvetica","Arial",sans-serif}body{margin:0;padding:0}h1,h2,h3,h4,h5,h6{font-family:"Source Sans Pro","Helvetica Neue","Helvetica","Arial",sans-serif}h1.subheader,h2.subheader,h3.subheader,h4.subheader,h5.subheader,h6.subheader{font-weight:300}h1.title-header,h2.title-header{margin-top:0px;margin-bottom:10px}.content.container{padding-top:50px}.centered{text-align:center}.feature-list{font-size:17px}.feature-list .icon{margin-right:5px !important}a.ui.icon.header{text-decoration:none;color:black}a.ui.icon.header:hover{color:blue}.divider .icon.huge{font-size:2em}.footer .text{text-align:center}canvas{width:350px;height:350px}@media screen and (max-width:768px){.hide-on-mobile{display:none !important}.ui.grid>.eight.wide.column{width:auto !important;min-width:100%}}@media screen and (min-width:769px){.hide-on-non-mobile{display:none !important}.main-menu{padding-left:8%}}.spacer{display:inline-block;width:50px}.ui.large.menu .item.minor{font-size:14px}.homepage-globe-canvas{text-align:right}@media screen and (max-width:998px){.homepage-globe-canvas{text-align:center}}
html,body{font-size:15px;font-family:"Open Sans","Helvetica Neue","Helvetica","Arial",sans-serif}body{margin:0;padding:0}h1,h2,h3,h4,h5,h6{font-family:"Source Sans Pro","Helvetica Neue","Helvetica","Arial",sans-serif}h1.subheader,h2.subheader,h3.subheader,h4.subheader,h5.subheader,h6.subheader{font-weight:300}h1.title-header,h2.title-header{margin-top:0px;margin-bottom:10px}.content.container{padding-top:50px}.centered{text-align:center}.feature-list{font-size:17px}.feature-list .icon{margin-right:5px !important}a.ui.icon.header{text-decoration:none;color:black}a.ui.icon.header:hover{color:blue}.divider .icon.huge{font-size:2em}.footer .text{text-align:center}canvas{width:350px;height:350px}@media screen and (max-width:768px){.hide-on-mobile{display:none !important}.ui.grid>.eight.wide.column{width:auto !important;min-width:100%}}@media screen and (min-width:769px){.hide-on-non-mobile{display:none !important}.main-menu{padding-left:8%}}.spacer{display:inline-block;width:50px}.ui.large.menu .item.minor{font-size:14px}.homepage-globe-canvas{text-align:right}@media screen and (max-width:998px){.homepage-globe-canvas{text-align:center}}.no-underline{text-decoration:none}

View File

@ -5,8 +5,6 @@
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Open+Sans:300italic,400,300,700' rel='stylesheet' type='text/css'>
<link type="text/css" rel="stylesheet" href="semantic/css/semantic.min.css">
<link type="text/css" rel="stylesheet" href="css/planetaryjs.css">
<script type='text/javascript' src="js/d3.v3.min.js"></script>
<script type='text/javascript' src="js/topojson.v1.min.js"></script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@ -18,7 +16,7 @@
<i class='globe icon'></i>Planetary.js
</a>
<span class='spacer hide-on-mobile'></span>
<a class='item minor' href='download.html'>
<a class='item minor' href='https://github.com/BinaryMuse/planetary.js/releases'>
<i class='download icon'></i><span class='hide-on-mobile'>Download</span>
</a>
<a class='item minor' href='examples.html'>
@ -62,7 +60,7 @@
</div>
<div class='ui buttons'>
<a class='ui green labeled icon button' href='download.html'><i class='icon download'></i>Download</a>
<a class='ui green labeled icon button' href='https://github.com/BinaryMuse/planetary.js/releases'><i class='icon download'></i>Download</a>
<div class='or'></div>
<a class='ui labeled button' href='https://github.com/BinaryMuse/planetary.js'>View Source</a>
</div>
@ -70,18 +68,18 @@
<div class='eight wide column left floated'>
<div class='ui panel homepage-globe-canvas'>
<canvas height='350' width='350' style="width: 350px; height: 350px;" id="homepage-globe-canvas"></canvas>
<div style="width: 350px; text-align: center; display: inline-block;">
<div class='ui pointing label'>
<a href='https://github.com/BinaryMuse/planetary.js/blob/master/site/public/js/homepage.js'
class='detail no-underline'><i class='icon code'></i> View the source for this example</a>
</div>
</div>
</div>
</div>
</div>
<!-- <div class='ui page grid center aligned'> -->
<!-- <div class='sixteen wide column center aligned'> -->
<!-- <h1>Explore Further</h1> -->
<!-- </div> -->
<!-- </div> -->
<div class='ui page grid'>
<div class='sixteen wide column'>
<div class='ui horizontal divider'>
@ -126,6 +124,9 @@
</div>
</div>
<script type="text/javascript" src="js/planetaryjs.js"></script>
<script type='text/javascript' src="js/lib/d3.v3.min.js"></script>
<script type='text/javascript' src="js/lib/topojson.v1.min.js"></script>
<script type="text/javascript" src="js/lib/planetaryjs.min.js"></script>
<script type="text/javascript" src="js/homepage.js"></script>
</body>
</html>

64
js/homepage.js Normal file
View File

@ -0,0 +1,64 @@
(function() {
var globe = planetaryjs.planet();
// The `earth` plugin draws the oceans and the land; it's actually
// a combination of several separate built-in plugins.
globe.loadPlugin(planetaryjs.plugins.earth({
topojson: { file: 'world-110m.json' },
oceans: { fill: '#000080' },
land: { fill: '#339966' },
borders: { stroke: '#008000' }
}));
// The `pings` plugin draws animated pings on the globe.
globe.loadPlugin(planetaryjs.plugins.pings());
// Load our custom `autorotate` plugin; see below.
globe.loadPlugin(autorotate(10));
// Set up the globe's initial scale, offset, and rotation.
globe.projection.scale(175).translate([175, 175]).rotate([0, -10, 0]);
// Every few hundred milliseconds, we'll draw another random ping.
var colors = ['red', 'yellow', 'white', 'orange', 'purple', 'cyan'];
setInterval(function() {
var lat = Math.random() * 170 - 85;
var lng = Math.random() * 360 - 180;
var color = colors[Math.floor(Math.random() * colors.length)];
globe.addPing(lat, lng, { color: color, ttl: 2000, angle: Math.random() * 10 });
}, 250);
var canvas = document.getElementById('homepage-globe-canvas');
// Special code to handle high-density displays (e.g. retina, some phones)
// In the future, Planetary.js will handle this by itself (or via a plugin).
if (window.devicePixelRatio == 2) {
canvas.width = 700;
canvas.height = 700;
context = canvas.getContext('2d');
context.scale(2, 2);
}
// Draw that globe!
globe.draw(canvas);
// This plugin will automatically rotate the globe around its vertical
// axis a configured number of degrees every second.
function autorotate(degPerSec) {
// Planetary.js plugins are functions that take a `planet` instance
// as an argument...
return function(planet) {
var lastTick = null;
// ...and configure hooks into certain pieces of its lifecycle.
planet.onDraw(function() {
if (!lastTick) {
lastTick = new Date();
} else {
var now = new Date();
var delta = now - lastTick;
// This plugin uses the built-in projection (provided by D3)
// to rotate the globe each time we draw it.
var rotation = planet.projection.rotate();
rotation[0] += degPerSec * delta / 1000;
if (rotation[0] >= 180) rotation[0] -= 360;
planet.projection.rotate(rotation);
lastTick = now;
}
});
};
};
})();

2
js/lib/planetaryjs.min.js vendored Normal file
View File

@ -0,0 +1,2 @@
/*! Planetary.js 0.0.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<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)},u=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)},a=function(n,t,o,e){l(n,o),n.canvas=t,n.context=t.getContext("2d"),u(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={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 c.plugins.topojson=function(t){return function(o){o.onInit(function(e){if(t.world)o.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.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(),0!=n.stroke&&(o.strokeStyle=n.stroke,o.stroke())})})}},c.plugins.land=function(n){return function(o){var e=null;o.onInit(function(){e=t.feature(o.world,o.world.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&&(t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var e=null;o.onInit(function(){var n=o.world.objects.countries;e=t.mesh(o.world,n,function(n,t){return n.id!==t.id})}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(e),t.strokeStyle=n.stroke||"gray",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(){var t=[],o=function(n,o,e){var e=e||{};e.color=e.color||"white",e.ttl=e.ttl||2e3,e.angle=e.angle||5,t.push({lat:n,lng:o,time:new Date,options:e})},e=function(n,o,e){for(var r=[],l=0;l<t.length;l++){var u=t[l],a=e-u.time;a<=u.options.ttl&&(r.push(u),i(n,o,e,u))}t=r},i=function(t,o,e,i){var r=e-i.time,l=1-r/i.options.ttl,u=n.rgb(i.options.color);u="rgba("+u.r+","+u.g+","+u.b+","+l+")",o.strokeStyle=u;var a=n.geo.circle().origin([i.lng,i.lat]).angle(r/i.options.ttl*i.options.angle)();o.beginPath(),t.path.context(o)(a),o.stroke()};return function(n){n.addPing=o,n.onDraw(function(){var t=new Date;n.withSavedContext(function(o){e(n,o,t)})})}},c});

View File

@ -1,98 +0,0 @@
var addPing, canvas, path, pings, projection, zoom;
projection = d3.geo.orthographic().scale(175).translate([175, 175]).clipAngle(90).precision(0);
zoom = d3.behavior.zoom().scale(projection.scale()).scaleExtent([50, 500]).on('zoom', function() {
return projection.scale(d3.event.scale);
});
canvas = d3.select('.homepage-globe-canvas').selectAll('canvas').data(d3.range(1)).enter().append('canvas').attr('width', 350).attr('height', 350).call(function(canvas) {
var context;
if (window.devicePixelRatio === 2) {
canvas[0][0].width = 700;
canvas[0][0].height = 700;
context = canvas[0][0].getContext('2d');
return context.scale(2, 2);
}
});
path = d3.geo.path().projection(projection);
pings = [];
addPing = function(pos) {
return pings.push({
pos: pos,
time: Date.now()
});
};
setInterval((function() {
var lat, lng;
lat = Math.random() * 180 - 90;
lng = Math.random() * 360 - 180;
return addPing([lat, lng]);
}), 300);
d3.json("world-110m.json", function(error, world) {
var borders, globe, land, lastRotation, rotate, velocity;
land = topojson.feature(world, world.objects.land);
borders = topojson.mesh(world, world.objects.countries, function(a, b) {
return a.id !== b.id;
});
globe = {
type: "Sphere"
};
lastRotation = Date.now();
rotate = [0, -5, 0];
velocity = -0.50;
return d3.timer(function() {
canvas.each(function(i) {
var alpha, circle, context, currentTime, difference, now, ping, _i, _len;
now = Date.now();
difference = now - lastRotation;
lastRotation = now;
rotate[i] -= velocity * difference / 100;
context = this.getContext('2d');
projection.rotate(rotate);
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
context.beginPath();
path(globe);
context.fillStyle = '#000080';
context.fill();
context.beginPath();
context.fillStyle = '#339966';
path.context(context)(land);
context.fill();
context.strokeStyle = '#008000';
context.beginPath();
path.context(context)(borders);
context.stroke();
context.strokeStyle = '#fff';
context.lineWidth = 1;
currentTime = Date.now();
for (_i = 0, _len = pings.length; _i < _len; _i++) {
ping = pings[_i];
difference = currentTime - ping.time;
alpha = 1 - (difference / 2000);
context.strokeStyle = "rgba(255,255,255," + alpha + ")";
circle = d3.geo.circle().origin(ping.pos).angle(difference / 500)();
context.beginPath();
path.context(context)(circle);
context.stroke();
}
return pings = (function() {
var _j, _len1, _results;
_results = [];
for (_j = 0, _len1 = pings.length; _j < _len1; _j++) {
ping = pings[_j];
if (currentTime - ping.time <= 2000) {
_results.push(ping);
}
}
return _results;
})();
});
return null;
});
});