Commit 28934d756038f96c323599d1ebf7b27cd278b0ec

Generate graphs locally using gruff and ./script/graph_generator

Commit diff

.gitignore

 
22.DS_Store
33coverage/*
44public/cache/*
5public/images/graphs/*
56config/database.yml
67config/gitorious.yml
78config/ultrasphinx/development.conf
toggle raw diff

app/helpers/application_helper.rb

 
8686 flash.map { |type, content| content_tag(:div, content_tag(:p, content), :class => "flash_message #{type}")}
8787 end
8888
89 def commit_graph_tag(repository, sha = "master", width = 650, height = 110)
90 labels, commits = repository.commit_graph_data(sha)
91 return if commits.blank?
92
93 label_names = []
94 labels.each_with_index do |week, index|
95 if (index % 5) == 0
96 label_names << "Week #{week}"
97 end
89 def commit_graph_tag(repository, ref = "master")
90 filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count.png"
91 if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename))
92 image_tag("graphs/#{filename}")
9893 end
99 label_names << "Week #{labels.last}"
100
101 # "<pre>#{labels.inspect}\n#{commits.inspect}</pre>" +
102 Gchart.line({
103 :title => "Commits by week (24 week period)",
104 :data => [0] + commits,
105 :width => width,
106 :height => height,
107 :format => "img_tag",
108 :axis_with_labels => ["y", "x"],
109 :axis_labels => ["|#{commits.max}", label_names.join("|")],
110 :bar_colors => "9cce2e",
111 :custom => "chm=B,E4E9D4,0,0,0",
112 :max_value => "auto"
113 })
11494 end
11595
116 def commit_graph_by_author_tag(repos, sha = "master", width = 350, height = 150)
117 labels, data = repos.commit_graph_data_by_author
118
119 Gchart.pie({
120 :title => "Commits by author",
121 :data => data,
122 :labels => labels,
123 :width => width,
124 :height => height,
125 :bar_colors => "9cce2e",
126 :format => "img_tag"
127 })
96 def commit_graph_by_author_tag(repository, ref = "master")
97 filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count_by_author.png"
98 if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename))
99 image_tag("graphs/#{filename}")
100 end
128101 end
129102end
toggle raw diff

app/models/repository.rb

 
206206 data << others_v.last
207207 end
208208
209 [labels, data]
209 #[labels, data]
210 labels.inject({}) do |hash, label|
211 hash[label] = data[labels.index(label)]
212 hash
213 end
210214 end
211215
212216 protected
toggle raw diff

app/views/logs/show.html.erb

 
1414
1515<% if @commits.current_page == 1 -%>
1616 <div class="commits_by_author_graph">
17 <%= commit_graph_by_author_tag(@repository) %>
17 <%= commit_graph_by_author_tag(@repository, params[:id]) %>
1818 </div>
1919<% end -%>
2020<h2>Commits in "<%=h params[:id] -%>"</h2>
toggle raw diff

lib/gitorious/graphs/builder.rb

 
1require "gruff"
2
3Gruff::Base::TITLE_MARGIN = 2.0
4
5module Gitorious
6 module Graphs
7 class Builder
8 def self.generate_all_for(repository)
9 CommitsBuilder.generate_for(repository)
10 CommitsByAuthorBuilder.generate_for(repository)
11 end
12
13 def self.graph_dir
14 File.join(RAILS_ROOT, "public/images/graphs/")
15 end
16
17 def self.default_theme
18 {
19 :colors => [
20 '#acd64f',
21 '#bcde71',
22 '#cce692',
23 '#dceeb4',
24 '#ecf6d6',
25 ],
26 :marker_color => '#aea9a9', # Grey
27 :font_color => 'black',
28 :background_colors => 'white'
29 }
30 end
31
32 def write
33 dest = File.join(self.class.graph_dir, construct_filename)
34 @graph.write(dest)
35 end
36 end
37 end
38end
toggle raw diff

lib/gitorious/graphs/commits_builder.rb

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

lib/gitorious/graphs/commits_by_author_builder.rb

 
1module Gitorious
2 module Graphs
3
4 class CommitsByAuthorBuilder < Gitorious::Graphs::Builder
5 def self.generate_for(repository)
6 if repository.has_commits?
7 repository.git.heads.each do |head|
8 builder = new(repository, head.name)
9 builder.build
10 builder.write
11 end
12 end
13 end
14
15 def initialize(repository, branch)
16 @repository = repository
17 @branch = branch
18 @graph = Gruff::Mini::Pie.new(250)
19 @graph.theme_pastel
20 @graph.marker_font_size = 32
21 @graph.legend_font_size = 32
22 @graph.top_margin = 1
23 @graph.bottom_margin = 1
24 end
25
26 def build
27 commits_by_author = @repository.commit_graph_data_by_author(@branch)
28
29 commits_by_author.each do |author, count|
30 @graph.data(author, count)
31 end
32 end
33
34 def construct_filename
35 "#{@repository.project.slug}_#{@repository.name}_#{@branch}_commit_count_by_author.png"
36 end
37 end
38
39 end
40end
toggle raw diff

public/stylesheets/base.css

 
438438
439439.commit_list .commit_item {
440440 clear:left;
441 margin-bottom: 10px;
441 margin-bottom: 15px;
442442}
443443
444444.commit_message, .commit_message p {
447447 font: 95%/105% "Bitstream Vera Sans Mono", Monaco, "Courier New", Courier, monospace;
448448}
449449
450.commit_list .commit_item .commit_message {
451 margin-left: 40px;
452}
453
450454small.commit_message {
451455 margin: 0;
452456 font: 85%/95% "Bitstream Vera Sans Mono", Monaco, "Courier New", Courier, monospace;
474474 margin-right: 5px;
475475}
476476
477.commit_list .commit_item .gravatar {
478 margin-top: 5px;
479}
480
477481ul.project_list li {
478482 padding-bottom: 1em;
479483 margin-bottom: 1em;
toggle raw diff

script/graph_generator

 
1#!/usr/bin/env ruby
2
3ENV["RAILS_ENV"] ||= "production"
4require File.dirname(__FILE__) + "/../config/environment"
5
6log = Logger.new(File.join(RAILS_ROOT, "log", "graph_generator.log"))
7log.formatter = Logger::Formatter.new
8log.level = Logger::INFO
9log.formatter.datetime_format = "%Y-%m-%d %H:%M:%S"
10
11Repository.find(:all).each_with_index do |repository, index|
12 begin
13 Gitorious::Graphs::Builder.generate_all_for(repository)
14 if index % 5 == 0
15 # GC every five cycles
16 GC.start
17 end
18 sleep(0.1)
19 rescue => e
20 log.fatal "Error generating graphs for repo##{repository.id}"
21 exception_backtrace_string = "#{e.class.name} #{e.message}\n#{e.backtrace.join("\n ")}"
22 log.fatal exception_backtrace_string
23 $stderr.puts exception_backtrace_string
24# exit(1)
25 end
26end
toggle raw diff

spec/helpers/application_helper_spec.rb

 
4444 end
4545
4646
47 it "should generate a commit graph url" do
48 repos = repositories(:johans)
49 repos.should_receive(:commit_graph_data).and_return([[1,2,3], [4,5,6]])
50
51 url = commit_graph_tag(repos)
52 url.should match(/\<img/)
53 url.include?("google.com").should == true
47 it "should generate a blank commit graph url if the graph isn't there" do
48 File.should_receive(:exist?).and_return(false)
49 url = commit_graph_tag(repositories(:johans))
50 url.should == nil
5451 end
5552
56 it "should generate a url for commit graph by author" do
57 repos = repositories(:johans)
58 repos.should_receive(:commit_graph_data_by_author).and_return([[1,2,3], [4,5,6]])
53 it "should generate a blank url for commit graph by author if the graph isn't there" do
54 File.should_receive(:exist?).and_return(false)
5955
60 url = commit_graph_by_author_tag(repos)
61 url.should match(/\<img/)
62 url.include?("google.com").should == true
56 url = commit_graph_by_author_tag(repositories(:johans))
57 url.should == nil
6358 end
6459end
toggle raw diff

vendor/plugins/gruff/History.txt

 
1== 0.3.2
2
3* Include init.rb for use as a Rails plugin.
4
5
6== 0.3.1
7
8* Fixed missing bullet graph bug (experimental, will be in a future release).
9
10== 0.3.0
11
12* Fixed bug where pie graphs weren't drawing their label correctly.
13
14== 0.2.9
15
16* Patch to make SideBar accurate instead of stacked [Marik]
17* Will be extracting net, pie, stacked, and side-stacked to separate gem
18 in next release.
19
20== 0.2.8
21
22* New accumulator bar graph (experimental)
23* Better mini graphs
24* Bug fixes
25
26== 0.2.7
27
28* Regenerated Manifest.txt
29* Added scene sample to package
30* Added mini side_bar (EXPERIMENTAL)
31* Added @zero_degree option to Gruff::Pie so first slice can start somewhere other than 3 o'clock
32* Increased size of numbers in Gruff::Mini::Pie
33* Added legend_box_size accessor
34
35== 0.2.6
36
37* Fixed missing side_bar.rb in Manifest.txt
38
39== 0.2.5
40
41* New mini graph types (Experimental)
42* Marker lines can be different color than text labels
43* Theme definition cleanup
44
45== 0.2.4
46
47* Added option to hide line numbers
48* Fixed code that was causing warnings
49
50== 0.2.3
51
52* Cleaned up measurements so the graph expands to fill the available space
53* Added x-axis and y-axis label options
54
55== 0.1.2
56
57* minimum_value and maximum_value can be set after data() to manually scale the graph
58* Fixed infinite loop bug when values are all equal
59* Added experimental net and spider graphs
60* Added non-linear scene graph for a simple interface to complex layered graphs
61* Initial refactoring of tests
62* A host of other bug fixes
63
64== 0.0.8
65
66* NEW Sidestacked Bar Graphs. [Alun Eyre]
67* baseline_value larger than data will now show correctly. [Mike Perham]
68* hide_dots and hide_lines are now options for line graphs.
69
70== 0.0.6
71
72* Fixed hang when no data is passed.
73
74== 0.0.4
75
76* Added bar graphs
77* Added area graphs
78* Added pie graphs
79* Added render_image_background for using images as background on a theme
80* Fixed small size legend centering issue
81* Added initial line marker rounding to significant digits (Christian Winkler)
82* Line graphs line width is scaled with number of points being drawn (Christian Winkler)
83
84== 0.0.3
85
86* Added option to draw line graphs without the lines (points only), thanks to Eric Hodel
87* Removed font-minimum check so graphs look better at 300px width
88
89== 0.0.2
90
91* Fixed to_blob (thanks to Carlos Villela)
92* Added bar graphs (initial functionality...will be enhanced)
93* Removed rendered test output from gem
94
95== 0.0.1
96
97* Initial release.
98* Line graphs only. Other graph styles coming soon.
toggle raw diff

vendor/plugins/gruff/MIT-LICENSE

 
1Copyright (c) 2005 Geoffrey Grosenbach boss@topfunky.com
2
3Permission is hereby granted, free of charge, to any person obtaining
4a copy of this software and associated documentation files (the
5"Software"), to deal in the Software without restriction, including
6without limitation the rights to use, copy, modify, merge, publish,
7distribute, sublicense, and/or sell copies of the Software, and to
8permit persons to whom the Software is furnished to do so, subject to
9the following conditions:
10
11The above copyright notice and this permission notice shall be
12included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
toggle raw diff

vendor/plugins/gruff/Manifest.txt

 
1History.txt
2MIT-LICENSE
3Manifest.txt
4README.txt
5Rakefile
6assets/bubble.png
7assets/city_scene/background/0000.png
8assets/city_scene/background/0600.png
9assets/city_scene/background/2000.png
10assets/city_scene/clouds/cloudy.png
11assets/city_scene/clouds/partly_cloudy.png
12assets/city_scene/clouds/stormy.png
13assets/city_scene/grass/default.png
14assets/city_scene/haze/true.png
15assets/city_scene/number_sample/1.png
16assets/city_scene/number_sample/2.png
17assets/city_scene/number_sample/default.png
18assets/city_scene/sky/0000.png
19assets/city_scene/sky/0200.png
20assets/city_scene/sky/0400.png
21assets/city_scene/sky/0600.png
22assets/city_scene/sky/0800.png
23assets/city_scene/sky/1000.png
24assets/city_scene/sky/1200.png
25assets/city_scene/sky/1400.png
26assets/city_scene/sky/1500.png
27assets/city_scene/sky/1700.png
28assets/city_scene/sky/2000.png
29assets/pc306715.jpg
30assets/plastik/blue.png
31assets/plastik/green.png
32assets/plastik/red.png
33init.rb
34lib/gruff.rb
35lib/gruff/accumulator_bar.rb
36lib/gruff/area.rb
37lib/gruff/bar.rb
38lib/gruff/bar_conversion.rb
39lib/gruff/base.rb
40lib/gruff/deprecated.rb
41lib/gruff/line.rb
42lib/gruff/mini/bar.rb
43lib/gruff/mini/legend.rb
44lib/gruff/mini/pie.rb
45lib/gruff/mini/side_bar.rb
46lib/gruff/net.rb
47lib/gruff/photo_bar.rb
48lib/gruff/pie.rb
49lib/gruff/scene.rb
50lib/gruff/side_bar.rb
51lib/gruff/side_stacked_bar.rb
52lib/gruff/spider.rb
53lib/gruff/stacked_area.rb
54lib/gruff/stacked_bar.rb
55lib/gruff/stacked_mixin.rb
56rails_generators/gruff/gruff_generator.rb
57rails_generators/gruff/templates/controller.rb
58rails_generators/gruff/templates/functional_test.rb
59test/gruff_test_case.rb
60test/test_accumulator_bar.rb
61test/test_area.rb
62test/test_bar.rb
63test/test_base.rb
64test/test_legend.rb
65test/test_line.rb
66test/test_mini_bar.rb
67test/test_mini_pie.rb
68test/test_mini_side_bar.rb
69test/test_net.rb
70test/test_photo.rb
71test/test_pie.rb
72test/test_scene.rb
73test/test_side_bar.rb
74test/test_sidestacked_bar.rb
75test/test_spider.rb
76test/test_stacked_bar.rb
toggle raw diff

vendor/plugins/gruff/README.txt

 
1== Gruff Graphs
2
3A library for making beautiful graphs.
4
5== Samples
6
7http://nubyonrails.com/pages/gruff
8
9== Documentation
10
11http://gruff.rubyforge.org
12
13See the test suite in test/line_test.rb for examples.
14
15== Rails Plugin
16
17Gruff is easy to use with Rails.
18
19 gem install gruff
20 cd vendor/plugins && gem unpack gruff
21
22== WARNING
23
24This is beta-quality software. It works well according to my tests, but the API may change and other features will be added.
25
26== Source
27
28The source for this project is now kept at GitHub:
29
30http://github.com/topfunky/gruff/tree/master
31
32== CONTRIBUTE
33
34Patches appreciated, especially if they are in Git format (with metadata so your name shows up in the commit logs).