//jshint esnext:true var graph = {}; // we namespace our d3 graph into setup and draw var stateDataURL = 'states.json'; var statisticsDataURL = 'stats.csv'; graph.setup = () => { let width = 1000; let height = 600; let svg = d3.select('div#states').append('svg') .attr('width', width) .attr('height', height); return svg; } graph.draw = (svg, data) => { /* our data expects an array of objects each object is expected to have: name: tooltip - the full name of the state abbrev: mergeData - used as the key to merge the json and csv low: tooltip, color domain high: tooltip, color domain average: tooltip, path fill */ let color = d3.scaleQuantize() .range(["rgb(237,248,233)", "rgb(186,228,179)", "rgb(116,196,118)", "rgb(49,163,84)", "rgb(0,109,44)"]); color.domain([ d3.min(data, function(d) { return d.low; }), d3.max(data, function(d) { return d.high; }) ]); let states = svg.selectAll('path.states') .data(data); let drawStates = states.enter().append('path') .attr('class', 'state') .attr('id', d => d.abbrev) .attr('stroke', 'gray') .attr('d', d => d.path) .style('fill', d => color(d.average)) .on('mouseover', mouseOver) .on('mouseout', mouseOut); } let tooltipHtml = (d) => { return '
| Low | '+(d.low)+' |
| High | '+(d.high)+' |
| Avg | '+(d.average)+' |