]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Show the number of games used to calculate accuracy in the chart.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 22 Sep 2013 12:56:29 +0000 (08:56 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 22 Sep 2013 12:56:29 +0000 (08:56 -0400)
xonstat/static/js/weaponCharts.js

index 3586db78d2a6567f7c8e098eb2e5bce989898629..dcd743e2bf7ccb128f2f560976a74d702989d521 100644 (file)
@@ -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 '<h3>' + key + '</h3>' + '<p>' +  y + ' accuracy in game #' + x + ' <br /> ' + data.averages[key]  + '% average</p>';
+        return '<h3>' + key + '</h3>' + '<p>' +  y + ' accuracy in game #' + x + ' <br /> ' + data.averages[key]  + '% average over ' + findNumGames(key) + ' games</p>';
       })
       .color(keyColor);