Demo loading The Migrant Files data hosted via https://github.com/enjalot/migrants
Built with blockbuilder.org
forked from enjalot's block: The Migrant Files: Deaths
Demo loading The Migrant Files data hosted via https://github.com/enjalot/migrants
Built with blockbuilder.org
forked from enjalot's block: The Migrant Files: Deaths
| <!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 toNumber(s) { | |
| // convert strings with spaces instead of commas into numbers | |
| var n = s.replace(/[w]/g, "") //remove any whitespace | |
| .replace(/ /g, "") //utf8 space? | |
| return +n; //convert to number | |
| } | |
| function process(d) { | |
| var processed = { | |
| country: d.Country, | |
| year: +d.Year, | |
| cost: toNumber(d["Estimate of costs in 2014 EUR"]), | |
| forcedReturns: toNumber(d["Forced returns (1)"]), | |
| //the low estimate seems to be the only populated estimate | |
| deported: toNumber(d["Persons deported or who left following an order to leave (low estimate)"]) | |
| } | |
| return processed; | |
| } | |
| d3.csv("http://enjalot.github.io/migrants/deportations-year-country.csv", function(err, rawdata) { | |
| console.log("rawdata", rawdata); | |
| var data = rawdata.map(process); | |
| console.log("data", data); | |
| d3.select("#json").text(JSON.stringify(data, null, 2)) | |
| }); | |
| </script> | |
| </body> |