Guest User

Untitled

a guest
Dec 13th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. // Community colors
  2. var comm_colors = [ "red", "blue", "green", "yellow", "purple" ];
  3.  
  4. // CSV
  5. function parse_add_csv(cts){
  6.  
  7. var new_cts = cts
  8. console.log('parsing csv');
  9. d3.csv("data/communities.csv", function(comms)
  10. { csv = comms.map(function(d)
  11. {
  12.  
  13. return {"community": d.community, "label": d.BoroCT2010} ;
  14. })
  15.  
  16. csv.forEach(function(d, i) {
  17. new_cts.forEach(function(e, j) {
  18. if (d.label === e.properties.BoroCT2010) {
  19.  
  20. e.properties.community = parseInt(d.community)
  21. }
  22. })
  23. })
  24. })
  25. return new_cts
  26. }
  27.  
  28.  
  29. d3.json("data/nyct2010_17a3_topo.json", function(error, nyb) {
  30. console.log('tracts uploaded, v3')
  31.  
  32. var ctss = topojson.feature(nyb, nyb.objects.nyct2010_17a3).features;
  33. ctss = parse_add_csv(ctss); // match data from csv by BoroCT2010
  34.  
  35. cts.selectAll(".tract")
  36. .data(ctss)
  37. .enter().append("path")
  38. .attr("class", "tract")
  39. .attr("d", path)
  40. .attr("id", function(d) {
  41. return d.properties.BoroCT2010;})
  42. .attr("nhd_name", function(d) {
  43. return d.properties.NTAName;})
  44. .style('fill', function(d){
  45. console.log(comm_colors[d.properties.community])
  46. return comm_colors[d.properties.community];})
  47. .on("mouseover", handleMouseOver)
  48. .on("mouseout", handleMouseOut)
  49. .style('fill', function(d) {return
  50. comm_colors[d.properties.community]});
  51. })
  52.  
  53. .style('fill', function(d){
  54. console.log(comm_colors[d.properties.community])
  55. return comm_colors[d.properties.community];})
  56.  
  57. d3.json("data/nyct2010_17a3_topo.json", function(error, nyb){
  58. d3.csv("data/communities.csv", function(comms){
  59. //here goes all code that uses both 'nyb' and 'comms'
  60. })
  61. })
Add Comment
Please, Sign In to add comment