Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <div id="iowa-map">
  2. <strong>Population by counties (color: total population)</strong>
  3. <a class="reset" href="javascript:iowaMap.filterAll();dc.redrawAll();" style="display: none; ">reset</a>
  4. <span class="reset" style="display: none;"> | Current filter: <span class="filter"></span></span>
  5. <div class="clearfix"></div>
  6. </div>
  7.  
  8. <div id="population-chart">
  9. <strong>Population by county</strong>
  10. <a class="reset" href="javascript:populationChart.filterAll();dc.redrawAll();" style="display: none; ">reset</a>
  11. <span class="reset" style="display: none;"> | Current filter: <span class="filter"></span></span>
  12. <div class="clearfix"></div>
  13. </div>
  14.  
  15. <div class="clearfix"></div>
  16.  
  17. <div>
  18. <a href="javascript:dc.filterAll(); dc.renderAll();">Reset All</a>
  19. </div>
  20.  
  21. var iowaMap = dc.geoChoroplethChart("#iowa-map");
  22. var populationChart = dc.barChart("#population-chart");
  23.  
  24. d3.csv("iowaCountiesPop.csv", function (data) {
  25.  
  26. data.forEach(function (d) {
  27. d.county = d.county;
  28. d.popByCounty = +d.e2015;
  29. });
  30.  
  31. var data = crossfilter(data);
  32.  
  33. var counties = data.dimension(function (d) {
  34. return d.county;
  35. });
  36.  
  37. var counties2 = data.dimension(function (d) {
  38. return d.county;
  39. });
  40.  
  41. var popByCounty = counties.group().reduceSum(function (d) {
  42. return d.popByCounty;
  43. });
  44.  
  45.  
  46. d3.json("IowaCounties.json", function (countiesJson) {
  47. iowaMap.width(990)
  48. .height(500)
  49. .dimension(counties)
  50. .group(popByCounty)
  51. .projection(d3.geo.mercator()
  52. .translate([495, 250])
  53. .rotate([93 + 20 / 60, -41 - 60 / 60])
  54. .scale(7900))
  55. .colors(d3.scale.quantile().range(colorScheme[quantiles]))
  56. .colorDomain([0, 430640])
  57. .overlayGeoJson(countiesJson.features, "NAME", function (d) {
  58. return d.properties.NAME;
  59. })
  60. .title(function (d) {
  61. return d.key + " County nTotal Population: " + numberFormat(d.value);
  62. })
  63. .on('renderlet', function(map) {
  64. map.selectAll("path").on("click", function(d) {
  65. //console.log("click!", d)
  66. map.filter(d.properties.NAME)
  67. .redrawGroup();
  68. })
  69. });
  70.  
  71.  
  72. populationChart.width(width)
  73. .height(height)
  74. .dimension(counties2)
  75. .group(popByCounty)
  76. .x(d3.scale.ordinal().domain(counties))
  77. .xUnits(dc.units.ordinal)
  78. .margins({top: 0, right: 0, bottom: 70, left: 70})
  79. .yAxisLabel(["Population Values"])//,[12])
  80. .xAxisLabel("County Names")
  81. .barPadding(0.1)
  82. .outerPadding(0.05)
  83. .elasticY(false)
  84. //.turnOnControls(true)
  85. .on('renderlet', function(chart) {
  86. chart.selectAll('rect').on("click", function(d) {
  87. //console.log("click!", d)
  88. chart.filter(d.data.key)
  89. .redrawGroup();
  90. })
  91. chart.selectAll("g.x text")
  92. .style("text-anchor", "end")
  93. .attr("dx","-8")
  94. .attr("dy", "5")
  95. .attr("transform", "rotate(-50)");
  96. });
  97.  
  98. dc.renderAll();
  99.  
  100. });
  101.  
  102. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement