From: Tom Rees Date: Tue, 19 Mar 2013 16:41:09 +0000 Subject: [304] Remove minornavigation elements from ga-report extension. X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=d43b5ab38f673a10802af9505272e6578d9ac759 --- [304] Remove minornavigation elements from ga-report extension. --- --- 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 @@ -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; @@ -18,6 +23,7 @@ .rickshaw_legend { background: transparent; width: 100%; + padding-top: 4px; } .rickshaw_y_axis { position: absolute; @@ -29,6 +35,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 +54,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('
Click on a series below to isolate its graph:
'); 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(); + } ); }; @@ -81,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'); @@ -94,39 +100,23 @@ } legend_name = '#legend_'+legend_name; $('#graph-legend-container > *').hide(); + $('#graph-legend-container .instructions').show(); $(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() { 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); 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/ga_util.html +++ b/ckanext/ga_report/templates/ga_report/ga_util.html @@ -14,7 +14,7 @@ - +
@@ -24,7 +24,7 @@ - +
Name Source
${name} ${source}${count}${count}
@@ -45,34 +45,29 @@ - +
- + - +
Name% ${title}% ${title}
${name}${value}${value}
-
-
-
- -
-
+
+ + + Site-wide + | + Publishers + | + Datasets +
--- a/ckanext/ga_report/templates/ga_report/publisher/index.html +++ b/ckanext/ga_report/templates/ga_report/publisher/index.html @@ -6,6 +6,8 @@ Usage by Publisher + +
  • @@ -24,9 +26,10 @@ - - + + + @@ -34,36 +37,34 @@
    -

    Site Usage

    +

    Site Usage ${usage_nav('Publishers')}

    - ${usage_nav('Publishers')} - +
    ${rickshaw_graph(c.top_publishers_graph,'publishers')} -
    +
    ${month_selector(c.month, c.months, c.day)}
    - - - - - +
    PublisherDataset Views
    + + + + - - - - + + + +
    PublisherDataset Views
    - ${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 ''))} - ${views}
    + ${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 ''))} + ${views}
    - - -
    +
    +
  • + + + @@ -34,11 +37,9 @@
    -

    Site Usage

    +

    Site Usage ${usage_nav('Datasets')}

    - ${usage_nav('Datasets')} - - +

    ${c.publisher.title}

    No page views in this period

    @@ -61,7 +62,7 @@
    - +
    @@ -72,13 +73,14 @@ - - + +
    Dataset Views ${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))} ${views}${downloads}${views}${downloads}
    +
    --- a/ckanext/ga_report/templates/ga_report/site/downloads.html +++ b/ckanext/ga_report/templates/ga_report/site/downloads.html @@ -6,6 +6,8 @@ Downloads + +
  • @@ -19,8 +21,9 @@
    -

    Downloads

    - ${usage_nav('Downloads')} +

    Downloads ${usage_nav('Downloads')}

    + +
    @@ -38,6 +41,7 @@

    No data

    There is no download data available for this month

    +
    --- a/ckanext/ga_report/templates/ga_report/site/index.html +++ b/ckanext/ga_report/templates/ga_report/site/index.html @@ -7,10 +7,12 @@ Site usage + + - - + + @@ -36,51 +38,55 @@
    -

    Site Usage

    - ${usage_nav('Site-wide')} +

    Site Usage ${usage_nav('Site-wide')}

    +
    -
    - +
    + + + ${month_selector(c.month, c.months, c.day)} + +
    - + - +
    NameValueValue History
    ${name}${value}${value} ${','.join([y for x,y in graph])} @@ -158,6 +164,7 @@ + @@ -167,12 +174,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'); - } });