Guest User

Untitled

a guest
Jul 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. //------ BEGIN NEW CODE HERE ------
  2. let univMenu = d3.select("#univDropdown");
  3.  
  4. univMenu
  5. .append("select")
  6. .selectAll("option")
  7. .data(nest)
  8. .enter()
  9. .append("option")
  10. .attr("value", function(d){return d.key;})
  11. .text(function(d){return d.key;})
  12.  
  13.  
  14.  
  15. // Function to create the initial graph
  16. let initialGraph = function(univ){
  17.  
  18.  
  19. let selectUniv = nest.filter(function(d){return d.key == univ;})
  20. let selectUnivGroups = svg.selectAll(".univGroups")
  21. .data(selectUniv, function(d){return d ? d.key : this.key;})
  22. .enter()
  23. .append("g")
  24. .attr("class", "univGroups")
  25.  
  26. let initialPath = selectUnivGroups.selectAll(".line")
  27. .data(function(d) { return d.values; })
  28. .enter()
  29. .append("path")
  30.  
  31. initialPath
  32. .attr("d", function(d){return valueLine(d.values)})
  33. .attr("class", "line")}
  34. // Create initial graph
  35. initialGraph("USHE Average")
  36.  
  37.  
  38. // Update the data
  39. let updateGraph = function(univ){
  40.  
  41. // Filter the data to include only fruit of interest
  42. let selectUniv = nest.filter(function(d){return d.key == univ;})
  43.  
  44. // Select all of the grouped elements and update the data
  45. let selectUnivGroups = svg.selectAll(".univGroups")
  46. .data(selectUniv)
  47.  
  48. // Select all the lines and transition to new positions
  49. selectUnivGroups.selectAll("path.line")
  50. .data(function(d){return (d.values);})
  51. .transition()
  52. .duration(1000)
  53.  
  54. .attr("d", function(d){return valueLine(d.values)})}
  55.  
  56.  
  57. // Run update function when dropdown selection changes
  58. univMenu.on('change', function(){
  59. let selectedUniv = d3.select(this)
  60. .select("select")
  61. .property("value")
  62.  
  63.  
  64. updateGraph(selectedUniv)
  65.  
  66.  
  67. });
Add Comment
Please, Sign In to add comment