Last active
August 15, 2016 15:16
-
-
Save davidbradway/1aaa3c08c3cbbfc9c6560ac2f9d2c774 to your computer and use it in GitHub Desktop.
learning topojson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
/* CSS goes here. */ | |
.country { | |
fill: #ccc; | |
stroke: #fff; | |
stroke-width: .5px; | |
stroke-linejoin: round; | |
} | |
.graticule { | |
fill: none; | |
stroke: #000; | |
stroke-opacity: .3; | |
stroke-width: .5px; | |
} | |
.graticule.outline { | |
stroke: #333; | |
stroke-opacity: 1; | |
stroke-width: 1.5px; | |
} | |
</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> | |
/* JavaScript goes here. */ | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.kavrayskiy7(), | |
color = d3.scale.category20(), | |
graticule = d3.geo.graticule(); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.append("path") | |
.datum(graticule) | |
.attr("class", "graticule") | |
.attr("d", path); | |
svg.append("path") | |
.datum(graticule.outline) | |
.attr("class", "graticule outline") | |
.attr("d", path); | |
d3.json("countries.json", function(error, world) { | |
var countries = topojson.feature(world, world.objects).features, | |
neighbors = topojson.neighbors(world.objects.geometries); | |
svg.selectAll(".country") | |
.data(countries) | |
.enter().insert("path", ".graticule") | |
.attr("class", "country") | |
.attr("d", path) | |
.style("fill", function(d, i) { return color(d.color = d3.max(neighbors[i], function(n) { return countries[n].color; }) + 1 | 0); }); | |
}); | |
/* | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.kavrayskiy7(), | |
color = d3.scale.category20(), | |
graticule = d3.geo.graticule(); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
svg.append("path") | |
.datum(graticule) | |
.attr("class", "graticule") | |
.attr("d", path); | |
svg.append("path") | |
.datum(graticule.outline) | |
.attr("class", "graticule outline") | |
.attr("d", path); | |
d3.json("readme-world.json", function(error, world) { | |
var countries = topojson.feature(world, world.objects.countries).features, | |
neighbors = topojson.neighbors(world.objects.countries.geometries); | |
svg.selectAll(".country") | |
.data(countries) | |
.enter().insert("path", ".graticule") | |
.attr("class", "country") | |
.attr("d", path) | |
.style("fill", function(d, i) { return color(d.color = d3.max(neighbors[i], function(n) { return countries[n].color; }) + 1 | 0); }); | |
});*/ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment