[403] Rickshaw graph always renders all series, no matter which month is selected.
--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -218,7 +218,10 @@
'x':_get_unix_epoch(stat.period_name),
'y':float(stat.value)
})
- graph = [ graph_dict[x[0]] for x in entries ]
+ stats_in_table = [x[0] for x in entries]
+ stats_not_in_table = set(graph_dict.keys()) - set(stats_in_table)
+ stats = stats_in_table + sorted(list(stats_not_in_table))
+ graph = [graph_dict[x] for x in stats]
setattr(c, v+'_graph', json.dumps( _to_rickshaw(graph,percentageMode=True) ))
# Get the total for each set of values and then set the value as
@@ -445,7 +448,7 @@
fraction = float(point['y']) / totals[point['x']]
if not (series in data) and fraction>THRESHOLD:
data.append(series)
- # Overwrite data with a set of intereting series
+ # Overwrite data with a set of interesting series
others = [ x for x in raw_data if not (x in data) ]
data.append({
'name':'Other',
--- a/ckanext/ga_report/public/css/ga_report.css
+++ b/ckanext/ga_report/public/css/ga_report.css
@@ -2,6 +2,11 @@
padding: 1px 0 0 0;
width: 108px;
text-align: center;
+ /* Hack to hide the momentary flash of text
+ * before sparklines are fully rendered */
+ font-size: 1px;
+ color: transparent;
+ overflow: hidden;
}
.rickshaw_chart_container {
position: relative;
--- a/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
+++ b/ckanext/ga_report/public/scripts/ckanext_ga_reports.js
@@ -55,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();
+ }
);
};
@@ -82,7 +87,7 @@
* Show the correct rickshaw graph in the sidebar.
* Not to be called before all graphs load.
*/
- $('a[data-toggle="hashchange"]').on(
+ $('a[data-toggle="hashtab"]').on(
'shown',
function(e) {
var href = $(e.target).attr('href');
@@ -99,6 +104,8 @@
$(legend_name).show();
}
);
+ /* The first tab might already have been shown */
+ $('li.active > a[data-toggle="hashtab"]').trigger('shown');
};
CKAN.GA_Reports.bind_month_selector = function() {
@@ -113,22 +120,3 @@
selectors.bind('change', handler);
};
-/*
- * Custom bootstrap plugin for handling data-toggle="hashchange".
- * Behaves like data-toggle="tab" but I respond to the hashchange.
- * Page state is memo-ized in the URL this way. Why doesn't Bootstrap do this?
- */
-$(function() {
- var mapping = {};
- $('a[data-toggle="hashchange"]').each(
- function(i,link) {
- link = $(link);
- mapping[link.attr('href')] = link;
- }
- );
- $(window).hashchange(function() {
- var link = mapping[window.location.hash];
- if (link) { link.tab('show'); }
- });
-});
-
--- a/ckanext/ga_report/templates/ga_report/publisher/index.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/index.html
@@ -24,8 +24,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>
--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.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>
--- 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>
@@ -41,36 +41,40 @@
<div class="tabbable">
<ul class="nav nav-tabs">
- <li><a href="#totals" data-toggle="hashchange">Totals</a></li>
+ <li class="active"><a href="#totals" data-toggle="hashtab">Totals</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Browsers
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#browsers_names" data-toggle="hashchange">Browsers</a></li>
- <li><a href="#browsers_versions" data-toggle="hashchange">Versions</a></li>
+ <li><a href="#browsers_names" data-toggle="hashtab">Browsers</a></li>
+ <li><a href="#browsers_versions" data-toggle="hashtab">Versions</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Operating Systems
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#os" data-toggle="hashchange">Operating Systems</a></li>
- <li><a href="#os_versions" data-toggle="hashchange">Versions</a></li>
+ <li><a href="#os" data-toggle="hashtab">Operating Systems</a></li>
+ <li><a href="#os_versions" data-toggle="hashtab">Versions</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Social
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="#social_networks" data-toggle="hashchange">All networks</a></li>
- <li><a href="#social_referrals_totals" data-toggle="hashchange">Referral links</a></li>
+ <li><a href="#social_networks" data-toggle="hashtab">All networks</a></li>
+ <li><a href="#social_referrals_totals" data-toggle="hashtab">Referral links</a></li>
</ul>
</li>
- <li><a href="#languages" data-toggle="hashchange">Languages</a></li>
- <li><a href="#country" data-toggle="hashchange">Country</a></li>
+ <li><a href="#languages" data-toggle="hashtab">Languages</a></li>
+ <li><a href="#country" data-toggle="hashtab">Country</a></li>
</ul>
<div class="tab-content">
- <div class="tab-pane" id="totals">
+ <div class="tab-pane active" id="totals">
+ <form class="form-inline" action="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='index')}" method="get">
+ <label>Show stats table for:</label>
+ ${month_selector(c.month, c.months, c.day)}
+ </form>
<table class="ga-reports-table table table-condensed table-bordered table-striped">
<tr>
<th>Name</th>
@@ -167,12 +171,6 @@
CKAN.GA_Reports.bind_sparklines();
CKAN.GA_Reports.bind_sidebar();
CKAN.GA_Reports.bind_month_selector();
- if (!window.location.hash) {
- window.location.hash='totals';
- }
- else {
- $(window).trigger('hashchange');
- }
});
</script>
</py:def>