aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-10-15 13:47:08 +0100
committerMark Longair <mhl@pobox.com>2013-10-15 13:57:45 +0100
commitf3ecb5b64229f5e566be3b8df3d7b87e9bb6dd75 (patch)
tree7cecaed74c9f30ad3c3c1df8f3cde434ab37f51c
parent7e1ed07ea7f6448b1fada769e04b0369fdd0a222 (diff)
Make bars in public body statistics charts clickable
Now if you click on the bar representing statistics for a particular public body, it will take you to that public body's page. In addition, the bars are highlighted when you hover over them.
-rw-r--r--app/views/public_body/statistics.html.erb4
-rw-r--r--public/javascripts/stats-graphs.js13
2 files changed, 15 insertions, 2 deletions
diff --git a/app/views/public_body/statistics.html.erb b/app/views/public_body/statistics.html.erb
index e23f47405..992ec1fca 100644
--- a/app/views/public_body/statistics.html.erb
+++ b/app/views/public_body/statistics.html.erb
@@ -52,9 +52,9 @@ are due to him.") %></p>
</tr>
</thead>
<tbody>
- <% graph_data['x_ticks'].each_with_index do |pb_and_index, i| %>
+ <% graph_data['public_bodies'].each_with_index do |pb, i| %>
<tr>
- <td><%= pb_and_index[1] %></td>
+ <td><%= link_to pb['name'], pb['url'] %></td>
<td class="statistic"><%= graph_data['y_values'][i].round %></td>
</tr>
<% end %>
diff --git a/public/javascripts/stats-graphs.js b/public/javascripts/stats-graphs.js
index f738427ae..7afbd20c1 100644
--- a/public/javascripts/stats-graphs.js
+++ b/public/javascripts/stats-graphs.js
@@ -56,6 +56,7 @@ $(document).ready(function() {
}
options = {
+ 'grid': { 'hoverable': true, 'clickable': true },
'xaxis': {
'ticks': graph_data.x_ticks,
'rotateTicks': 90
@@ -84,5 +85,17 @@ $(document).ready(function() {
plot = $.plot(graph_div,
dataset,
options);
+
+ graph_div.bind("plotclick", function(event, pos, item) {
+ var i, pb, url, name;
+ if (item) {
+ i = item.dataIndex;
+ pb = graph_data.public_bodies[i];
+ url = pb.url;
+ name = pb.name;
+ window.location.href = url;
+ }
+ });
+
});
});