d3.csv('passing_stats.csv', function(error, raw) { var width = 800; var height = 800; var padding = 50; var dataset = []; var color = new ColorMap(); var radius = 5; raw.forEach(function(v) { dataset.push({ x: Number(v['Passing Attempts']), y: Number(v['Passing Yards']), name: v['Player'], conference: v['Conf'], color: color.byConference(v['Conf']), radius: radius, layer: 0 }); }); var svg = d3.select('body') .append('svg') .attr('width', width) .attr('height', height); var scatterplot = new Scatterplot(svg, dataset, width, height, padding); scatterplot.draw(); scatterplot.makeHoverLabels(function(d) { return d.name; }); scatterplot.drawAxisLabels('Passing Yards', 'Passing Attempts'); var lg = svg.append('g') .attr('transform', 'translate(100,50)'); var legend = new Legend(lg); legend.draw(color.getConferenceColors()); var last = null; var detail = new Detail(svg, width - padding, height - padding, width * 0.30, height * 0.275, 10, 15); scatterplot.each(function() { d3.select(this) .on('click', function(d) { if (last != null) { last.color = color.byConference(last.conference); last.radius = radius; last.layer = 0; } d.color = 'black'; d.radius = radius * 2; d.layer = 1; last = d; scatterplot.draw(); var details; raw.forEach(function(r) { if (d.name == r['Player']) { details = [ 'Rank: ' + r['Rk'], 'Name: ' + r['Player'], 'School: ' + r['School'], 'Passing Attempts: ' + r['Passing Attempts'], 'Passing Yards: ' + r['Passing Yards'], 'Passing TD: ' + r['Passing TD'], 'Interceptions: ' + r['Interceptions'], 'Rate: ' + r['Rate'], 'Rushing Attempts: ' + r['Rushing Attempts'], 'Rushing Yards: ' + r['Rushing Yards'], 'Rushing Avg: ' + r['Rushing Avg'], 'Rushing TD: ' + r['Rushing TD'] ]; } }); if (details) { detail.update(details); } }); }); });