Commit 235605fc6d88f0a47f4c5b7e9abc6a99e9286495
Exists in
master
and in
4 other branches
Merge pull request #3288 from hiroponz/fix-style-network-graph
Fix style of network graph.
Showing
1 changed file
with
50 additions
and
49 deletions
Show diff stats
app/assets/javascripts/branch-graph.js.coffee
@@ -51,21 +51,21 @@ class BranchGraph | @@ -51,21 +51,21 @@ class BranchGraph | ||
51 | buildGraph: -> | 51 | buildGraph: -> |
52 | graphHeight = $(@element).height() | 52 | graphHeight = $(@element).height() |
53 | graphWidth = $(@element).width() | 53 | graphWidth = $(@element).width() |
54 | - ch = Math.max(graphHeight, @unitTime * @mtime + 100) | ||
55 | - cw = Math.max(graphWidth, @unitSpace * @mspace + 260) | 54 | + ch = Math.max(graphHeight, @offsetY + @unitTime * @mtime + 150) |
55 | + cw = Math.max(graphWidth, @offsetX + @unitSpace * @mspace + 300) | ||
56 | @r = r = Raphael(@element.get(0), cw, ch) | 56 | @r = r = Raphael(@element.get(0), cw, ch) |
57 | top = r.set() | 57 | top = r.set() |
58 | cuday = 0 | 58 | cuday = 0 |
59 | cumonth = "" | 59 | cumonth = "" |
60 | barHeight = Math.max(graphHeight, @unitTime * @days.length + 320) | 60 | barHeight = Math.max(graphHeight, @unitTime * @days.length + 320) |
61 | 61 | ||
62 | - r.rect(0, 0, 20, barHeight).attr fill: "#222" | ||
63 | - r.rect(20, 0, 20, barHeight).attr fill: "#444" | 62 | + r.rect(0, 0, 26, barHeight).attr fill: "#222" |
63 | + r.rect(26, 0, 20, barHeight).attr fill: "#444" | ||
64 | 64 | ||
65 | for day, mm in @days | 65 | for day, mm in @days |
66 | if cuday isnt day[0] | 66 | if cuday isnt day[0] |
67 | # Dates | 67 | # Dates |
68 | - r.text(30, @offsetY + @unitTime * mm, day[0]) | 68 | + r.text(36, @offsetY + @unitTime * mm, day[0]) |
69 | .attr( | 69 | .attr( |
70 | font: "12px Monaco, monospace" | 70 | font: "12px Monaco, monospace" |
71 | fill: "#DDD" | 71 | fill: "#DDD" |
@@ -74,7 +74,7 @@ class BranchGraph | @@ -74,7 +74,7 @@ class BranchGraph | ||
74 | 74 | ||
75 | if cumonth isnt day[1] | 75 | if cumonth isnt day[1] |
76 | # Months | 76 | # Months |
77 | - r.text(10, @offsetY + @unitTime * mm, day[1]) | 77 | + r.text(13, @offsetY + @unitTime * mm, day[1]) |
78 | .attr( | 78 | .attr( |
79 | font: "12px Monaco, monospace" | 79 | font: "12px Monaco, monospace" |
80 | fill: "#EEE" | 80 | fill: "#EEE" |
@@ -191,57 +191,58 @@ class BranchGraph | @@ -191,57 +191,58 @@ class BranchGraph | ||
191 | 191 | ||
192 | drawLines: (x, y, commit) -> | 192 | drawLines: (x, y, commit) -> |
193 | r = @r | 193 | r = @r |
194 | - for parent in commit.parents | 194 | + for parent, i in commit.parents |
195 | parentCommit = @preparedCommits[parent[0]] | 195 | parentCommit = @preparedCommits[parent[0]] |
196 | parentY = @offsetY + @unitTime * parentCommit.time | 196 | parentY = @offsetY + @unitTime * parentCommit.time |
197 | parentX1 = @offsetX + @unitSpace * (@mspace - parentCommit.space) | 197 | parentX1 = @offsetX + @unitSpace * (@mspace - parentCommit.space) |
198 | parentX2 = @offsetX + @unitSpace * (@mspace - parent[1]) | 198 | parentX2 = @offsetX + @unitSpace * (@mspace - parent[1]) |
199 | 199 | ||
200 | - if parentCommit.space is commit.space and parentCommit.space is parent[1] | ||
201 | - r.path(["M", x, y, "L", parentX1, parentY]).attr( | ||
202 | - stroke: @colors[parentCommit.space] | ||
203 | - "stroke-width": 2 | ||
204 | - ) | 200 | + # Set line color |
201 | + if parentCommit.space <= commit.space | ||
202 | + color = @colors[commit.space] | ||
203 | + | ||
204 | + else | ||
205 | + color = @colors[parentCommit.space] | ||
206 | + | ||
207 | + # Build line shape | ||
208 | + if parent[1] is commit.space | ||
209 | + d1 = [0, 5] | ||
210 | + d2 = [0, 10] | ||
211 | + arrow = "l-2,5,4,0,-2,-5" | ||
205 | 212 | ||
206 | - else if parentCommit.space < commit.space | ||
207 | - if x is parentX2 | ||
208 | - r | ||
209 | - .path([ | ||
210 | - "M", x, y + 5, | ||
211 | - "l-2,5,4,0,-2,-5", | ||
212 | - "L", x, y + 10, | ||
213 | - "L", parentX2, y + 10, | ||
214 | - "L", parentX2, parentY - 5, | ||
215 | - "L", parentX1, parentY]) | ||
216 | - .attr( | ||
217 | - stroke: @colors[commit.space] | ||
218 | - "stroke-width": 2) | ||
219 | - | ||
220 | - else | ||
221 | - r | ||
222 | - .path([ | ||
223 | - "M", x + 3, y + 3, | ||
224 | - "l5,0,-2,4,-3,-4", | ||
225 | - "L", x + 7, y + 5, | ||
226 | - "L", parentX2, y + 10, | ||
227 | - "L", parentX2, parentY - 5, | ||
228 | - "L", parentX1, parentY]) | ||
229 | - .attr( | ||
230 | - stroke: @colors[commit.space] | ||
231 | - "stroke-width": 2) | 213 | + else if parent[1] < commit.space |
214 | + d1 = [3, 3] | ||
215 | + d2 = [7, 5] | ||
216 | + arrow = "l5,0,-2,4,-3,-4" | ||
232 | 217 | ||
233 | else | 218 | else |
234 | - r | ||
235 | - .path([ | ||
236 | - "M", x - 3, y + 3, | ||
237 | - "l-5,0,2,4,3,-4", | ||
238 | - "L", x - 7, y + 5, | ||
239 | - "L", parentX2, y + 10, | ||
240 | - "L", parentX2, parentY - 5, | ||
241 | - "L", parentX1, parentY]) | ||
242 | - .attr( | ||
243 | - stroke: @colors[parentCommit.space] | ||
244 | - "stroke-width": 2) | 219 | + d1 = [-3, 3] |
220 | + d2 = [-7, 5] | ||
221 | + arrow = "l-5,0,2,4,3,-4" | ||
222 | + | ||
223 | + # Start point | ||
224 | + route = ["M", x + d1[0], y + d1[1]] | ||
225 | + | ||
226 | + # Add arrow if not first parent | ||
227 | + if i > 0 | ||
228 | + route.push(arrow) | ||
229 | + | ||
230 | + # Circumvent if overlap | ||
231 | + if commit.space isnt parentCommit.space or commit.space isnt parent[1] | ||
232 | + route.push( | ||
233 | + "L", x + d2[0], y + d2[1], | ||
234 | + "L", parentX2, y + 10, | ||
235 | + "L", parentX2, parentY - 5, | ||
236 | + ) | ||
237 | + | ||
238 | + # End point | ||
239 | + route.push("L", parentX1, parentY) | ||
240 | + | ||
241 | + r | ||
242 | + .path(route) | ||
243 | + .attr( | ||
244 | + stroke: color | ||
245 | + "stroke-width": 2) | ||
245 | 246 | ||
246 | markCommit: (x, y, commit, graphHeight) -> | 247 | markCommit: (x, y, commit, graphHeight) -> |
247 | if commit.id is @options.commit_id | 248 | if commit.id is @options.commit_id |