From 532ac51e74960c890004fd0d342c02406b6fe5e8 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sun, 22 Sep 2013 08:56:29 -0400 Subject: [PATCH] Show the number of games used to calculate accuracy in the chart. --- xonstat/static/js/weaponCharts.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xonstat/static/js/weaponCharts.js b/xonstat/static/js/weaponCharts.js index 3586db7..dcd743e 100644 --- a/xonstat/static/js/weaponCharts.js +++ b/xonstat/static/js/weaponCharts.js @@ -1,4 +1,3 @@ -// 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"]; @@ -73,6 +72,15 @@ var drawAccuracyChart = function(data) { var transformedData = d3.nest() .key(function(d) { return d.weapon_cd; }).entries(data.weapon_stats); + var findNumGames = function(weapon) { + var numGames = transformedData.filter(function(e){return e.key == weapon})[0].values.length; + if(numGames !== undefined) { + return numGames; + } else { + return 0; + } + }; + // transform games list into a map such that games[game_id] = linear sequence var games = {}; data.games.forEach(function(v,i){ games[v] = i; }); @@ -102,7 +110,7 @@ var drawAccuracyChart = function(data) { } }) .tooltip(function(key, x, y, e, graph) { - return '

' + key + '

' + '

' + y + ' accuracy in game #' + x + '
' + data.averages[key] + '% average

'; + return '

' + key + '

' + '

' + y + ' accuracy in game #' + x + '
' + data.averages[key] + '% average over ' + findNumGames(key) + ' games

'; }) .color(keyColor); -- 2.39.2