diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 32c7c25d7..657ef58b0 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -37,16 +37,16 @@ module GitStats commits.map(&:date).minmax end - def commits_count_by_author - Hash[authors.map { |author| [author, author.commits.size] }.sort_by { |author, commits| -commits }[0..5]] + def commits_count_by_author(limit = 4) + Hash[authors.map { |author| [author, author.commits.size] }.sort_by { |author, commits| -commits }[0..limit]] end - def lines_added_by_author - Hash[authors.map { |author| [author, author.lines_added] }.sort_by { |author, lines| -lines }[0..5]] + def lines_added_by_author(limit = 4) + Hash[authors.map { |author| [author, author.lines_added] }.sort_by { |author, lines| -lines }[0..limit]] end - def lines_deleted_by_author - Hash[authors.map { |author| [author, author.lines_deleted] }.sort_by { |author, lines| -lines }[0..5]] + def lines_deleted_by_author(limit = 4) + Hash[authors.map { |author| [author, author.lines_deleted] }.sort_by { |author, lines| -lines }[0..limit]] end def files_count_by_date diff --git a/lib/git_stats/stats_view/charts/authors_charts.rb b/lib/git_stats/stats_view/charts/authors_charts.rb index 791ac749a..c2c1488f9 100644 --- a/lib/git_stats/stats_view/charts/authors_charts.rb +++ b/lib/git_stats/stats_view/charts/authors_charts.rb @@ -6,30 +6,30 @@ module GitStats @authors = authors end - def commits_sum_by_author_by_date + def commits_sum_by_author_by_date(limit = 4) Chart.new do |f| f.multi_date_chart( - data: @authors.sort_by { |author| -author.commits.size }[0..5].map { |author| {name: author.email, data: author.commits_sum_by_date} }, + data: @authors.sort_by { |author| -author.commits.size }[0..limit].map { |author| {name: author.email, data: author.commits_sum_by_date} }, title: :lines_by_date.t, y_text: :lines.t ) end end - def lines_added_by_author_by_date + def lines_added_by_author_by_date(limit = 4) Chart.new do |f| f.multi_date_chart( - data: @authors.sort_by { |author| -author.lines_added }[0..5].map { |author| {name: author.email, data: author.lines_added_by_date} }, + data: @authors.sort_by { |author| -author.lines_added }[0..limit].map { |author| {name: author.email, data: author.lines_added_by_date} }, title: :lines_by_date.t, y_text: :lines.t ) end end - def lines_deleted_by_author_by_date + def lines_deleted_by_author_by_date(limit = 4) Chart.new do |f| f.multi_date_chart( - data: @authors.sort_by { |author| -author.lines_deleted }[0..5].map { |author| {name: author.email, data: author.lines_deleted_by_date} }, + data: @authors.sort_by { |author| -author.lines_deleted }[0..limit].map { |author| {name: author.email, data: author.lines_deleted_by_date} }, title: :lines_by_date.t, y_text: :lines.t ) diff --git a/lib/git_stats/stats_view/charts/chart.rb b/lib/git_stats/stats_view/charts/chart.rb index e382a9ddb..340cbf7a6 100644 --- a/lib/git_stats/stats_view/charts/chart.rb +++ b/lib/git_stats/stats_view/charts/chart.rb @@ -43,6 +43,7 @@ module GitStats def multi_date_chart(params) common_options(params) + default_legend params[:data].each do |s| series( name: s[:name], @@ -60,6 +61,7 @@ module GitStats def default_legend legend( + enabled: true, layout: 'vertical', backgroundColor: '#FFFFFF', align: 'left',