Skip to content

Instantly share code, notes, and snippets.

@enjalot
Last active November 2, 2015 22:12
Show Gist options
  • Save enjalot/6281f8a4ef5967c74ebe to your computer and use it in GitHub Desktop.
Save enjalot/6281f8a4ef5967c74ebe to your computer and use it in GitHub Desktop.
Country Code Lookup
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
pre { width: 100%; height: 100%; font-size: 10px; overflow-y: scroll; }
</style>
</head>
<body>
<pre id="json">
</pre>
<script>
function makeLookup(data) {
var lookup = {};
data.forEach(function(d) {
lookup[d.iso2] = d;
});
return lookup;
}
d3.csv("http://enjalot.github.io/migrants/countries.csv", function(err, countries) {
console.log("rawdata", countries);
var lookup = makeLookup(countries);
d3.select("#json").text(JSON.stringify(lookup, null, 2))
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment