diff --git a/config/locales/en.yml b/config/locales/en.yml index 74811bc53..550c476aa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,4 +21,6 @@ en: percentage: Percentage day: Day day_of_week: Day of week - hour_of_week: Hour of week \ No newline at end of file + hour_of_week: Hour of week + month: Month + month_of_year: Month of year \ No newline at end of file diff --git a/lib/git_stats/git_data/activity.rb b/lib/git_stats/git_data/activity.rb index 9396163be..c74d5c450 100644 --- a/lib/git_stats/git_data/activity.rb +++ b/lib/git_stats/git_data/activity.rb @@ -30,6 +30,10 @@ module GitStats @by_month ||= default_hash end + def by_month_array + by_month.to_key_indexed_array(min_size: 12, default: 0) + end + def by_year @by_year ||= default_hash end diff --git a/lib/git_stats/stats_view/charts/activity_charts.rb b/lib/git_stats/stats_view/charts/activity_charts.rb index ffe75312b..8c4703af1 100644 --- a/lib/git_stats/stats_view/charts/activity_charts.rb +++ b/lib/git_stats/stats_view/charts/activity_charts.rb @@ -29,6 +29,18 @@ module GitStats ) end end + + def activity_by_month + Chart.new do |f| + f.simple_column_chart( + title: :commits_by_month.t, + y_text: :commits.t, + x_text: :month.t, + data_x: Date::ABBR_MONTHNAMES, + data_y: @activity.by_month_array + ) + end + end end end end diff --git a/lib/git_stats/stats_view/charts/charts.rb b/lib/git_stats/stats_view/charts/charts.rb index 280cacc2e..f273bfcce 100644 --- a/lib/git_stats/stats_view/charts/charts.rb +++ b/lib/git_stats/stats_view/charts/charts.rb @@ -5,7 +5,7 @@ module GitStats delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date, :lines_added_by_author, :lines_deleted_by_author, to: :repo_charts delegate :by_authors_wday, to: :authors_charts - delegate :activity_by_hour, :activity_by_wday, to: :activity_charts + delegate :activity_by_hour, :activity_by_wday, :activity_by_month, to: :activity_charts attr_reader :repo diff --git a/templates/activity.haml b/templates/activity.haml index c90551c77..3b14b0f98 100644 --- a/templates/activity.haml +++ b/templates/activity.haml @@ -1,48 +1,80 @@ -.page-header - %h1.pagination-centered= :hour_of_day.t -%table{:class => "table table-bordered table-condensed"} - %tr - %th= :hour.t - - (0..23).each do |h| - %th= h - %tr - %th= :commits.t - - repo.activity.by_hour_array.each do |commits| - %td= commits - %tr - %th= :percentage.t - - repo.activity.by_hour_array.each do |commits| - %td= (commits * 100.0 / repo.activity.by_hour_array.sum).round(2) -= high_chart("activity_by_hour", charts.activity_by_hour) +.tabbable.tabs-left + %ul.nav.nav-tabs + %li.active + %a{:href => '#hour_of_day', 'data-toogle' => 'tab'}= :hour_of_day.t + %li + %a{:href => '#day_of_week', 'data-toogle' => 'tab'}= :day_of_week.t + %li + %a{:href => '#hour_of_week', 'data-toogle' => 'tab'}= :hour_of_week.t + %li + %a{:href => '#month_of_year', 'data-toogle' => 'tab'}= :month_of_year.t + + .tab-content + .tab-pane.active{id: 'hour_of_day'} + .page-header + %h1.pagination-centered= :hour_of_day.t + %table{:class => "table table-bordered table-condensed"} + %tr + %th= :hour.t + - (0..23).each do |h| + %th= h + %tr + %th= :commits.t + - repo.activity.by_hour_array.each do |commits| + %td= commits + %tr + %th= :percentage.t + - repo.activity.by_hour_array.each do |commits| + %td= (commits * 100.0 / repo.activity.by_hour_array.sum).round(2) + = high_chart("activity_by_hour", charts.activity_by_hour) + + .tab-pane{id: 'day_of_week'} + .page-header + %h1.pagination-centered= :day_of_week.t + %table{:class => "table table-bordered table-condensed"} + %tr + %th= :day.t + - Date::ABBR_DAYNAMES.each do |d| + %th= d + %tr + %th= :commits.t + - repo.activity.by_wday_array.each do |commits| + %td= commits + %tr + %th= :percentage.t + - repo.activity.by_wday_array.each do |commits| + %td= (commits * 100.0 / repo.activity.by_wday_array.sum).round(2) + = high_chart("activity_by_wday", charts.activity_by_wday) -.page-header - %h1.pagination-centered= :day_of_week.t -%table{:class => "table table-bordered table-condensed"} - %tr - %th= :day.t - - Date::ABBR_DAYNAMES.each do |d| - %th= d - %tr - %th= :commits.t - - repo.activity.by_wday_array.each do |commits| - %td= commits - %tr - %th= :percentage.t - - repo.activity.by_wday_array.each do |commits| - %td= (commits * 100.0 / repo.activity.by_wday_array.sum).round(2) -= high_chart("activity_by_wday", charts.activity_by_wday) + .tab-pane{id: 'hour_of_week'} + .page-header + %h1.pagination-centered= :hour_of_week.t + %table{:class => "table table-bordered table-condensed"} + %tr + %th + - (0..23).each do |h| + %th= h + - (0..6).each do |day| + %tr + %th= Date::ABBR_DAYNAMES[day] + - (0..23).each do |hour| + %td= repo.activity.by_wday_hour[day][hour] - -.page-header - %h1.pagination-centered= :hour_of_week.t -%table{:class => "table table-bordered table-condensed"} - %tr - %th - - (0..23).each do |h| - %th= h - - (0..6).each do |day| - %tr - %th= Date::ABBR_DAYNAMES[day] - - (0..23).each do |hour| - %td= repo.activity.by_wday_hour[day][hour] + .tab-pane{id: 'month_of_year'} + .page-header + %h1.pagination-centered= :month_of_year.t + %table{:class => "table table-bordered table-condensed"} + %tr + %th= :day.t + - Date::ABBR_MONTHNAMES.each do |m| + %th= m + %tr + %th= :commits.t + - repo.activity.by_month_array.each do |commits| + %td= commits + %tr + %th= :percentage.t + - repo.activity.by_month_array.each do |commits| + %td= (commits * 100.0 / repo.activity.by_month_array.sum).round(2) + = high_chart("activity_by_month", charts.activity_by_month) diff --git a/templates/layout.haml b/templates/layout.haml index 314138148..a54e114e3 100644 --- a/templates/layout.haml +++ b/templates/layout.haml @@ -11,6 +11,14 @@ %script{:src => "assets/jquery.min.js", :type => "text/javascript"} %script{:src => "assets/bootstrap/js/bootstrap.min.js", :type => "text/javascript"} %script{:src => "assets/highstock.js", :type => "text/javascript"} + %script + :plain + $(function() { + $('.tabbable ul a').click(function (e) { + e.preventDefault(); + $(this).tab('show'); + }) + }); %body %div.navbar.navbar-inverse.navbar-fixed-top %div.navbar-inner