Blob of lib/gitorious/graphs/commits_builder.rb (raw blob data)

1 module Gitorious
2 module Graphs
3
4 class CommitsBuilder < Gitorious::Graphs::Builder
5 def self.generate_for(repository)
6 head = repository.head_candidate
7 return if head.nil?
8
9 branch = head.name
10 if !File.exist?(self.status_file(repository, branch)) && repository.has_commits?
11 builder = new(repository, branch)
12 builder.build
13 builder.write
14 FileUtils.touch(self.status_file(repository, branch))
15 end
16 end
17
18 def initialize(repository, branch)
19 @repository = repository
20 @branch = branch
21 @graph = Gruff::Area.new("650x100")
22 @graph.title = "Commits by week (24 week period)"
23 #@graph.x_axis_label = 'Commits by week (24 week period)'
24 #@graph.y_axis_label = "Commits"
25 @graph.theme = self.class.default_theme
26 @graph.hide_legend = true
27 @graph.title_font_size = 12.5
28 @graph.marker_font_size = 12
29 @graph.top_margin = 1
30 @graph.bottom_margin = 1
31 end
32
33 def build
34 week_numbers, commits_by_week = @repository.commit_graph_data(@branch)
35
36 @graph.y_axis_increment = commits_by_week.max# / 3
37 @graph.data("Commits", commits_by_week)
38 @graph.labels = build_labels(week_numbers)
39 end
40
41 def self.filename(repository, branch)
42 Builder.construct_filename(repository, branch, "commit_count")
43 end
44
45 def construct_filename
46 CommitsBuilder.filename(@repository, @branch)
47 end
48
49 private
50 def build_labels(week_numbers)
51 label_names = {}
52 week_numbers.each_with_index do |week, index|
53 if (index % 5) == 0
54 label_names[index] = "Week #{week}"
55 end
56 end
57 label_names[week_numbers.index(week_numbers.last)] = "Week #{week_numbers.last}"
58 label_names
59 end
60 end
61
62 end
63 end