-var weapons = ["laser", "shotgun", "uzi", "grenadelauncher", "electro", "crylink",
- "nex", "hagar", "rocketlauncher", "minstanex", "rifle", "fireball",
- "minelayer", "seeker", "tuba", "hlac", "hook", "porto"];
+// weapons and their corresponding colors
+var weapons = ["laser", "shotgun", "uzi", "grenadelauncher", "minelayer", "electro",
+ "crylink", "nex", "hagar", "rocketlauncher", "porto", "minstanex", "hook", "hlac",
+ "seeker", "rifle", "tuba", "fireball"];
+
+var weaponColors = ["#ff5933", "#b2b2b2", "#66e559", "#ff2600", "#bfbf00", "#597fff",
+ "#d83fff", "#00e5ff", "#d87f59", "#ffbf33", "#7fff7f", "#a5a5ff", "#a5ffd8",
+ "#ffa533", "#ff5959", "#d87f3f", "#d87f3f", "#33ff33"];
+
+var colorScale = d3.scale.ordinal().domain(weapons).range(weaponColors);
var drawDamageChart = function(data) {
// the chart should fill the "damageChart" div
width -= margin.left - margin.right;
// colors
- var colors = d3.scale.category20().domain(weapons);
- keyColor = function(d, i) {return colors(d.key)};
+ keyColor = function(d, i) {return colorScale(d.key)};
var chart;
nv.addGraph(function() {
// the chart should fill the "accuracyChart" div
var width = document.getElementById("accuracyChart").offsetWidth;
+ // get rid of empty values
+ data.weapon_stats = data.weapon_stats.filter(function(e){ return e.fired > 0; });
+
// transform the dataset into something nvd3 can use
var transformedData = d3.nest()
.key(function(d) { return d.weapon_cd; }).entries(data.weapon_stats);
width -= margin.left - margin.right;
// colors
- var colors = d3.scale.category20().domain(weapons);
- keyColor = function(d, i) {return colors(d.key)};
+ keyColor = function(d, i) {return colorScale(d.key)};
var chart;
nv.addGraph(function() {
.margin(margin)
.width(width)
.height(height)
+ .forceY([0,1])
.x(function(d) { return games[d.game_id] })
.y(function(d) {
if(d.fired > 0) {
return 0;
}
})
+ .tooltip(function(key, x, y, e, graph) {
+ return '<h3>' + key + '</h3>' + '<p>' + y + ' accuracy in game #' + x + ' <br /> ' + data.averages[key] + '% average</p>';
+ })
.color(keyColor);
chart.xAxis
.ticks(5)
.tickFormat(function(d) { return data.games[d]; });
+ var yScale = d3.scale.linear().domain([0,1]).range([0,height]);
chart.yAxis
.axisLabel('% Accuracy')
.tickFormat(d3.format('2%'));