]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Working charts on the player_info pages. Yeah!
authorAnt Zucaro <azucaro@gmail.com>
Wed, 11 Sep 2013 01:40:54 +0000 (21:40 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 11 Sep 2013 01:40:54 +0000 (21:40 -0400)
xonstat/templates/player_info.mako

index 2539a0d899dd5222cbb1ea89d34b91ad8d8965ce..a1c40ef8d545285c073485c61b005c27f5dbbdc9 100644 (file)
@@ -11,13 +11,21 @@ ${nav.nav('players')}
 <%block name="css">
 ${parent.css()}
 <link href="/static/css/sprites.css" rel="stylesheet">
+<link href="/static/css/nv.d3.css" rel="stylesheet" type="text/css">
+<style>
+#damageChartSVG, #accuracyChartSVG {
+  height: 300px;
+}
+</style>
 </%block>
 
 <%block name="js">
 ${parent.js()}
-% if player is not None:
-<script src="/static/js/jquery.flot.min.js"></script>
+<script src="/static/js/d3.v3.min.js"></script>
+<script src="/static/js/nv.d3.min.js"></script>
+<script src="/static/js/weaponCharts.js"></script>
 <script type="text/javascript">
+// tabs
 $(function () {
   $('#gbtab li').click(function(e) {
     e.preventDefault();
@@ -26,173 +34,32 @@ $(function () {
 
   $('#gbtab a:first').tab('show');
 })
-</script>
-
-<script type="text/javascript">
-$(function () {
-    // plot the accuracy graph
-    function plot_acc_graph(data) {
-    var games = new Array();
-    var avgs = new Array();
-    var accs = new Array();
-
-  var i=0;
-  for(i=0; i < data.games; i++) {
-    avgs[i] = [i, data.avg];
-    accs[i] = [i, data.accs[i][1]];
-    game_link = '/game/' + data.accs[i][0];
-    j = data.games - i;
-    games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
-  }
-
-  $.plot(
-    $("#acc-graph"), 
-    [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
-      { label: 'accuracy', data: accs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
-      { yaxis: {ticks: 10, min: 0, max: 100 },
-        xaxis: {ticks: games},
-        grid: { hoverable: true, clickable: true },
-      });
-}
-
-// plot the damage graph
-function plot_dmg_graph(data) {
-  var games = new Array();
-  var avgs = new Array();
-  var dmgs = new Array();
-
-var i=0;
-for(i=0; i < data.games; i++) {
-  avgs[i] = [i, data.avg];
-  dmgs[i] = [i, data.dmgs[i][1]];
-  game_link = '/game/' + data.dmgs[i][0];
-  j = data.games - i;
-  games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
-}
 
-$.plot(
-  $("#dmg-graph"), 
-  [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
-    { label: 'efficiency', data: dmgs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
-    { yaxis: {ticks: 10, min: 0 },
-      xaxis: {ticks: games},
-      grid: { hoverable: true, clickable: true },
-    });
-          }
-
-          function showTooltip(x, y, contents) {
-            $('<div id="tooltip">' + contents + '</div>').css( {
-              position: 'absolute',
-              display: 'none',
-              top: y - 35,
-              left: x + 10,
-              border: '1px solid #fdd',
-              padding: '2px',
-              'background-color': '#333333',
-              opacity: 0.80
-            }).appendTo("body").fadeIn(200);
-          }
-
-          var previousPoint = null;
-          var previousLabel = null;
-          $('#acc-graph').bind("plothover", function (event, pos, item) {
-            if (item) {
-              if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
-                previousLabel = item.series.label;
-                previousPoint = item.dataIndex;
-
-                $("#tooltip").remove();
-                var x = item.datapoint[0].toFixed(2),
-                y = item.datapoint[1].toFixed(2);
-
-                showTooltip(item.pageX, item.pageY, y + "%");
-              }
-            }
-            else {
-              $("#tooltip").remove();
-              previousPoint = null;
-              previousLabel = null;
-            }
-          });
-
-          $('#dmg-graph').bind("plothover", function (event, pos, item) {
-            if (item) {
-              if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
-                previousPoint = item.dataIndex;
-                previousLabel = item.series.label;
-
-                $("#tooltip").remove();
-                var x = item.datapoint[0].toFixed(2),
-                y = item.datapoint[1].toFixed(2);
-
-                showTooltip(item.pageX, item.pageY, y);
-              }
-            }
-            else {
-              $("#tooltip").remove();
-              previousPoint = null;
-              previousLabel = null;
-            }
-          });
-
-// bind click events to the weapon images
-$(".acc-weap").click(function () {
-    var dataurl = $(this).find('a').attr('href');
-
-          $('.accuracy-nav').find('.weapon-active').removeClass('weapon-active');
-          $(this).addClass('weapon-active');
-
-          $.ajax({
-            url: dataurl,
-            method: 'GET',
-            dataType: 'json',
-            success: plot_acc_graph
-          });
+// weapon accuracy and damage charts
+d3.json("${request.route_url('player_weaponstats_data_json', id=player.player_id)}", function(err, data) {
+  drawDamageChart(data);
+  drawAccuracyChart(data);
 });
 
-$(".dmg-weap").click(function () {
-  var dataurl = $(this).find('a').attr('href');
-
-  $('.damage-nav').find('.weapon-active').removeClass('weapon-active');
-  $(this).addClass('weapon-active');
-
-  $.ajax({
-    url: dataurl,
-    method: 'GET',
-    dataType: 'json',
-    success: plot_dmg_graph
+% for g in games_played:
+d3.select('.tab-${g.game_type_cd}').on("click", function() {
+  // have to remove the chart each time
+  d3.select('#damageChartSVG .nvd3').remove();
+  d3.select('#accuracyChartSVG .nvd3').remove();
+  d3.json("${request.route_url('player_weaponstats_data_json', id=player.player_id, _query={'limit':20, 'game_type':g.game_type_cd})}", function(err, data) {
+    drawDamageChart(data);
+    drawAccuracyChart(data);
   });
 });
+% endfor
 
-// populate the graphs with the default weapons
-$.ajax({
-url: '${request.route_url("player_accuracy", id=player.player_id)}',
-method: 'GET',
-dataType: 'json',
-success: plot_acc_graph
-});
-
-$.ajax({
-  url: '${request.route_url("player_damage", id=player.player_id)}',
-  method: 'GET',
-  dataType: 'json',
-  success: plot_dmg_graph
-});
-})
 </script>
-% endif
 </%block>
 
 <%block name="title">
 Player Information
 </%block>
 
-
-% if player is None:
-<h2>This player is so good we couldn't find him!</h2>
-<p>Seriously though, he probably doesn't exist...just a figment of your imagination. Carry on then!</p>
-
-% else:
 <div class="row">
   <div class="span12">
     <h2>
@@ -240,7 +107,7 @@ Player Information
           % else:
           <small><br /></small>
           % endif
-          
+
           % if g.game_type_cd == 'ctf':
           % if overall_stats[g.game_type_cd].total_captures is not None:
           <small><a href="${request.route_url("player_captimes", id=player.player_id)}">Fastest flag captures...</a> <br /></small>
@@ -250,7 +117,7 @@ Player Information
           % else:
           <small><br /></small>
           % endif
-          
+
           </p>
         </div>
         <div class="span5">
@@ -320,7 +187,7 @@ Player Information
   <div class="span12">
     <ul id="gbtab" class="nav nav-tabs">
       % for g in games_played:
-      <li>
+      <li class="tab-${g.game_type_cd}">
       <a href="#tab-${g.game_type_cd}" data-toggle="tab" alt="${g.game_type_cd}" title="${overall_stats[g.game_type_cd].game_type_descr}">
         <span class="sprite sprite-${g.game_type_cd}"> </span><br />
         ${g.game_type_cd} <br />
@@ -332,11 +199,29 @@ Player Information
   </div>
 </div>
 
-### ACCURACY GRAPH
-${accuracy_graph(recent_weapons)}
 
-### DAMAGE GRAPH
-${damage_graph(recent_weapons)}
+##### Weapon Accuracy Chart ####
+<div class="row">
+  <div class="span12">
+    <h3>Weapon Accuracy</h3>
+    <div id="accuracyChart">
+      <svg id="accuracyChartSVG"></svg>
+    </div>
+  </div> <!-- end span12 -->
+</div> <!-- end row -->
+
+
+##### Weapon Damage Chart ####
+<div class="row">
+  <div class="span12">
+    <h3>Weapon Damage</h3>
+    <div id="damageChart">
+      <svg id="damageChartSVG"></svg>
+    </div>
+  </div> <!-- end span12 -->
+</div> <!-- end row -->
+
+
 
 ##### RECENT GAMES (v2) ####
 % if recent_games:
@@ -403,4 +288,3 @@ ${damage_graph(recent_weapons)}
   </div>
 </div>
 % endif
-% endif