Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. var margins = {top:20, bottom:300, left:30, right:100};
  2.  
  3. var height = 600;
  4. var width = 900;
  5.  
  6. var totalWidth = width+margins.left+margins.right;
  7. var totalHeight = height+margins.top+margins.bottom;
  8. var projection = d3.geoMercator().rotate([-10,0]).scale(50).translate([160,100]);
  9.  
  10. var path = d3.geoPath().projection(projection);
  11.  
  12. var svg = d3.select("body")
  13. .append('svg')
  14. .attr('width', 310)
  15. .attr('height', 150);
  16.  
  17. var topoData = d3.json("world-continents.json");
  18.  
  19. topoData.then(function(data) {
  20.  
  21. var continents = topojson.feature(data, data.objects.continent).features;
  22.  
  23. var map = svg.append('g').attr('class', 'boundary');
  24. var continent = map.selectAll('.continent').data(continents);
  25. console.log(continents)
  26. var color = d3.scaleLinear()
  27. .range(["#4f81d7","#f6d18b"])
  28. .domain([3000000,105000000]);
  29.  
  30. var data = [
  31. {'continent':'Asia', 't1fg':19, 't2fg':24, 't1fc':758, 't2fc':773},
  32. {'continent':'Europe', 't1fg':6, 't2fg':37, 't1fc':234, 't2fc':241},
  33. {'continent':'North America', 't1fg':20, 't2fg':60, 't1fc':102, 't2fc':102},
  34. {'continent':'South America', 't1fg':-2, 't2fg':22, 't1fc':1, 't2fc':1},
  35. {'continent':'Other', 't1fg':3, 't2fg':4, 't1fc':5, 't2fc':5},
  36. ];
  37.  
  38. var continentG = svg.selectAll('.cont')
  39. .data(data)
  40. .attr('class','cont')
  41. .enter()
  42. .append('g');
  43.  
  44. continentG.data(continents).append('path')
  45. .attr('class', 'continent')
  46. .attr('d', path)
  47. .style('stroke', "#a6a6a6")
  48. .style('fill', function(d) {
  49. if (d.properties.continent=="South America") {
  50. return "#003366";
  51. } else {
  52. return "none";
  53. }
  54. });
  55.  
  56.  
  57. })
  58.  
  59. svg.selectAll('.cont')
  60. .data(data)
  61. .attr('class','cont')
  62. .enter()
  63. .append('g');
  64.  
  65. var svg = d3.select("body").selectAll(null)
  66. .data(data)
  67. .enter()
  68. .append('svg')
  69. .attr('width', 300)
  70. .attr('height', 150)
  71.  
  72. var map = svg.selectAll(null)
  73. .data(continents)
  74. .enter()
  75. .append('path')
  76. .attr('class', 'continent')
  77. .attr('d', path)
  78.  
  79. map.style('fill', function(d) {
  80. var thisContinent = d3.select(this.parentNode).datum().continent;
  81. if (d.properties.continent === thisContinent) {
  82. return "#003366";
  83. } else {
  84. return "none";
  85. }
  86. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement