[321] Redraw sparklines on tab refresh
[321] Redraw sparklines on tab refresh

--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -417,11 +417,14 @@
     # Create a consistent x-axis between all series
     num_points = [ len(series['data']) for series in data ]
     ideal_index = num_points.index( max(num_points) )
-    x_axis = [ point['x'] for point in data[ideal_index]['data'] ]
+    x_axis = []
+    for series in data:
+        for point in series['data']:
+            x_axis.append(point['x'])
+    x_axis = sorted( list( set(x_axis) ) )
+    # Zero pad any missing values
     for series in data:
         xs = [ point['x'] for point in series['data'] ]
-        assert set(xs).issubset( set(x_axis) ), (xs, x_axis)
-        # Zero pad any missing values
         for x in set(x_axis).difference(set(xs)):
             series['data'].append( {'x':x, 'y':0} )
     if percentageMode:
@@ -430,9 +433,6 @@
             for series in series_list:
                 for point in series['data']:
                     totals[point['x']] = totals.get(point['x'],0) + point['y']
-            lengths = [ len(series['data']) for series in series_list ]
-            assert len(set(lengths))==1
-            assert lengths[0] == len(totals)
             return totals
         # Transform data into percentage stacks
         totals = get_totals(data)

--- a/ckanext/ga_report/public/css/ga_report.css
+++ b/ckanext/ga_report/public/css/ga_report.css
@@ -18,6 +18,7 @@
 .rickshaw_legend {
   background: transparent;
   width: 100%;
+  padding-top: 4px;
 }
 .rickshaw_y_axis {
   position: absolute;
@@ -29,6 +30,10 @@
   background: transparent !important;
   color: #000000 !important;
   font-weight: normal !important;
+}
+.rickshaw_legend .instructions {
+  color: #000;
+  margin-bottom: 6px;
 }
 
 .rickshaw_legend .line .action {
@@ -44,4 +49,11 @@
   float: left;
   width: 200px;
 }
+.rickshaw_legend .line .label:hover {
+  text-decoration: underline;
+}
 
+.ga-reports-table .td-numeric {
+  text-align: center;
+}
+

--- a/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
+++ b/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
@@ -45,6 +45,7 @@
       graph: graph,
       legend: legend
     } );
+    myLegend.prepend('<div class="instructions">Click on a series below to isolate its graph:</div>');
     graph.render();
 };
 
@@ -54,24 +55,29 @@
    * Sparkline graphs should be drawn.
    * Note that they cannot be drawn sooner.
    */
+  var created = false;
   $('a[href="#totals"]').on(
     'shown', 
-    function() {
-      var sparkOptions = {
-        enableTagOptions: true,
-        type: 'line',
-        width: 100,
-        height: 26,
-        chartRangeMin: 0,
-        spotColor: '',
-        maxSpotColor: '',
-        minSpotColor: '',
-        highlightSpotColor: '000000',
-        lineColor: '3F8E6D',
-        fillColor: 'B7E66B'
-      };
-      $('.sparkline').sparkline('html',sparkOptions);
-    }
+      function() {
+        if (!created) {
+          var sparkOptions = {
+            enableTagOptions: true,
+            type: 'line',
+            width: 100,
+            height: 26,
+            chartRangeMin: 0,
+            spotColor: '',
+            maxSpotColor: '',
+            minSpotColor: '',
+            highlightSpotColor: '000000',
+            lineColor: '3F8E6D',
+            fillColor: 'B7E66B'
+          };
+          $('.sparkline').sparkline('html',sparkOptions);
+          created = true;
+        }
+        $.sparkline_display_visible();
+      }
   );
 };
 
@@ -94,6 +100,7 @@
       }
       legend_name = '#legend_'+legend_name;
       $('#graph-legend-container > *').hide();
+      $('#graph-legend-container .instructions').show();
       $(legend_name).show();
     }
   );
@@ -103,8 +110,8 @@
   var handler = function(e) { 
     var target = $(e.delegateTarget);
     var form = target.closest('form');
-    form.attr('action', form.attr('action')+window.location.hash);
-    form.submit();
+    var url = form.attr('action')+'?month='+target.val()+window.location.hash;
+    window.location = url;
   };
   var selectors = $('select[name="month"]');
   assert(selectors.length>0);

--- a/ckanext/ga_report/templates/ga_report/ga_util.html
+++ b/ckanext/ga_report/templates/ga_report/ga_util.html
@@ -14,7 +14,7 @@
 </select>
 
 
-<table py:def="social_table(items, with_source=False)" class="table table-condensed table-bordered table-striped">
+<table py:def="social_table(items, with_source=False)" class="ga-reports-table table table-condensed table-bordered table-striped">
     <tr>
         <th>Name</th>
         <th py:if="with_source">Source</th>
@@ -24,7 +24,7 @@
     <tr>
         <td><a href="${url}">${name}</a></td>
         <td py:if="with_source">${source}</td>
-        <td>${count}</td>
+        <td class="td-numeric">${count}</td>
     </tr>
     </py:for>
  </table>
@@ -45,15 +45,15 @@
 </div>
 
 
-<table py:def="stat_table(items, title='Views')" class="table table-condensed table-bordered table-striped">
+<table py:def="stat_table(items, title='Views')" class="ga-reports-table table table-condensed table-bordered table-striped">
     <tr>
         <th>Name</th>
-        <th>% ${title}</th>
+        <th class="td-numeric">% ${title}</th>
     </tr>
     <py:for each="name, value in items">
     <tr>
         <td>${name}</td>
-        <td>${value}</td>
+        <td class="td-numeric">${value}</td>
     </tr>
     </py:for>
  </table>
@@ -63,12 +63,13 @@
     <div id="minornavigation-bg-left">
     <div id="minornavigation-bg-right">
       <ul class="nav nav-pills">
-        <li py:attrs="{'class': 'active' if active_name=='Site-wide' else None}"><a py:attrs="{'class': 'active' if active_name=='Site-wide' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='index')}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Site-wide</a></li>
+        <?python querystring='?month='+c.month if c.month else '' ?>
+        <li py:attrs="{'class': 'active' if active_name=='Site-wide' else None}"><a py:attrs="{'class': 'active' if active_name=='Site-wide' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='index')}${querystring}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Site-wide</a></li>
         <li py:attrs="{'class': 'active' if active_name=='Publishers' else None}">
-                <a py:attrs="{'class': 'active' if active_name=='Publishers' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publishers')}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Publishers</a>
+        <a py:attrs="{'class': 'active' if active_name=='Publishers' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publishers')}${querystring}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Publishers</a>
         </li>
         <li py:attrs="{'class': 'active' if active_name=='Datasets' else None}">
-                <a py:attrs="{'class': 'active' if active_name=='Datasets' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='read')}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Datasets</a>
+        <a py:attrs="{'class': 'active' if active_name=='Datasets' else None}"  href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='read')}${querystring}"><img src="/images/icons/page_white.png" height="16px" width="16px" alt="None" class="inline-icon "/> Datasets</a>
         </li>
       </ul>
     </div>

--- a/ckanext/ga_report/templates/ga_report/publisher/index.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/index.html
@@ -24,9 +24,10 @@
 
   <py:def function="optional_head">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>
-    <link rel="stylesheet" type="text/css" href="/css/ga_report.css"/>
-    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js"></script>
+    <link rel="stylesheet" type="text/css" href="/css/ga_report.css?1"/>
+    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js?1"></script>
     <script type="text/javascript" src="/scripts/vendor/jquery.sparkline.modified.js"></script>
+    <script type="text/javascript" src="/scripts/rickshaw_ie7_shim.js"></script>
     <script type="text/javascript" src="/scripts/vendor/d3.v2.js"></script>
     <script type="text/javascript" src="/scripts/vendor/d3.layout.min.js"></script>
     <script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
@@ -47,17 +48,17 @@
           </div>
        </form>
 
-       <table class="table table-condensed table-bordered table-striped">
+       <table class="ga-reports-table table table-condensed table-bordered table-striped">
 	 <tr>
 	   <th>Publisher</th>
-	   <th>Dataset Views</th>
+	   <th class="td-numeric">Dataset Views</th>
 	 </tr>
         <py:for each="publisher, views, visits in c.top_publishers">
 	  <tr>
 	    <td>
 	        ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name) + (("?month=" + c.month) if c.month else ''))}
 	    </td>
-	    <td>${views}</td>
+	    <td class="td-numeric">${views}</td>
 	  </tr>
         </py:for>
        </table>

--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -9,9 +9,10 @@
 
   <py:def function="optional_head">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>
-    <link rel="stylesheet" type="text/css" href="/css/ga_report.css"/>
-    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js"></script>
+    <link rel="stylesheet" type="text/css" href="/css/ga_report.css?1"/>
+    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js?1"></script>
     <script type="text/javascript" src="/scripts/vendor/jquery.sparkline.modified.js"></script>
+    <script type="text/javascript" src="/scripts/rickshaw_ie7_shim.js"></script>
     <script type="text/javascript" src="/scripts/vendor/d3.v2.js"></script>
     <script type="text/javascript" src="/scripts/vendor/d3.layout.min.js"></script>
     <script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
@@ -61,7 +62,7 @@
         </div>
      </form>
      <py:if test="c.top_packages">
-       <table class="table table-condensed table-bordered table-striped">
+       <table class="ga-reports-table table table-condensed table-bordered table-striped">
          <tr>
            <th>Dataset</th>
            <th>Views</th>
@@ -72,8 +73,8 @@
              <td>
                ${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}
              </td>
-             <td>${views}</td>
-             <td>${downloads}</td>
+             <td class="td-numeric">${views}</td>
+             <td class="td-numeric">${downloads}</td>
           </tr>
         </py:for>
       </table>

--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -9,8 +9,8 @@
 
   <py:def function="optional_head">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>
-    <link rel="stylesheet" type="text/css" href="/css/ga_report.css"/>
-    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js"></script>
+    <link rel="stylesheet" type="text/css" href="/css/ga_report.css?1"/>
+    <script type="text/javascript" src="/scripts/ckanext_ga_reports.js?1"></script>
     <script type="text/javascript" src="/scripts/vendor/jquery.sparkline.modified.js"></script>
     <script type="text/javascript" src="/scripts/rickshaw_ie7_shim.js"></script>
     <script type="text/javascript" src="/scripts/vendor/d3.v2.js"></script>
@@ -71,16 +71,16 @@
       </ul>
       <div class="tab-content">
         <div class="tab-pane" id="totals">
-             <table class="table table-condensed table-bordered table-striped">
+             <table class="ga-reports-table table table-condensed table-bordered table-striped">
             	 <tr>
             	   <th>Name</th>
-            	   <th>Value</th>
+            	   <th class="td-numeric">Value</th>
             	   <th>History</th>
             	 </tr>
                 <py:for each="name, value, graph in c.global_totals">
                     <tr>
                         <td>${name}</td>
-                        <td>${value}</td>
+                        <td class="td-numeric">${value}</td>
                         <td class="sparkline-cell">
                           <span class="sparkline" sparkTooltips="${','.join([x for x,y in graph])}">
                             ${','.join([y for x,y in graph])}