diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-09-24 11:29:31 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-09-24 11:29:31 +0100 |
commit | d8deb8418b4cd26c68eb1301959e156c19b111e2 (patch) | |
tree | 99c346db95d17be9c5105ce47d5f3ac8e943e952 /public/javascripts/stats-graphs.js | |
parent | 8459314b691f5b02277035219cd58f510d100a77 (diff) | |
parent | 75542416a1cc36b353ade557b1bc4f729b02423a (diff) |
Merge branch 'release/0.14'0.14
Conflicts:
locale/bg/app.po
locale/fr/app.po
locale/fr_CA/app.po
locale/he_IL/app.po
locale/hr/app.po
locale/it/app.po
locale/nb_NO/app.po
locale/pl/app.po
locale/sv/app.po
locale/vi/app.po
Diffstat (limited to 'public/javascripts/stats-graphs.js')
-rw-r--r-- | public/javascripts/stats-graphs.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/public/javascripts/stats-graphs.js b/public/javascripts/stats-graphs.js new file mode 100644 index 000000000..73e19a6fc --- /dev/null +++ b/public/javascripts/stats-graphs.js @@ -0,0 +1,87 @@ +/* From http://stackoverflow.com/a/10284006/223092 */ +function zip(arrays) { + return arrays[0].map(function(_,i){ + return arrays.map(function(array){return array[i]}) + }); +} + +$(document).ready(function() { + $.each(graphs_data, function(index, graph_data) { + var graph_id = graph_data.id, + dataset, + plot, + graph_data, + graph_div = $('#' + graph_id); + + if (!graph_data.x_values) { + /* Then there's no data for this graph */ + return true; + } + + graph_div.css('width', '700px'); + graph_div.css('height', '400px'); + + dataset = [ + {'color': 'orange', + 'bars': { + 'show': true, + 'barWidth': 0.5, + 'align': 'center' + }, + 'data': zip([graph_data.x_values, + graph_data.y_values]) + } + ] + + if (graph_data.errorbars) { + dataset.push({ + 'color': 'orange', + 'points': { + // Don't show these, just draw error bars: + 'radius': 0, + 'errorbars': 'y', + 'yerr': { + 'asymmetric': true, + 'show': true, + 'upperCap': "-", + 'lowerCap': "-", + 'radius': 5 + } + }, + 'data': zip([graph_data.x_values, + graph_data.y_values, + graph_data.cis_below, + graph_data.cis_above]) + }); + } + + options = { + 'xaxis': { + 'ticks': graph_data.x_ticks, + }, + 'yaxis': { + 'min': 0, + 'max': graph_data.y_max + }, + 'xaxes': [{ + 'axisLabel': graph_data.x_axis, + 'axisLabelPadding': 20, + 'axisLabelColour': 'black' + }], + 'yaxes': [{ + 'axisLabel': graph_data.y_axis, + 'axisLabelPadding': 20, + 'axisLabelColour': 'black' + }], + 'series': { + 'lines': { + 'show': false + } + }, + } + + plot = $.plot(graph_div, + dataset, + options); + }); +}); |