Skip to content

Instantly share code, notes, and snippets.

@jbwhit
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbwhit/d03db0ca560da7c445f7 to your computer and use it in GitHub Desktop.
Save jbwhit/d03db0ca560da7c445f7 to your computer and use it in GitHub Desktop.
Jonathan Whitmore's Life Trajectory (so far)
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #fff;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #bbb;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.points circle {
fill: #fff;
stroke: red;
stroke-width: 2px;
}
.points text {
font: 11px sans-serif;
text-anchor: middle;
text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.route {
fill: none;
stroke: red;
stroke-width: 3px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 570;
var places = {
London: [+0.1275, +51.5072],
Miami: [-80.2241, +25.7877],
Dallas: [-97.0381, +32.8969],
Nashville: [-86.7833, +36.1667],
SanDiego: [-117.1625, +32.7150],
Melbourne: [+144.8433, -37.6733],
SiliconValley: [-122.3750, +37.6189],
};
var route = {
type: "LineString",
coordinates: [
places.London,
places.Miami,
places.Dallas,
places.Nashville,
places.SanDiego,
places.Melbourne,
places.SiliconValley
]
};
var projection = d3.geo.kavrayskiy7()
.scale(170)
// .rotate([-40, 0])
.rotate([100, 0])
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
svg.append("path")
.datum(route)
.attr("class", "route")
.attr("d", path);
var point = svg.append("g")
.attr("class", "points")
.selectAll("g")
.data(d3.entries(places))
.enter().append("g")
.attr("transform", function(d) { return "translate(" + projection(d.value) + ")"; });
point.append("circle")
.attr("r", 4.5);
point.append("text")
.attr("y", 10)
.attr("dy", ".71em")
.text(function(d) { return d.key; });
d3.json("/mbostock/raw/4090846/world-50m.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
});
d3.select(self.frameElement).style("height", height + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment