From: Tom Rees Date: Tue, 02 Apr 2013 16:25:45 +0000 Subject: [403] Fix rickshaw choking if there is an empty 'Others' series. X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=712b17e95c6b16fa6a688d274665b2d1701515ba --- [403] Fix rickshaw choking if there is an empty 'Others' series. --- --- 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,12 +448,13 @@ 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', - 'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] - }) + if len(others): + data.append({ + 'name':'Other', + 'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] + }) # Turn each point into a percentage for series in data: for point in series['data']: --- 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 @@ -69,9 +69,9 @@ spotColor: '', maxSpotColor: '', minSpotColor: '', - highlightSpotColor: '000000', - lineColor: '3F8E6D', - fillColor: 'B7E66B' + highlightSpotColor: '#000000', + lineColor: '#3F8E6D', + fillColor: '#B7E66B' }; $('.sparkline').sparkline('html',sparkOptions); created = true; @@ -87,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'); @@ -104,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() { @@ -118,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/site/index.html +++ b/ckanext/ga_report/templates/ga_report/site/index.html @@ -41,36 +41,40 @@
-
+
+
+ + ${month_selector(c.month, c.months, c.day)} +
@@ -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'); - } });
Name