Last active
August 25, 2016 09:56
-
-
Save ckothari/32149f15261b9c5c7a56c40f7f6b353d to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
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
iso lat long name | |
US 37.09024 -95.712891 United States | |
ZA -30.559482 22.937506 South Africa |
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> | |
path { | |
stroke: white; | |
stroke-width: 1px; | |
fill: #cbcbcb; | |
} | |
path.selected { | |
fill: steelblue; | |
} | |
circle { | |
fill: none; | |
stroke: red; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var projection = d3.geo.mercator() | |
.center([0, 5 ]) | |
.scale(150); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var path = d3.geo.path() | |
.projection(projection); | |
var g = svg.append("g"); | |
var zoomMap = d3.behavior.zoom() | |
.on("zoom",function() { | |
g.attr("transform","translate("+ | |
d3.event.translate.join(",")+")scale("+d3.event.scale+")"); | |
g.selectAll("path") | |
.attr("d", path.projection(projection)); | |
}); | |
this.svg.call(zoomMap); | |
function drawNodes(){ | |
d3.tsv('data.csv', function(data){ | |
g.selectAll('path') | |
.filter(function(d){ | |
return data.find(function(d1){ | |
return d1.iso == d.properties.iso_a2; | |
}) | |
}) | |
.attr('class', 'selected'); | |
g.append('g') | |
.selectAll("circle") | |
.data(data) | |
.enter() | |
.append("a") | |
.append("circle") | |
.attr("cx", function(d) { | |
return projection([d.long, d.lat])[0]; | |
}) | |
.attr("r", function(d){ | |
return 5; | |
}) | |
.attr("cy", function(d) { | |
return projection([d.long, d.lat])[1]; | |
}) | |
.transition() | |
.duration(750) | |
.delay(function(d, i) {return i * 100; }) | |
.each(pulse); | |
// Ref: http://bl.ocks.org/chiester/11267307 | |
function pulse() { | |
var circle = d3.select(this); | |
(function repeat() { | |
circle = circle.transition() | |
.attr("r", 2) | |
.transition() | |
.attr("r", 10) | |
.ease('linear') | |
.each("end", repeat); | |
})(); | |
} | |
}) | |
} | |
d3.json("world-map-new.json", function(error, topology) { | |
g.selectAll("path") | |
.data(topojson.object(topology, topology.objects.subunits).geometries) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.attr('class', 'feature'); | |
drawNodes(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment