Sha256: 83187fb0d3c777b5733231b90b1bce3b552251d1785a4df070b31501b4794142

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

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

3 entries across 3 versions & 1 rubygems

Version Path
nova_git_stats-2.4.1 lib/git_stats/stats_view/charts/authors_charts.rb
nova_git_stats-2.4.0 lib/git_stats/stats_view/charts/authors_charts.rb
nova_git_stats-2.3.0 lib/git_stats/stats_view/charts/authors_charts.rb