GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

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
Prettified graphs and graphing code

- moved model related things into the model
- display full week range for repos commits-per-week
- Don't show the mainline repos commit graph everywhere
js (author)
Sat Mar 29 17:13:38 -0700 2008
commit  4adcf87e54718d78781524b1f8c97790b939491d
tree    beef285a198257bb0ee663b98ca0cea949a111dd
parent  906f7d557733ea8fa8e01366f7aafd8d8ca40523
...
1
2
 
3
4
5
...
1
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 (in no particular order)
0
 
0
+* Get rid of the non-libre google graphs in favor of locally-generated ones (though NOT by the rails app)
0
 * Make the fact that you _can_ clone/fork any repo more visible, maybe reword it since people confuse it with local cloning
0
 * Update the HACKING with some basic coding guidelines
0
 * Show the most recent mergerequests on users dashboard so they can track them
...
57
58
59
60
 
61
62
63
...
79
80
81
82
83
84
85
 
 
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
 
 
 
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
 
 
 
 
 
 
 
 
 
 
 
 
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
 
169
170
 
 
 
 
 
 
 
 
 
171
172
...
57
58
59
 
60
61
62
63
...
79
80
81
 
 
 
 
82
83
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
108
109
 
110
111
112
113
114
115
116
117
118
119
120
0
@@ -57,7 +57,7 @@ module ApplicationHelper
0
   end
0
   
0
   def gravatar_url_for(email, options = {})
0
- "http://www.gravatar.com/avatar.php?default=/images/default_face.png&amp;gravatar_id=" <<
0
+ "http://www.gravatar.com/avatar.php?gravatar_id=" <<
0
     Digest::MD5.hexdigest(email) <<
0
     options.map { |k,v| "&amp;#{k}=#{v}" }.join
0
   end
0
@@ -79,94 +79,42 @@ module ApplicationHelper
0
     flash.map { |type, content| content_tag(:div, content_tag(:p, content), :class => "flash_message #{type}")}
0
   end
0
   
0
- def commit_graph_tag(project, sha = "master", width = 250, height = 150)
0
- repo = project.repositories.first
0
- git_repo = repo.git
0
- git = git_repo.git
0
+ def commit_graph_tag(repository, sha = "master", width = 650, height = 110)
0
+ labels, commits = repository.commit_graph_data(sha)
0
+ return if commits.blank?
0
+ # "<pre>#{labels.inspect}\n#{commits.inspect}</pre>" +
0
     
0
- h = Hash.new
0
- dategroup = Date.new
0
-
0
- data = git.rev_list({:pretty => "format:%at", :since => "24 weeks ago"}, sha)
0
- rx = /^\d/.freeze
0
- data.each_line { |line|
0
- if line =~ rx then
0
- date = Time.at(line.to_i)
0
-
0
- dategroup = Date.new(date.year, date.month, 1)
0
- if h[dategroup]
0
- h[dategroup] += 1
0
- else
0
- h[dategroup] = 1
0
- end
0
+ label_names = []
0
+ labels.each_with_index do |week, index|
0
+ if (index % 5) == 0
0
+ label_names << "Week #{week}"
0
       end
0
- }
0
-
0
- commits = []
0
- labels = []
0
-
0
- h.sort.each { |entry|
0
- date = entry.first
0
- value = entry.last
0
-
0
- labels << date.strftime("%b") # + "[#{value}]"
0
- commits << value
0
- }
0
-
0
- Gchart.bar(:data => commits, :labels => labels, :width => width, :height => height, :bg => "efefef", :format => "img_tag", :axis_with_labels => ['x'], :axis_labels => [commits], :bar_colors => 'FFDBA3')
0
+ end
0
+ Gchart.line({
0
+ :title => "Commits by week (24 week period)",
0
+ :data => [0] + commits,
0
+ :width => width,
0
+ :height => height,
0
+ :format => "img_tag",
0
+ :axis_with_labels => ["y", "x"],
0
+ :axis_labels => ["0|#{commits.max}", label_names.join("|")],
0
+ :bar_colors => "9cce2e",
0
+ :custom => "chm=B,E4E9D4,0,0,0",
0
+ :max_value => "auto"
0
+ })
0
   end
0
   
0
- def commit_graph_by_author_tag(project, sha = "master", width = 400, height = 200)
0
- repo = project.repositories.first
0
- git_repo = repo.git
0
- git = git_repo.git
0
-
0
- h = Hash.new
0
-
0
- data = git.rev_list({:pretty => "format:name:%cn", :since => "1 years ago" }, sha)
0
- data.each_line { |line|
0
- if line =~ /^name:(.*)$/ then
0
- author = $1
0
-
0
- if h[author]
0
- h[author] += 1
0
- else
0
- h[author] = 1
0
- end
0
- end
0
- }
0
-
0
- sorted = h.sort_by { |author, commits|
0
- commits
0
- }
0
-
0
- labels = []
0
- data = []
0
-
0
- max = 5
0
- others = []
0
- top = sorted
0
-
0
-
0
- if sorted.size > max
0
- top = sorted[sorted.size-max, sorted.size]
0
- others = sorted[0, sorted.size-max]
0
- end
0
-
0
- top.each { |entry|
0
- author = entry.first
0
- v = entry.last
0
-
0
- data << v
0
- labels << author
0
- }
0
-
0
- unless others.empty?
0
- others_v = others.inject { |v, acum| [v.last + acum.last] }
0
- labels << "others"
0
- data << others_v.last
0
- end
0
+ def commit_graph_by_author_tag(repos, sha = "master", width = 350, height = 150)
0
+ labels, data = repos.commit_graph_data_by_author
0
     
0
- Gchart.pie(:data => data, :labels => labels, :width => width, :height => height, :bg => "efefef", :format => "img_tag" )
0
+ Gchart.pie({
0
+ :title => "Commits by author",
0
+ :data => data,
0
+ :labels => labels,
0
+ :width => width,
0
+ :height => height,
0
+ :bar_colors => "9cce2e",
0
+ :format => "img_tag"
0
+ })
0
   end
0
 end
...
136
137
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
140
141
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
0
@@ -136,6 +136,78 @@ class Repository < ActiveRecord::Base
0
     end
0
     commits_by_email.size
0
   end
0
+
0
+ # TODO: cache
0
+ def commit_graph_data(head = "master")
0
+ commits = git.commits_since(head, "24 weeks ago")
0
+ commits_by_week = commits.group_by{|c| c.committed_date.strftime("%W") }
0
+
0
+ # build an initial empty set of 24 week commit data
0
+ weeks = [1.day.from_now-1.week]
0
+ 23.times{|w| weeks << weeks.last-1.week }
0
+ week_numbers = weeks.map{|d| d.strftime("%W") }
0
+ commits = (0..24).to_a.map{|i| 0 }
0
+
0
+ commits_by_week.each do |week, commits_in_week|
0
+ if week_pos = week_numbers.index(week)
0
+ commits[week_pos+1] = commits_in_week.size
0
+ end
0
+ end
0
+ commits = [] if commits.max == 0
0
+ [week_numbers.reverse, commits.reverse]
0
+ end
0
+
0
+ # TODO: refactor into simpler approach
0
+ # TODO: caching
0
+ def commit_graph_data_by_author(head = "master")
0
+ h = Hash.new
0
+
0
+ data = self.git.git.rev_list({:pretty => "format:name:%cn", :since => "1 years ago" }, head)
0
+ data.each_line do |line|
0
+ if line =~ /^name:(.*)$/ then
0
+ author = $1
0
+
0
+ if h[author]
0
+ h[author] += 1
0
+ else
0
+ h[author] = 1
0
+ end
0
+ end
0
+ end
0
+
0
+ sorted = h.sort_by do |author, commits|
0
+ commits
0
+ end
0
+
0
+ labels = []
0
+ data = []
0
+
0
+ max = 5
0
+ others = []
0
+ top = sorted
0
+
0
+
0
+ if sorted.size > max
0
+ top = sorted[sorted.size-max, sorted.size]
0
+ others = sorted[0, sorted.size-max]
0
+ end
0
+
0
+ top.each do |entry|
0
+ author = entry.first
0
+ v = entry.last
0
+
0
+ data << v
0
+ labels << author
0
+ end
0
+
0
+ unless others.empty?
0
+ others_v = others.inject { |v, acum| [v.last + acum.last] }
0
+ labels << "others"
0
+ data << others_v.last
0
+ end
0
+
0
+ [labels, data]
0
+ end
0
     
0
   protected
0
     def set_as_mainline_if_first
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@
0
   </div>
0
   <%= gravatar_frame(commit.committer.email, :size => 32) %>
0
   <div class="commit_message"> <%= simple_format(h(commit.message)) -%></div>
0
- <div class="clear">
0
+ <div class="clear_left"></div>
0
 </li>
0
 <% end -%>
0
 </ul>
...
9
10
11
12
13
14
15
 
 
 
16
17
18
...
9
10
11
 
12
13
14
15
16
17
18
19
20
0
@@ -9,10 +9,12 @@
0
   <% unless @commits.blank? -%>
0
   <li><strong>HEAD tree:</strong> <%= link_to h(@commits.first.tree.id),
0
     tree_path(@commits.first.id) -%></li>
0
- <li><%= commit_graph_by_author_tag(@project) %></li>
0
   <% end -%>
0
 </ul>
0
 
0
+<div class="commits_by_author_graph">
0
+ <%= commit_graph_by_author_tag(@repository) %>
0
+</div>
0
 <h2>Commits in "<%=h params[:id] -%>"</h2>
0
 <%= render :partial => "log" -%>
0
 <%= will_paginate @commits %>
...
1
2
3
4
5
6
7
8
...
1
2
 
 
 
3
4
5
0
@@ -1,8 +1,5 @@
0
 <h3><%= link_to h(project.title), project_path(project) -%></h3>
0
 <p><%= truncate h(project.stripped_description), 250 -%></p>
0
-<% if project.repositories.first.has_commits? %>
0
- <div><%= commit_graph_tag(project) %></div>
0
-<% end -%>
0
 <p class="hint">
0
   <strong>Categories:</strong>
0
   <%= project.tag_list.blank? ? "none" : linked_tag_list_as_sentence(project.tags) -%>
...
20
21
22
23
24
25
26
27
28
...
20
21
22
 
 
 
23
24
25
0
@@ -20,9 +20,6 @@
0
     <li><strong>Bugtracker at </strong>
0
       <%= link_to base_url(@project.bugtracker_url), h(@project.bugtracker_url) -%></li>
0
     <% end -%>
0
- <% if @repositories.first.has_commits? %>
0
- <li><%= commit_graph_tag(@project) %></li>
0
- <% end -%>
0
   </ul>
0
 </div>
0
 
...
7
8
9
 
 
10
11
12
...
7
8
9
10
11
12
13
14
0
@@ -7,6 +7,8 @@
0
 
0
   <%= render :partial => "infobox" -%>
0
   
0
+ <%= commit_graph_tag(@repository) %>
0
+
0
   <ul class="tab_menu">
0
     <li class="selected">Recent commits</li>
0
     <li><%= link_to "comments (#{@comment_count})",
...
120
121
122
 
 
 
 
 
123
124
125
...
973
974
975
 
 
 
 
 
976
977
...
120
121
122
123
124
125
126
127
128
129
130
...
978
979
980
981
982
983
984
985
986
987
0
@@ -120,6 +120,11 @@ abbr {
0
   height: 0;
0
 }
0
 
0
+.clear_left {
0
+ clear: left;
0
+ height: 0;
0
+}
0
+
0
 #container {
0
   width: 90%;
0
   margin-top: 20px;
0
@@ -973,4 +978,9 @@ ul.diff_stats small.deletions { color: #DC0000; }
0
 
0
 #users .infobox {
0
   margin-bottom: 20px;
0
+}
0
+
0
+.commits_by_author_graph img {
0
+ float: right;
0
+ margin: 0 0 10px 10px;
0
 }
0
\ No newline at end of file
...
45
46
47
48
49
50
51
 
 
52
53
 
 
54
55
56
57
58
59
60
61
62
 
 
63
64
65
 
 
66
67
68
69
70
71
...
45
46
47
 
 
 
 
48
49
50
 
51
52
53
 
 
 
54
55
56
 
 
57
58
59
 
 
60
61
62
 
 
 
63
64
0
@@ -45,27 +45,20 @@ describe ApplicationHelper do
0
   
0
     
0
   it "should generate a commit graph url" do
0
- project = projects(:johans)
0
- FileUtils.mkpath(project.mainline_repository.full_repository_path)
0
-
0
- url = commit_graph_tag(project)
0
+ repos = repositories(:johans)
0
+ repos.should_receive(:commit_graph_data).and_return([[1,2,3], [4,5,6]])
0
     
0
- (url =~ /\<img/).should == 0
0
+ url = commit_graph_tag(repos)
0
+ url.should match(/\<img/)
0
     url.include?("google.com").should == true
0
-
0
- Gchart.should_receive(:bar)
0
- commit_graph_tag(project)
0
   end
0
   
0
   it "should generate a url for commit graph by author" do
0
- project = projects(:johans)
0
- FileUtils.mkpath(project.mainline_repository.full_repository_path)
0
+ repos = repositories(:johans)
0
+ repos.should_receive(:commit_graph_data_by_author).and_return([[1,2,3], [4,5,6]])
0
     
0
- url = commit_graph_by_author_tag(project)
0
- (url =~ /\<img/).should == 0
0
+ url = commit_graph_by_author_tag(repos)
0
+ url.should match(/\<img/)
0
     url.include?("google.com").should == true
0
-
0
- Gchart.should_receive(:pie)
0
- commit_graph_by_author_tag(project)
0
   end
0
 end

Comments

    No one has commented yet.