// Various formatters. var formatNumber = d3.format(",d"), formatChange = d3.format("+,d"), formatDate = d3.time.format("%B %d, %Y"), formatTime = d3.time.format("%I:%M %p"); // data across years var extant = []; var width = 960, height = 500; var rateById = d3.map(), nameById = d3.map(), baseById = d3.map(), checkById = d3.map(); var quantize = d3.scale.quantize() .domain([0, 1]) .range(d3.range(9).map(function(i) { return "q" + i + "-9"; })); var path = d3.geo.path(); var svg = d3.select("#map").append("svg") .attr("width", width) .attr("height", height); tip = d3.tip() .attr('class', 'd3-tip') .offset([-10, 0]) .direction('n') .html(function(d) { return baseById.get(d.id) }); svg.call(tip); var nation = crossfilter(), all = nation.groupAll() queue() .defer(d3.json, "counties.json") .defer(d3.tsv, "county_growth.tsv", function(d) { for(var propertyName in d) { if (propertyName == "Area"||propertyName == "basename") { continue; }; d[propertyName] = +d[propertyName]; } nation.add([d]); extant.push(d.id); nameById.set(d.id, d.Area); baseById.set(d.id, d.basename); checkById.set(d.id,d.check); }) .await(ready); function ready(error, us) { svg.append("g") .attr("class", "counties") .selectAll("path") .data(topojson.feature(us, us.objects.counties).features) .enter().append("path") .attr("class", function(d) { return quantize(checkById.get(d.id)); }) .attr("id", function(d) {if ((checkById.get(d.id))>1) {return d.id;} }) .attr("d", path) .on('mouseover',function(d){tip.show(d)}) .on('mouseout', tip.hide); renderAll(); }