Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <script>
  2. var width = 1000;
  3. var height = 600;
  4.  
  5. var d = [];
  6. var projection = d3.geo.mercator()
  7. .translate([width/2, height/2])
  8. .scale([500]);
  9.  
  10. var path = d3.geo.path().projection(projection);
  11.  
  12. var color = d3.scale.ordinal().range(colorbrewer.YlGn[9]);
  13.  
  14. var svg = d3.select("#viz").append("svg")
  15. .attr("width",width)
  16. .attr("height",height);
  17.  
  18. d3.json('scm-timezone.json', function(data){
  19. var com = data.commits;
  20. d.push(com);
  21. color.domain([
  22. d3.min(d[0]),
  23. d3.max(d[0])
  24. ]);
  25.  
  26. d3.json("world.json", function(json){
  27.  
  28. for(var i = 0;i < data.tz.length;i++){
  29.  
  30. var dataTZ = data.tz[i];
  31.  
  32. var commitValue = parseInt(data.commits[i]);
  33.  
  34. for(var j = 0;j<json.features.length;j++){
  35.  
  36. var jsonTZ = json.features[j].properties.description;
  37.  
  38. if(dataTZ == jsonTZ) {
  39.  
  40. json.features[j].properties.value = commitValue;
  41.  
  42. }
  43. }
  44. }
  45. svg.selectAll("path")
  46. .data(json.features)
  47. .enter()
  48. .insert("path")
  49. .attr("d",path)
  50. .style("fill", function(d) {
  51. var val = d.properties.value;
  52. if(val){ return color(val); }
  53. else { return "white"; }
  54. });
  55. });
  56. });
  57.  
  58. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement