diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb
index 2c3e500a5..186f242be 100644
--- a/app/helpers/timelog_helper.rb
+++ b/app/helpers/timelog_helper.rb
@@ -125,4 +125,26 @@ module TimelogHelper
cancel_button_tag(fallback_path)
end
+ def report_to_chart_datas(report, period_name='month')
+ return {} if report.periods.nil?
+ chart_datas = {}
+
+ chart_datas[period_name] = { :labels => [], :type => 'bar', :datasets => [{:data => []}] }
+ report.periods.each do |period|
+ chart_datas[period_name][:labels] << period
+ chart_datas[period_name][:datasets].first[:data] << sum_hours(select_hours(report.hours, report.columns, period.to_s))
+ end
+
+ report.criteria.each_with_index do |criteria, level|
+ chart_datas[criteria] = { :labels => [], :type => 'horizontalBar', :datasets => [{:data => []}]}
+ report.hours.collect {|h| h[criteria]}.uniq.each do |value|
+ hours_for_value = select_hours(report.hours, criteria, value)
+ next if hours_for_value.empty?
+ chart_datas[criteria][:labels] << format_criteria_value(report.available_criteria[report.criteria[level]], value, false).to_s
+ chart_datas[criteria][:datasets].first[:data] << report.periods.collect {|period| sum_hours(select_hours(hours_for_value, report.columns, period.to_s)) }.sum
+ end
+ end
+
+ chart_datas
+ end
end
diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb
index ee6f0f83b..f6998d1f3 100644
--- a/app/views/timelog/report.html.erb
+++ b/app/views/timelog/report.html.erb
@@ -14,6 +14,7 @@
<%= hidden_field_tag 'criteria[]', criterion, :id => nil %>
<% end %>
<%= render :partial => 'timelog/date_range' %>
+
<%= link_to l(:label_statistics), '#', :onclick => "showAndScrollTo('timelog_chart')", :class => 'icon icon-stats' if @report.criteria.any? && @report.hours.any? %>
: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
[l(:label_month), 'month'],
@@ -68,6 +69,7 @@
<% other_formats_links do |f| %>
<%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
<% end %>
+
<% end %>
<%= l(:label_export_options, :export_format => 'CSV') %>
@@ -88,6 +90,35 @@
<%= javascript_tag do %>
+function renderChart(canvas_id, chart_data, title){
+ var backgroundColors = ['rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)'];
+ var borderColors = ['rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)'];
+ chart_data.datasets[0].backgroundColor = [];
+ chart_data.datasets[0].borderColor = [];
+ chart_data.datasets[0].borderWidth = [];
+ for (var i = 0; i < chart_data.datasets[0].data.length; i++) {
+ chart_data.datasets[0].backgroundColor[i] = backgroundColors[i % backgroundColors.length];
+ chart_data.datasets[0].borderColor[i] = borderColors[i % backgroundColors.length];
+ chart_data.datasets[0].borderWidth[i] = 1;
+ }
+ if (chart_data.type=='horizontalBar' & chart_data.labels.length > 40) {
+ var ctx = $(canvas_id);
+ ctx.attr('height', chart_data.labels.length * 5);
+ }
+ new Chart($(canvas_id), {
+ type: chart_data.type,
+ data: chart_data,
+ options: {
+ responsive: true,
+ legend: { display: false },
+ title: { display: true, text: title },
+ scales: {
+ xAxes: [ { ticks: { beginAtZero: true } } ],
+ yAxes: [ { ticks: { beginAtZero: true } } ]
+ },
+ },
+ });
+}
$(document).ready(function(){
$('input#csv-export-button').click(function(){
$('form input#encoding').val($('select#encoding option:selected').val());
@@ -95,5 +126,14 @@ $(document).ready(function(){
$('form#query_form').attr('action', '<%= _report_time_entries_path(@project, nil) %>');
hideModal(this);
});
+ <% report_to_chart_datas(@report, params[:columns]).each do |column, chart_data| %>
+ $('#timelog_chart').append('');
+ renderChart("#<%= column %>_timelog_chart",
+ <%= chart_data.to_json.html_safe %>,
+ "<%= l("label_total_spent_time_per", :column => l_or_humanize(column)) %>");
+ <% end %>
});
<% end %>
+<% content_for :header_tags do %>
+ <%= javascript_include_tag "Chart.bundle.min" %>
+<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3df365c09..d217f00ae 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -834,6 +834,11 @@ en:
label_f_hour_plural: "%{value} hours"
label_f_hour_short: "%{value} h"
label_time_tracking: Time tracking
+ label_total_spent_time_per: Total spent time per %{column}
+ label_year_spent_time_per: Annual spent time per %{column}
+ label_month_spent_time_per: Monthly spent time per %{column}
+ label_week_spent_time_per: Weekly spent time per %{column}
+ label_day_spent_time_per: Daily spent time per %{column}
label_change_plural: Changes
label_statistics: Statistics
label_commits_per_month: Commits per month