Guest User

Untitled

a guest
Jan 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  5. <title>Countries of the World</title>
  6. <script type="text/javascript" src="../../d3.v2.js"></script>
  7. <style type="text/css">
  8.  
  9. svg {
  10. width: 960px;
  11. height: 500px;
  12. }
  13.  
  14. #countries path, #country-centroids circle {
  15. fill: #ccc;
  16. stroke: #fff;
  17. stroke-width: 1.5px;
  18. }
  19.  
  20. #country-centroids circle {
  21. fill: steelblue;
  22. fill-opacity: .8;
  23. }
  24.  
  25. </style>
  26. </head>
  27. <body>
  28. <script type="text/javascript">
  29.  
  30. // The radius scale for the centroids
  31. var r = d3.scale.sqrt()
  32. .domain([0, 1e6])
  33. .range([0, 10]);
  34.  
  35. // World Map Projection
  36. var xy = d3.geo.mercator(),
  37. path = d3.geo.path().projection(xy);
  38.  
  39.  
  40. var svg = d3.select("body").append("svg");
  41. svg.append("g").attr("id", "countries");
  42. svg.append("g").attr("id", "country-centroids");
  43.  
  44. d3.json("../data/world-countries.json", function(collection) {
  45. svg.select("#countries")
  46. .selectAll("path")
  47. .data(collection.features)
  48. .enter().append("path")
  49. .attr("d", d3.geo.path().projection(xy));
  50. });
  51.  
  52. d3.json("../data/world-country-centroids.json", function(collection) {
  53. svg.select("#country-centroids")
  54. .selectAll("circle")
  55. .data(collection.features
  56. .sort(function(a, b) { return b.properties.population - a.properties.population; }))
  57. .enter().append("circle")
  58. .attr("transform", function(d) { return "translate(" + xy(d.geometry.coordinates) + ")"; })
  59. .attr("r", 0)
  60. .transition()
  61. .duration(1000)
  62. .delay(function(d, i) { return i * 50; })
  63. .attr("r", function(d) { return r(d.properties.population); });
  64. });
  65.  
  66. </script>
  67. </body>
  68. </html>
  69.  
  70. var svg = d3.select("body").append("svg")
  71. .attr("width", 960)
  72. .attr("height", 500);
Add Comment
Please, Sign In to add comment