Sha256: ebdbb92ecdd59edcb4cb8d5f9ac1adbf03219aa73c99f96f6cb99b400c8ae263

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module GitStats
  module StatsView
    module Charts
      class AuthorsCharts
        AUTHORS_ON_CHART_LIMIT = 5

        def initialize(authors)
          @authors = authors
        end

        [:commits_sum].each do |method|
          define_method "#{method}_by_author_by_date" do |authors = nil|
            Chart.new do |f|
              authors ||= @authors.sort_by { |a| -a.send(method) }[0...AUTHORS_ON_CHART_LIMIT]
              f.multi_date_chart(
                data: authors.map { |a| {name: a.name, data: a.send("#{method}_by_date")} },
                title: :lines_by_date.t,
                y_text: :lines.t
              )
            end
          end
        end

        [:insertions, :deletions, :changed_lines].each do |method|
          define_method "total_#{method}_by_author_by_date" do |authors = nil|
            Chart.new do |f|
              authors ||= @authors.sort_by { |a| -a.send(method) }[0...AUTHORS_ON_CHART_LIMIT]
              f.multi_date_chart(
                data: authors.map { |a| {name: a.name, data: a.send("total_#{method}_by_date")} },
                title: :lines_by_date.t,
                y_text: :lines.t
              )
            end
          end

          define_method "#{method}_by_author_by_date" do |author|
            Chart.new do |f|
              f.date_column_chart(
                data: author.send("#{method}_by_date"),
                title: :lines_by_date.t,
                y_text: :lines.t
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nova_git_stats-2.2.0 lib/git_stats/stats_view/charts/authors_charts.rb