public
Description: Gitorious aims to provide a great way of doing distributed opensource code collaboration.
Homepage: http://gitorious.org/projects/gitorious
Clone URL: git://github.com/dysinger/gitorious.git
js (author)
Sun Apr 27 14:34:24 -0700 2008
commit  4d372ef9ab1c5c08425c46066e6b103ed07d06c4
tree    1acc5357ca22d4790425c05dbd9d0c523c9b55f4
parent  d32a4cc201f9d57c1b288569d5b8b01d9ce7cb97
gitorious / lib / gitorious / graphs / commits_builder.rb
100644 64 lines (54 sloc) 1.965 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Gitorious
  module Graphs
    
    class CommitsBuilder < Gitorious::Graphs::Builder
      def self.generate_for(repository)
        head = repository.head_candidate
        return if head.nil?
        
        branch = head.name
        if !File.exist?(self.status_file(repository, branch)) && repository.has_commits?
          builder = new(repository, branch)
          builder.build
          builder.write
          FileUtils.touch(self.status_file(repository, branch))
        end
      end
      
      def initialize(repository, branch)
        @repository = repository
        @branch = branch
        @graph = Gruff::Area.new("650x100")
        @graph.title = "Commits by week (24 week period)"
        #@graph.x_axis_label = 'Commits by week (24 week period)'
        #@graph.y_axis_label = "Commits"
        @graph.theme = self.class.default_theme
        @graph.hide_legend = true
        @graph.title_font_size = 12.5
        @graph.marker_font_size = 12
        @graph.top_margin = 1
        @graph.bottom_margin = 1
      end
      
      def build
        week_numbers, commits_by_week = @repository.commit_graph_data(@branch)
        
        @graph.y_axis_increment = commits_by_week.max# / 3
        @graph.data("Commits", commits_by_week)
        @graph.labels = build_labels(week_numbers)
      end
      
      def self.filename(repository, branch)
        Builder.construct_filename(repository, branch, "commit_count")
      end
      
      def construct_filename
        CommitsBuilder.filename(@repository, @branch)
      end
      
      private
        def build_labels(week_numbers)
          label_names = {}
          week_numbers.each_with_index do |week, index|
            if (index % 5) == 0
              label_names[index] = "Week #{week}"
            end
          end
          label_names[week_numbers.index(week_numbers.last)] = "Week #{week_numbers.last}"
          label_names
        end
    end
    
  end
end