ReadMe file for VI8
xxxxxxxxxx
<html>
<meta charset="utf-8">
<!-- Example based on https://bl.ocks.org/mbostock/3887118 -->
<!-- Tooltip example from https://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html -->
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<style>
body {
font: 11px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
.tooltip {
position: absolute;
width: 200px;
height: 28px;
pointer-events: none;
}
</style>
<body>
<div class="row">
<div class="col-lg-6 graph1">
<h6 class="text-center">Color the marks by if the QB's school is in the Big Five, Group of Five, or Independent - no restrictions</h6>
<h6 class="text-center">Explanation: We are encoding categorical attributes and only four bins needed including the background, thus, colors with different hue are appropriate choice</h6>
</div>
<div class="col-lg-6 graph2">
<h6 class="text-center">Color the marks by if the QB's school is in the Big Five, Group of Five, or Independent - color-blind safe</h6>
<h6 class="text-center">Explanation: For this graph, we do not include red color, for color-blindness safety. differentiation in red-green channel is reduced or totally absent for color-blinded people</h6>
</div>
</div>
<div class="row">
<div class="col-lg-6 graph3">
<h6 class="text-center">Color the marks by if the QB's school is in the Big Five, Group of Five, or Independent - photocopy safe</h6>
<h6 class="text-center">Explanation: In this graph, because we have categorical attribute to encode with color, then we have to have different hue colors. but again in order for this to be photocopy-safe, we need to have different luminance for each color choice</h6>
</div>
<div class="col-lg-6 graph4">
<h6 class="text-center">Plot only QBs from schools in the Big Five conferences. Color the marks by conference - no restrictions</h6>
<h6 class="text-center">Explanation: We have six bins including the background. Thus we are using hue color map with different color for each conference. Here we cannot have both photocopy-safe and color-blind friendly, because number of bins are too high to have an appropriate choice</h6>
</div>
</div>
<div class="row">
<div class="col-lg-6 graph5">
<h6 class="text-center">Plot only the top 5 QBs by rank and color the marks by rank. choose a multi-hue colormap</h6>
<h6 class="text-center">Explanation: We are using ranking which is a sequential attribute. Thus, we start with darker color for the higher rank to lighter color for lower rank</h6>
</div>
<div class="col-md-6 graph6">
<h6 class="text-center">Plot only the top 5 QBs by rank and color the marks by rank. choose a single-hue colormap</h6>
<h6 class="text-center">Explanation: Explanation: We are using ranking which is a sequential attribute in a single hue colormap. Thus, We assign higher saturated color to the higher rank and lower saturated color to lower rank.</h6>
</div>
</div>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 20, right: 5, bottom: 30, left: 40},
width = 550 - margin.left - margin.right,
height = 360 - margin.top - margin.bottom;
/*
* value accessor - returns the value to encode for a given data object.
* scale - maps value to a visual display encoding, such as a pixel position.
* map function - maps from data value to display value
* axis - sets up axis
*/
// setup x
var xValue = function(d) { return d['Rushing Attempts'];}, // data -> value
xScale = d3.scale.linear().range([0, width]), // value -> display
xMap = function(d) { return xScale(xValue(d));}, // data -> display
xAxis = d3.svg.axis().scale(xScale).orient("bottom");
// setup y
var yValue = function(d) { return d["Passing Attempts"];}, // data -> value
yScale = d3.scale.linear().range([height, 0]), // value -> display
yMap = function(d) { return yScale(yValue(d));}, // data -> display
yAxis = d3.svg.axis().scale(yScale).orient("left");
// setup fill color
var cValue = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return 'Big Five';
} else if(d['Conf'] == 'American' || d['Conf'] == 'Sun Belt' || d['Conf'] == 'MWC' || d['Conf'] == 'MAC' || d['Conf'] == 'CUSA'){
return 'Group of Five';
} else {
return 'Independent';
}
}, color = function(val) {
if(val == 'Big Five') {
return '#e41a1c';
} else if (val == 'Group of Five') {
return '#377eb8';
} else {
return '#4daf4a';
}
}
// add the graph canvas to the body of the webpage
var svg = d3.select(".graph1").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// add the tooltip area to the webpage
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// load data
d3.csv("passing-stats-2014.csv", function(error, data) {
// change string (from CSV) into number format
data.forEach(function(d) {
//d.Calories = +d.Calories;
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
//console.log(d);
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(data, xValue)-5, d3.max(data, xValue)+5]);
yScale.domain([d3.min(data, yValue)-5, d3.max(data, yValue)+5]);
// x-axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return color(cValue(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValue(d)
+ ", " + yValue(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg.selectAll(".legend")
.data(['Big Five', 'Group of Five', 'Independent'])
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
/*
--------------------------------------------------------------------------------------
SECOND PART
--------------------------------------------------------------------------------------
*/
// setup fill color
var cValueBigFive = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return 'Big Five';
} else if(d['Conf'] == 'American' || d['Conf'] == 'Sun Belt' || d['Conf'] == 'MWC' || d['Conf'] == 'MAC' || d['Conf'] == 'CUSA'){
return 'Group of Five';
} else {
return 'Independent';
}
}, colorBigFive = function(val) {
if(val == 'Big Five') {
return '#a6cee3';
} else if (val == 'Group of Five') {
return '#1f78b4';
} else {
return '#b2df8a';
}
}
// setup x
var xValueBigFive = function(d) { return d['Rushing Attempts'];},
// setup y
yValueBigFive = function(d) {return d["Passing Attempts"];}// data -> value
// add the graph canvas to the body of the webpage
var svg2 = d3.select(".graph2").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load data
d3.csv("passing-stats-2014.csv", function(error, myData) {
// change string (from CSV) into number format
myData.forEach(function(d) {
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(myData, xValueBigFive)-5, d3.max(myData, xValueBigFive)+5]);
yScale.domain([d3.min(myData, yValueBigFive)-5, d3.max(myData, yValueBigFive)+5]);
// x-axis
svg2.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg2.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg2.selectAll(".dot")
.data(myData)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return colorBigFive(cValueBigFive(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValueBigFive(d)
+ ", " + yValueBigFive(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg2.selectAll(".legend")
.data(['Big Five', 'Group of Five', 'Independent'])
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", colorBigFive);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
/*
--------------------------------------------------------------------------------------
THIRD PART
--------------------------------------------------------------------------------------
*/
// setup fill color
var cValueBigFivee = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return 'Big Five';
} else if(d['Conf'] == 'American' || d['Conf'] == 'Sun Belt' || d['Conf'] == 'MWC' || d['Conf'] == 'MAC' || d['Conf'] == 'CUSA'){
return 'Group of Five';
} else {
return 'Independent';
}
}, colorBigFivee = function(val) {
if(val == 'Big Five') {
return '#8dd3c7';
} else if (val == 'Group of Five') {
return '#ffffb3';
} else {
return '#bebada';
}
}
// setup x
var xValueBigFivee = function(d) { return d['Rushing Attempts'];},
// setup y
yValueBigFivee = function(d) {return d["Passing Attempts"];}// data -> value
// add the graph canvas to the body of the webpage
var svg3 = d3.select(".graph3").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load data
d3.csv("passing-stats-2014.csv", function(error, myDataa) {
// change string (from CSV) into number format
myDataa.forEach(function(d) {
//d.Calories = +d.Calories;
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(myDataa, xValueBigFivee)-5, d3.max(myDataa, xValueBigFivee)+5]);
yScale.domain([d3.min(myDataa, yValueBigFivee)-5, d3.max(myDataa, yValueBigFivee)+5]);
// x-axis
svg3.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg3.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg3.selectAll(".dot")
.data(myDataa)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return colorBigFivee(cValueBigFivee(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValueBigFivee(d)
+ ", " + yValueBigFivee(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg3.selectAll(".legend")
.data(['Big Five', 'Group of Five', 'Independent'])
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", colorBigFivee);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
/*
--------------------------------------------------------------------------------------
FOURTH PART
--------------------------------------------------------------------------------------
*/
// setup fill color
var cValueTR = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return d['Conf'];
}
}, colorTR = d3.scale.category10();
// setup x
var xValueTR = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return d['Rushing Attempts'];
}
}, yValueTR = function(d) {
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
return d["Passing Attempts"];
}
}// data -> value
// add the graph canvas to the body of the webpage
var svg4 = d3.select(".graph4").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load data
d3.csv("passing-stats-2014.csv", function(error, data) {
// change string (from CSV) into number format
var myDataTR = [];
data.forEach(function(d) {
//d.Calories = +d.Calories;
if(d['Conf'] == 'SEC' || d['Conf'] == 'ACC' || d['Conf'] == 'Big 12' || d['Conf'] == 'Pac-12' || d['Conf'] == 'Big Ten') {
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
myDataTR.push(d);
}
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(myDataTR, xValueTR)-5, d3.max(myDataTR, xValueTR)+5]);
yScale.domain([d3.min(myDataTR, yValueTR)-5, d3.max(myDataTR, yValueTR)+5]);
// x-axis
svg4.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg4.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg4.selectAll(".dot")
.data(myDataTR)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return colorTR(cValueTR(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValueTR(d)
+ ", " + yValueTR(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg4.selectAll(".legend")
.data(colorTR.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", colorTR);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
/*
--------------------------------------------------------------------------------------
FIFTH PART
--------------------------------------------------------------------------------------
*/
// setup fill color
var cValueTR2 = function(d) {
if(d['Rk'] <= 5) {
return d['Rk'];
}
}, colorTR2 = function(val) {
if(val == 1) {
return '#253494';
} else if (val == 2) {
return '#2c7fb8';
} else if (val == 3) {
return '#41b6c4';
} else if (val == 4) {
return '#a1dab4';
} else if (val == 5) {
return '#ffffcc';
}
};
// setup x
var xValueTR2 = function(d) {
if(d['Rk'] <= 5) {
return d['Rushing Attempts'];
}
}, yValueTR2 = function(d) {
if(d['Rk'] <= 5) {
return d["Passing Attempts"];
}
}// data -> value
// add the graph canvas to the body of the webpage
var svg5 = d3.select(".graph5").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load data
d3.csv("passing-stats-2014.csv", function(error, data) {
// change string (from CSV) into number format
var myDataTR2 = [];
data.forEach(function(d) {
//d.Calories = +d.Calories;
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
d['Rk'] = +d['Rk'];
if(d['Rk'] <=5) {
myDataTR2.push(d);
}
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(myDataTR2, xValueTR2)-5, d3.max(myDataTR2, xValueTR2)+5]);
yScale.domain([d3.min(myDataTR2, yValueTR2)-5, d3.max(myDataTR2, yValueTR2)+5]);
// x-axis
svg5.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg5.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg5.selectAll(".dot")
.data(myDataTR2)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return colorTR2(cValueTR2(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValueTR2(d)
+ ", " + yValueTR2(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg5.selectAll(".legend")
.data([1,2,3,4,5])
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", colorTR2);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
/*
--------------------------------------------------------------------------------------
Sixth PART
--------------------------------------------------------------------------------------
*/
// setup fill color
var colorTR3 = function(val) {
if(val == 1) {
return '#54278f';
} else if (val == 2) {
return '#756bb1';
} else if (val == 3) {
return '#9e9ac8';
} else if (val == 4) {
return '#cbc9e2';
} else if (val == 5) {
return '#f2f0f7';
}
};
// add the graph canvas to the body of the webpage
var svg6 = d3.select(".graph6").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load data
d3.csv("passing-stats-2014.csv", function(error, data) {
// change string (from CSV) into number format
var myDataTR2 = [];
data.forEach(function(d) {
//d.Calories = +d.Calories;
d['Rushing Attempts'] = +d['Rushing Attempts'];
d['Passing Attempts'] = +d['Passing Attempts'];
d['Rk'] = +d['Rk'];
if(d['Rk'] <=5) {
myDataTR2.push(d);
}
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(myDataTR2, xValueTR2)-5, d3.max(myDataTR2, xValueTR2)+5]);
yScale.domain([d3.min(myDataTR2, yValueTR2)-5, d3.max(myDataTR2, yValueTR2)+5]);
// x-axis
svg6.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rushing Attempts");
// y-axis
svg6.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Passing Attempts");
// draw dots
svg6.selectAll(".dot")
.data(myDataTR2)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return colorTR3(cValueTR2(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Player"] + "<br/> (" + xValueTR2(d)
+ ", " + yValueTR2(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg6.selectAll(".legend")
.data([1,2,3,4,5])
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", colorTR3);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://code.jquery.com/jquery-2.2.2.min.js
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js
https://d3js.org/d3.v3.min.js