mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-07 09:48:50 +01:00
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.
This commit is contained in:
parent
0cd6656be2
commit
6e2f1a8e5f
4 changed files with 19 additions and 32 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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&
|
||||
|
|
@ -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&
|
||||
9
app/views/stats/pie_chart_data.html.erb
Executable file
9
app/views/stats/pie_chart_data.html.erb
Executable file
|
|
@ -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&
|
||||
Loading…
Add table
Add a link
Reference in a new issue