Commit 1f6b6b6c629592e3ecc08e9dac6514a4b1a831a0
1 parent
175e09f1
Exists in
master
and in
4 other branches
Rotating graph orientation.
Showing
2 changed files
with
82 additions
and
70 deletions
Show diff stats
app/assets/javascripts/branch-graph.js.coffee
... | ... | @@ -20,8 +20,6 @@ class BranchGraph |
20 | 20 | |
21 | 21 | prepareData: (@days, @commits) -> |
22 | 22 | @collectParents() |
23 | - @mtime += 4 | |
24 | - @mspace += 10 | |
25 | 23 | |
26 | 24 | for c in @commits |
27 | 25 | c.isParent = true if c.id of @parents |
... | ... | @@ -35,6 +33,7 @@ class BranchGraph |
35 | 33 | @mspace = Math.max(@mspace, c.space) |
36 | 34 | for p in c.parents |
37 | 35 | @parents[p[0]] = true |
36 | + @mspace = Math.max(@mspace, p[1]) | |
38 | 37 | |
39 | 38 | collectColors: -> |
40 | 39 | k = 0 |
... | ... | @@ -46,25 +45,26 @@ class BranchGraph |
46 | 45 | k++ |
47 | 46 | |
48 | 47 | buildGraph: -> |
48 | + graphHeight = $(@element).height() | |
49 | 49 | graphWidth = $(@element).width() |
50 | - ch = @mspace * 10 + 100 | |
51 | - cw = Math.max(graphWidth, @mtime * 20 + 260) | |
50 | + ch = Math.max(graphHeight, @mtime * 20 + 100) | |
51 | + cw = Math.max(graphWidth, @mspace * 10 + 260) | |
52 | 52 | r = Raphael(@element.get(0), cw, ch) |
53 | 53 | top = r.set() |
54 | 54 | cuday = 0 |
55 | 55 | cumonth = "" |
56 | - @offsetX = 20 | |
57 | - @offsetY = 50 | |
58 | - barWidth = Math.max(graphWidth, @days.length * 20 + 320) | |
56 | + @offsetX = 120 | |
57 | + @offsetY = 20 | |
58 | + barHeight = Math.max(graphHeight, @days.length * 20 + 320) | |
59 | 59 | @scrollLeft = cw |
60 | 60 | @raphael = r |
61 | - r.rect(0, 0, barWidth, 20).attr fill: "#222" | |
62 | - r.rect(0, 20, barWidth, 20).attr fill: "#444" | |
61 | + r.rect(0, 0, 20, barHeight).attr fill: "#222" | |
62 | + r.rect(20, 0, 20, barHeight).attr fill: "#444" | |
63 | 63 | |
64 | 64 | for day, mm in @days |
65 | 65 | if cuday isnt day[0] |
66 | 66 | # Dates |
67 | - r.text(@offsetX + mm * 20, 30, day[0]) | |
67 | + r.text(30, @offsetY + mm * 20, day[0]) | |
68 | 68 | .attr( |
69 | 69 | font: "12px Monaco, monospace" |
70 | 70 | fill: "#DDD" |
... | ... | @@ -73,7 +73,7 @@ class BranchGraph |
73 | 73 | |
74 | 74 | if cumonth isnt day[1] |
75 | 75 | # Months |
76 | - r.text(@offsetX + mm * 20, 10, day[1]) | |
76 | + r.text(10, @offsetY + mm * 20, day[1]) | |
77 | 77 | .attr( |
78 | 78 | font: "12px Monaco, monospace" |
79 | 79 | fill: "#EEE" |
... | ... | @@ -81,8 +81,8 @@ class BranchGraph |
81 | 81 | cumonth = day[1] |
82 | 82 | |
83 | 83 | for commit in @commits |
84 | - x = @offsetX + 20 * commit.time | |
85 | - y = @offsetY + 10 * commit.space | |
84 | + x = @offsetX + 10 * (@mspace - commit.space) | |
85 | + y = @offsetY + 20 * commit.time | |
86 | 86 | |
87 | 87 | @drawDot(x, y, commit) |
88 | 88 | |
... | ... | @@ -92,10 +92,9 @@ class BranchGraph |
92 | 92 | |
93 | 93 | @appendAnchor(top, commit, x, y) |
94 | 94 | |
95 | - @markCommit(x, y, commit, graphWidth) | |
95 | + @markCommit(x, y, commit, graphHeight) | |
96 | 96 | |
97 | 97 | top.toFront() |
98 | - @element.scrollLeft @scrollLeft | |
99 | 98 | @bindEvents() |
100 | 99 | |
101 | 100 | bindEvents: -> |
... | ... | @@ -131,26 +130,28 @@ class BranchGraph |
131 | 130 | shortrefs = refs |
132 | 131 | # Truncate if longer than 15 chars |
133 | 132 | shortrefs = shortrefs.substr(0, 15) + "…" if shortrefs.length > 17 |
134 | - text = r.text(x + 5, y + 8 + 10, shortrefs).attr( | |
133 | + text = r.text(x + 8, y, shortrefs).attr( | |
134 | + "text-anchor": "start" | |
135 | 135 | font: "10px Monaco, monospace" |
136 | 136 | fill: "#FFF" |
137 | 137 | title: refs |
138 | 138 | ) |
139 | 139 | textbox = text.getBBox() |
140 | - text.transform ["t", textbox.height / -4, textbox.width / 2 + 5, "r90"] | |
141 | 140 | # Create rectangle based on the size of the textbox |
142 | - rect = r.rect(x, y, textbox.width + 15, textbox.height + 5, 4).attr( | |
141 | + rect = r.rect(x, y - 7, textbox.width + 15, textbox.height + 5, 4).attr( | |
143 | 142 | fill: "#000" |
144 | - "fill-opacity": .7 | |
143 | + "fill-opacity": .5 | |
145 | 144 | stroke: "none" |
146 | 145 | ) |
147 | - triangle = r.path(["M", x, y + 5, "L", x + 4, y + 15, "L", x - 4, y + 15, "Z"]).attr( | |
146 | + triangle = r.path(["M", x - 5, y, "L", x - 15, y - 4, "L", x - 15, y + 4, "Z"]).attr( | |
148 | 147 | fill: "#000" |
149 | - "fill-opacity": .7 | |
148 | + "fill-opacity": .5 | |
150 | 149 | stroke: "none" |
151 | 150 | ) |
152 | - # Rotate and reposition rectangle over text | |
153 | - rect.transform ["r", 90, x, y, "t", 15, -9] | |
151 | + | |
152 | + label = r.set(rect, text) | |
153 | + label.transform(["t", -rect.getBBox().width - 15, 0]) | |
154 | + | |
154 | 155 | # Set text to front |
155 | 156 | text.toFront() |
156 | 157 | |
... | ... | @@ -164,7 +165,7 @@ class BranchGraph |
164 | 165 | ).click(-> |
165 | 166 | window.open options.commit_url.replace("%s", commit.id), "_blank" |
166 | 167 | ).hover(-> |
167 | - @tooltip = r.commitTooltip(x, y + 5, commit) | |
168 | + @tooltip = r.commitTooltip(x + 5, y, commit) | |
168 | 169 | top.push @tooltip.insertBefore(this) |
169 | 170 | , -> |
170 | 171 | @tooltip and @tooltip.remove() and delete @tooltip |
... | ... | @@ -182,44 +183,66 @@ class BranchGraph |
182 | 183 | r = @raphael |
183 | 184 | for parent in commit.parents |
184 | 185 | parentCommit = @preparedCommits[parent[0]] |
185 | - parentX = @offsetX + 20 * parentCommit.time | |
186 | - parentY1 = @offsetY + 10 * parentCommit.space | |
187 | - parentY2 = @offsetY + 10 * parent[1] | |
186 | + parentY = @offsetY + 20 * parentCommit.time | |
187 | + parentX1 = @offsetX + 10 * (@mspace - parentCommit.space) | |
188 | + parentX2 = @offsetX + 10 * (@mspace - parent[1]) | |
189 | + | |
188 | 190 | if parentCommit.space is commit.space and parentCommit.space is parent[1] |
189 | - r.path(["M", x, y, "L", parentX, parentY1]).attr( | |
191 | + r.path(["M", x, y, "L", parentX1, parentY]).attr( | |
190 | 192 | stroke: @colors[parentCommit.space] |
191 | 193 | "stroke-width": 2 |
192 | 194 | ) |
193 | 195 | |
194 | 196 | else if parentCommit.space < commit.space |
195 | - if y is parentY2 | |
196 | - r.path(["M", x - 5, y, "l-5,-2,0,4,5,-2", "L", x - 10, y, "L", x - 15, parentY2, "L", parentX + 5, parentY2, "L", parentX, parentY1]).attr( | |
197 | - stroke: @colors[commit.space] | |
198 | - "stroke-width": 2 | |
199 | - ) | |
197 | + if x is parentX2 | |
198 | + r | |
199 | + .path([ | |
200 | + "M", x, y + 5, | |
201 | + "l-2,5,4,0,-2,-5", | |
202 | + "L", x, y + 10, | |
203 | + "L", parentX2, y + 10, | |
204 | + "L", parentX2, parentY - 5, | |
205 | + "L", parentX1, parentY]) | |
206 | + .attr( | |
207 | + stroke: @colors[commit.space] | |
208 | + "stroke-width": 2) | |
200 | 209 | |
201 | 210 | else |
202 | - r.path(["M", x - 3, y - 6, "l-4,-3,4,-2,0,5", "L", x - 5, y - 10, "L", x - 10, parentY2, "L", parentX + 5, parentY2, "L", parentX, parentY1]).attr( | |
203 | - stroke: @colors[commit.space] | |
204 | - "stroke-width": 2 | |
205 | - ) | |
211 | + r | |
212 | + .path([ | |
213 | + "M", x + 3, y + 3, | |
214 | + "l5,0,-2,4,-3,-4", | |
215 | + "L", x + 7, y + 5, | |
216 | + "L", parentX2, y + 10, | |
217 | + "L", parentX2, parentY - 5, | |
218 | + "L", parentX1, parentY]) | |
219 | + .attr( | |
220 | + stroke: @colors[commit.space] | |
221 | + "stroke-width": 2) | |
206 | 222 | |
207 | 223 | else |
208 | - r.path(["M", x - 3, y + 6, "l-4,3,4,2,0,-5", "L", x - 5, y + 10, "L", x - 10, parentY2, "L", parentX + 5, parentY2, "L", parentX, parentY1]).attr( | |
209 | - stroke: @colors[parentCommit.space] | |
210 | - "stroke-width": 2 | |
211 | - ) | |
224 | + r | |
225 | + .path([ | |
226 | + "M", x - 3, y + 3, | |
227 | + "l-5,0,2,4,3,-4", | |
228 | + "L", x - 7, y + 5, | |
229 | + "L", parentX2, y + 10, | |
230 | + "L", parentX2, parentY - 5, | |
231 | + "L", parentX1, parentY]) | |
232 | + .attr( | |
233 | + stroke: @colors[parentCommit.space] | |
234 | + "stroke-width": 2) | |
212 | 235 | |
213 | - markCommit: (x, y, commit, graphWidth) -> | |
236 | + markCommit: (x, y, commit, graphHeight) -> | |
214 | 237 | if commit.id is @options.commit_id |
215 | 238 | r = @raphael |
216 | - r.path(["M", x, y - 5, "L", x + 4, y - 15, "L", x - 4, y - 15, "Z"]).attr( | |
239 | + r.path(["M", x + 5, y, "L", x + 15, y + 4, "L", x + 15, y - 4, "Z"]).attr( | |
217 | 240 | fill: "#000" |
218 | - "fill-opacity": .7 | |
241 | + "fill-opacity": .5 | |
219 | 242 | stroke: "none" |
220 | 243 | ) |
221 | 244 | # Displayed in the center |
222 | - @scrollLeft = x - graphWidth / 2 | |
245 | + @element.scrollTop(y - graphHeight / 2) | |
223 | 246 | |
224 | 247 | Raphael::commitTooltip = (x, y, commit) -> |
225 | 248 | boxWidth = 300 | ... | ... |
app/models/network/graph.rb
... | ... | @@ -40,15 +40,12 @@ module Network |
40 | 40 | def index_commits |
41 | 41 | days = [] |
42 | 42 | @map = {} |
43 | + @reserved = {} | |
43 | 44 | |
44 | - @commits.reverse.each_with_index do |c,i| | |
45 | + @commits.each_with_index do |c,i| | |
45 | 46 | c.time = i |
46 | 47 | days[i] = c.committed_date |
47 | 48 | @map[c.id] = c |
48 | - end | |
49 | - | |
50 | - @reserved = {} | |
51 | - days.each_index do |i| | |
52 | 49 | @reserved[i] = [] |
53 | 50 | end |
54 | 51 | |
... | ... | @@ -135,11 +132,7 @@ module Network |
135 | 132 | spaces = [] |
136 | 133 | |
137 | 134 | commit.parents(@map).each do |parent| |
138 | - range = if commit.time < parent.time then | |
139 | - commit.time..parent.time | |
140 | - else | |
141 | - parent.time..commit.time | |
142 | - end | |
135 | + range = commit.time..parent.time | |
143 | 136 | |
144 | 137 | space = if commit.space >= parent.space then |
145 | 138 | find_free_parent_space(range, parent.space, -1, commit.space) |
... | ... | @@ -166,7 +159,7 @@ module Network |
166 | 159 | range.each do |i| |
167 | 160 | if i != range.first && |
168 | 161 | i != range.last && |
169 | - @commits[reversed_index(i)].spaces.include?(overlap_space) then | |
162 | + @commits[i].spaces.include?(overlap_space) then | |
170 | 163 | |
171 | 164 | return true; |
172 | 165 | end |
... | ... | @@ -184,7 +177,7 @@ module Network |
184 | 177 | return |
185 | 178 | end |
186 | 179 | |
187 | - time_range = leaves.last.time..leaves.first.time | |
180 | + time_range = leaves.first.time..leaves.last.time | |
188 | 181 | space_base = get_space_base(leaves) |
189 | 182 | space = find_free_space(time_range, 2, space_base) |
190 | 183 | leaves.each do |l| |
... | ... | @@ -198,17 +191,17 @@ module Network |
198 | 191 | end |
199 | 192 | |
200 | 193 | # and mark it as reserved |
201 | - min_time = leaves.last.time | |
202 | - leaves.last.parents(@map).each do |parent| | |
203 | - if parent.time < min_time | |
204 | - min_time = parent.time | |
205 | - end | |
206 | - end | |
207 | - | |
208 | 194 | if parent_time.nil? |
209 | - max_time = leaves.first.time | |
195 | + min_time = leaves.first.time | |
210 | 196 | else |
211 | - max_time = parent_time - 1 | |
197 | + min_time = parent_time + 1 | |
198 | + end | |
199 | + | |
200 | + max_time = leaves.last.time | |
201 | + leaves.last.parents(@map).each do |parent| | |
202 | + if max_time < parent.time | |
203 | + max_time = parent.time | |
204 | + end | |
212 | 205 | end |
213 | 206 | mark_reserved(min_time..max_time, space) |
214 | 207 | |
... | ... | @@ -289,9 +282,5 @@ module Network |
289 | 282 | end |
290 | 283 | refs_cache |
291 | 284 | end |
292 | - | |
293 | - def reversed_index(index) | |
294 | - -index - 1 | |
295 | - end | |
296 | 285 | end |
297 | 286 | end | ... | ... |