From 6e2f1a8e5f0700119a764203197d20a5becafff7 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Sun, 17 Mar 2013 19:38:57 -0600 Subject: [PATCH] De-dupe pie chart view Pull logic into the controller from the view. There were only a couple of tiny differences between the running actions and the total actions view, so I added a couple of instance variables and then called the same template twice. --- app/controllers/stats_controller.rb | 12 ++++++++++-- .../stats/context_running_actions_data.html.erb | 15 --------------- .../stats/context_total_actions_data.html.erb | 15 --------------- app/views/stats/pie_chart_data.html.erb | 9 +++++++++ 4 files changed, 19 insertions(+), 32 deletions(-) delete mode 100755 app/views/stats/context_running_actions_data.html.erb delete mode 100755 app/views/stats/context_total_actions_data.html.erb create mode 100755 app/views/stats/pie_chart_data.html.erb diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 545a87a1..5e669cf0 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -179,17 +179,21 @@ class StatsController < ApplicationController def context_total_actions_data all_actions_per_context = Stats::TopContextsQuery.new(current_user).result + @title = t('stats.spread_of_actions_for_all_context') + @alpha = 70 prep_context_data_for_view(all_actions_per_context) - render :layout => false + render :pie_chart_data, :layout => false end def context_running_actions_data all_actions_per_context = Stats::TopContextsQuery.new(current_user, :running => true).result + @title = t('stats.spread_of_running_actions_for_visible_contexts') + @alpha = 60 prep_context_data_for_view(all_actions_per_context) - render :layout => false + render :pie_chart_data, :layout => false end def actions_day_of_week_all_data @@ -363,6 +367,10 @@ class StatsController < ApplicationController end @truncate_chars = 15 + + @pie_slices = Array.new(size){|i| @actions_per_context[i]['total'].to_i*100/@sum } + @pie_labels = Array.new(size){|i| @actions_per_context[i]['name'].truncate(@truncate_chars, :omission => '...') } + @pie_links = Array.new(size){|i| context_path(@actions_per_context[i]['id'])} end def init diff --git a/app/views/stats/context_running_actions_data.html.erb b/app/views/stats/context_running_actions_data.html.erb deleted file mode 100755 index 690a82f4..00000000 --- a/app/views/stats/context_running_actions_data.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% - size = @actions_per_context.size() - pie_slices = Array.new(size){|i| @actions_per_context[i]['total'].to_i*100/@sum } - pie_labels = Array.new(size){|i| truncate(@actions_per_context[i]['name'], :length => @truncate_chars, :omission => '...') } - pie_links = Array.new(size){|i| url_for :controller => "contexts", :action => "show", :id=>@actions_per_context[i]['id']} --%> -&title=<%= t('stats.spread_of_running_actions_for_visible_contexts') %>,{font-size:16}& -&pie=60,#505050,{font-size: 12px; color: #404040;}& -&x_axis_steps=1& &y_ticks=5,10,5& &line=3,#87421F& &y_min=0& &y_max=20& -&values=<%= pie_slices.join(",") %>& -&pie_labels=<%= pie_labels.join(",") %>& -&links=<%= pie_links.join(",") %>& -&colours=#d01f3c,#356aa0,#C79810,#c61fd0,#1fc6d0,#1fd076,#72d01f,#c6d01f,#d0941f,#40941f& -&tool_tip=#x_label#: #val#%25& -&x_label_style=9,,2,1& \ No newline at end of file diff --git a/app/views/stats/context_total_actions_data.html.erb b/app/views/stats/context_total_actions_data.html.erb deleted file mode 100755 index 733bb5a7..00000000 --- a/app/views/stats/context_total_actions_data.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% - size = @actions_per_context.size() - pie_slices = Array.new(size){|i| @actions_per_context[i]['total'].to_i*100/@sum } - pie_labels = Array.new(size){|i| truncate(@actions_per_context[i]['name'], :length => @truncate_chars, :omission => '...') } - pie_links = Array.new(size){|i| url_for :controller => "contexts", :action => "show", :id=>@actions_per_context[i]['id']} --%> -&title=<%= t('stats.spread_of_actions_for_all_context') %>,{font-size:16}& -&pie=70,#505050,{font-size: 12px; color: #404040;}& -&x_axis_steps=1& &y_ticks=5,10,5& &line=3,#87421F& &y_min=0& &y_max=20& -&values=<%= pie_slices.join(",") %>& -&pie_labels=<%= pie_labels.join(",") %>& -&links=<%= pie_links.join(",") %>& -&colours=#d01f3c,#356aa0,#C79810,#c61fd0,#1fc6d0,#1fd076,#72d01f,#c6d01f,#d0941f,#40941f& -&tool_tip=#x_label#: #val#%25& -&x_label_style=9,,2,1& \ No newline at end of file diff --git a/app/views/stats/pie_chart_data.html.erb b/app/views/stats/pie_chart_data.html.erb new file mode 100755 index 00000000..de466212 --- /dev/null +++ b/app/views/stats/pie_chart_data.html.erb @@ -0,0 +1,9 @@ +&title=<%= @title %>,{font-size:16}& +&pie=<%= @alpha %>,#505050,{font-size: 12px; color: #404040;}& +&x_axis_steps=1& &y_ticks=5,10,5& &line=3,#87421F& &y_min=0& &y_max=20& +&values=<%= @pie_slices.join(",") %>& +&pie_labels=<%= @pie_labels.join(",") %>& +&links=<%= @pie_links.join(",") %>& +&colours=#d01f3c,#356aa0,#C79810,#c61fd0,#1fc6d0,#1fd076,#72d01f,#c6d01f,#d0941f,#40941f& +&tool_tip=#x_label#: #val#%25& +&x_label_style=9,,2,1&