|
<!DOCTYPE html> |
|
<meta charset="utf-8"> |
|
<style> |
|
|
|
body { |
|
font-size: 10px; |
|
font-family: sans-serif; |
|
font-weight: bold; |
|
text-anchor: left; |
|
} |
|
|
|
text { |
|
fill: #999; |
|
} |
|
|
|
.mesh { |
|
fill: none; |
|
stroke: #999; |
|
stroke-linejoin: round; |
|
} |
|
|
|
.country { |
|
fill: none; |
|
} |
|
|
|
.visited { |
|
fill: #8c96c6; |
|
opacity: 0.5; |
|
} |
|
|
|
.country-NLD { |
|
fill: #fe9929; |
|
opacity: 1; |
|
} |
|
</style> |
|
<body></body> |
|
<script src="https://d3js.org/d3.v4.min.js"></script> |
|
<script src='https://d3js.org/d3-queue.v2.min.js'></script> |
|
<script src="https://d3js.org/topojson.v1.min.js"></script> |
|
|
|
<script> |
|
var margin = {top: 10, right: 10, bottom: 10, left: 10}, |
|
width = 900 - margin.left - margin.right, |
|
height = 500 - margin.top - margin.bottom; |
|
|
|
var projection = d3.geoMercator() |
|
.translate([width / 2, height / 2]) |
|
.center([0, 25]) |
|
.scale(140); |
|
|
|
var path = d3.geoPath() |
|
.projection(projection); |
|
|
|
var svg = d3.select("body").append("svg") |
|
.attr("width", width + margin.left + margin.right) |
|
.attr("height", height + margin.top + margin.bottom) |
|
.append("g") |
|
.attr("class", "g-map") |
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
|
|
|
d3.queue() |
|
.defer(d3.json, "world-50m.json") |
|
.defer(d3.csv, "countries.csv") |
|
.await(ready); |
|
|
|
function ready(error, geo, countries) { |
|
if (error) return console.error(error); |
|
|
|
var visited = d3.entries(countries).map(function(d){ return d.value.code; }).slice(0, -1); |
|
|
|
svg.selectAll(".area") |
|
.data(topojson.feature(geo, geo.objects.ne_50m_admin_0_countries).features).enter() |
|
.append("path") |
|
.attr("class", function(d) { return "country country-" + d.id; }) |
|
.attr("d", path) |
|
.classed("visited", function(d) { return visited.indexOf(d.id) >= 0; }); |
|
|
|
svg.append("path") |
|
.datum(topojson.mesh(geo)) |
|
.attr("class", "mesh") |
|
.attr("d", path); |
|
|
|
svg.append("g").append("text") |
|
// .attr("dx", 0) |
|
.text(function() { return "Visited " + visited.length + " / " + geo.objects.ne_50m_admin_0_countries.geometries.length + " (" + |
|
d3.format(".0%")(visited.length / geo.objects.ne_50m_admin_0_countries.geometries.length, 2) + ")"; }); |
|
} |
|
</script> |