Commit d6338a8482920fc69cc016e5da796194034a1861

Authored by Dmitriy Zaporozhets
2 parents 02f70851 06c53897

Merge pull request #3258 from hiroponz/display-commit-msg

Display commit message on network graph.
app/assets/javascripts/branch-graph.js.coffee
... ... @@ -5,6 +5,10 @@ class BranchGraph
5 5 @mspace = 0
6 6 @parents = {}
7 7 @colors = ["#000"]
  8 + @offsetX = 120
  9 + @offsetY = 20
  10 + @unitTime = 30
  11 + @unitSpace = 10
8 12 @load()
9 13  
10 14 load: ->
... ... @@ -20,8 +24,6 @@ class BranchGraph
20 24  
21 25 prepareData: (@days, @commits) ->
22 26 @collectParents()
23   - @mtime += 4
24   - @mspace += 10
25 27  
26 28 for c in @commits
27 29 c.isParent = true if c.id of @parents
... ... @@ -35,6 +37,7 @@ class BranchGraph
35 37 @mspace = Math.max(@mspace, c.space)
36 38 for p in c.parents
37 39 @parents[p[0]] = true
  40 + @mspace = Math.max(@mspace, p[1])
38 41  
39 42 collectColors: ->
40 43 k = 0
... ... @@ -46,25 +49,23 @@ class BranchGraph
46 49 k++
47 50  
48 51 buildGraph: ->
  52 + graphHeight = $(@element).height()
49 53 graphWidth = $(@element).width()
50   - ch = @mspace * 20 + 100
51   - cw = Math.max(graphWidth, @mtime * 20 + 260)
52   - r = Raphael(@element.get(0), cw, ch)
  54 + ch = Math.max(graphHeight, @unitTime * @mtime + 100)
  55 + cw = Math.max(graphWidth, @unitSpace * @mspace + 260)
  56 + @r = r = Raphael(@element.get(0), cw, ch)
53 57 top = r.set()
54 58 cuday = 0
55 59 cumonth = ""
56   - offsetX = 20
57   - offsetY = 60
58   - barWidth = Math.max(graphWidth, @days.length * 20 + 320)
59   - scrollLeft = cw
60   - @raphael = r
61   - r.rect(0, 0, barWidth, 20).attr fill: "#222"
62   - r.rect(0, 20, barWidth, 20).attr fill: "#444"
  60 + barHeight = Math.max(graphHeight, @unitTime * @days.length + 320)
  61 +
  62 + r.rect(0, 0, 20, barHeight).attr fill: "#222"
  63 + r.rect(20, 0, 20, barHeight).attr fill: "#444"
63 64  
64 65 for day, mm in @days
65 66 if cuday isnt day[0]
66 67 # Dates
67   - r.text(offsetX + mm * 20, 31, day[0])
  68 + r.text(30, @offsetY + @unitTime * mm, day[0])
68 69 .attr(
69 70 font: "12px Monaco, monospace"
70 71 fill: "#DDD"
... ... @@ -73,7 +74,7 @@ class BranchGraph
73 74  
74 75 if cumonth isnt day[1]
75 76 # Months
76   - r.text(offsetX + mm * 20, 11, day[1])
  77 + r.text(10, @offsetY + @unitTime * mm, day[1])
77 78 .attr(
78 79 font: "12px Monaco, monospace"
79 80 fill: "#EEE"
... ... @@ -81,61 +82,20 @@ class BranchGraph
81 82 cumonth = day[1]
82 83  
83 84 for commit in @commits
84   - x = offsetX + 20 * commit.time
85   - y = offsetY + 10 * commit.space
86   - # Draw dot
87   - r.circle(x, y, 3).attr(
88   - fill: @colors[commit.space]
89   - stroke: "none"
90   - )
91   -
92   - # Draw lines
93   - for parent in commit.parents
94   - parentCommit = @preparedCommits[parent[0]]
95   - parentX = offsetX + 20 * parentCommit.time
96   - parentY1 = offsetY + 10 * parentCommit.space
97   - parentY2 = offsetY + 10 * parent[1]
98   - if parentCommit.space is commit.space and parentCommit.space is parent[1]
99   - r.path(["M", x, y, "L", parentX, parentY1]).attr(
100   - stroke: @colors[parentCommit.space]
101   - "stroke-width": 2
102   - )
103   -
104   - else if parentCommit.space < commit.space
105   - if y is parentY2
106   - 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(
107   - stroke: @colors[commit.space]
108   - "stroke-width": 2
109   - )
110   -
111   - else
112   - 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(
113   - stroke: @colors[commit.space]
114   - "stroke-width": 2
115   - )
  85 + x = @offsetX + @unitSpace * (@mspace - commit.space)
  86 + y = @offsetY + @unitTime * commit.time
116 87  
117   - else
118   - 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(
119   - stroke: @colors[parentCommit.space]
120   - "stroke-width": 2
121   - )
  88 + @drawDot(x, y, commit)
122 89  
123   - @appendLabel x, y, commit.refs if commit.refs
  90 + @drawLines(x, y, commit)
124 91  
125   - # Mark commit and displayed in the center
126   - if commit.id is @options.commit_id
127   - r.path(["M", x, y - 5, "L", x + 4, y - 15, "L", x - 4, y - 15, "Z"]).attr(
128   - fill: "#000"
129   - "fill-opacity": .7
130   - stroke: "none"
131   - )
  92 + @appendLabel(x, y, commit.refs) if commit.refs
132 93  
133   - scrollLeft = x - graphWidth / 2
  94 + @appendAnchor(top, commit, x, y)
134 95  
135   - @appendAnchor top, commit, x, y
  96 + @markCommit(x, y, commit, graphHeight)
136 97  
137 98 top.toFront()
138   - @element.scrollLeft scrollLeft
139 99 @bindEvents()
140 100  
141 101 bindEvents: ->
... ... @@ -167,35 +127,37 @@ class BranchGraph
167 127 element.scrollTop element.scrollTop() + 50 if event.keyCode is 40
168 128  
169 129 appendLabel: (x, y, refs) ->
170   - r = @raphael
  130 + r = @r
171 131 shortrefs = refs
172 132 # Truncate if longer than 15 chars
173 133 shortrefs = shortrefs.substr(0, 15) + "…" if shortrefs.length > 17
174   - text = r.text(x + 5, y + 8 + 10, shortrefs).attr(
  134 + text = r.text(x + 8, y, shortrefs).attr(
  135 + "text-anchor": "start"
175 136 font: "10px Monaco, monospace"
176 137 fill: "#FFF"
177 138 title: refs
178 139 )
179 140 textbox = text.getBBox()
180   - text.transform ["t", textbox.height / -4, textbox.width / 2 + 5, "r90"]
181 141 # Create rectangle based on the size of the textbox
182   - rect = r.rect(x, y, textbox.width + 15, textbox.height + 5, 4).attr(
  142 + rect = r.rect(x, y - 7, textbox.width + 15, textbox.height + 5, 4).attr(
183 143 fill: "#000"
184   - "fill-opacity": .7
  144 + "fill-opacity": .5
185 145 stroke: "none"
186 146 )
187   - triangle = r.path(["M", x, y + 5, "L", x + 4, y + 15, "L", x - 4, y + 15, "Z"]).attr(
  147 + triangle = r.path(["M", x - 5, y, "L", x - 15, y - 4, "L", x - 15, y + 4, "Z"]).attr(
188 148 fill: "#000"
189   - "fill-opacity": .7
  149 + "fill-opacity": .5
190 150 stroke: "none"
191 151 )
192   - # Rotate and reposition rectangle over text
193   - rect.transform ["r", 90, x, y, "t", 15, -9]
  152 +
  153 + label = r.set(rect, text)
  154 + label.transform(["t", -rect.getBBox().width - 15, 0])
  155 +
194 156 # Set text to front
195 157 text.toFront()
196 158  
197 159 appendAnchor: (top, commit, x, y) ->
198   - r = @raphael
  160 + r = @r
199 161 options = @options
200 162 anchor = r.circle(x, y, 10).attr(
201 163 fill: "#000"
... ... @@ -204,18 +166,95 @@ class BranchGraph
204 166 ).click(->
205 167 window.open options.commit_url.replace("%s", commit.id), "_blank"
206 168 ).hover(->
207   - @tooltip = r.commitTooltip(x, y + 5, commit)
  169 + @tooltip = r.commitTooltip(x + 5, y, commit)
208 170 top.push @tooltip.insertBefore(this)
209 171 , ->
210 172 @tooltip and @tooltip.remove() and delete @tooltip
211 173 )
212 174 top.push anchor
213 175  
  176 + drawDot: (x, y, commit) ->
  177 + r = @r
  178 + r.circle(x, y, 3).attr(
  179 + fill: @colors[commit.space]
  180 + stroke: "none"
  181 + )
  182 + r.rect(@offsetX + @unitSpace * @mspace + 10, y - 10, 20, 20).attr(
  183 + fill: "url(#{commit.author.icon})"
  184 + stroke: @colors[commit.space]
  185 + "stroke-width": 2
  186 + )
  187 + r.text(@offsetX + @unitSpace * @mspace + 35, y, commit.message.split("\n")[0]).attr(
  188 + "text-anchor": "start"
  189 + font: "14px Monaco, monospace"
  190 + )
  191 +
  192 + drawLines: (x, y, commit) ->
  193 + r = @r
  194 + for parent in commit.parents
  195 + parentCommit = @preparedCommits[parent[0]]
  196 + parentY = @offsetY + @unitTime * parentCommit.time
  197 + parentX1 = @offsetX + @unitSpace * (@mspace - parentCommit.space)
  198 + parentX2 = @offsetX + @unitSpace * (@mspace - parent[1])
  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 + )
  205 +
  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)
  232 +
  233 + 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)
  245 +
  246 + markCommit: (x, y, commit, graphHeight) ->
  247 + if commit.id is @options.commit_id
  248 + r = @r
  249 + r.path(["M", x + 5, y, "L", x + 15, y + 4, "L", x + 15, y - 4, "Z"]).attr(
  250 + fill: "#000"
  251 + "fill-opacity": .5
  252 + stroke: "none"
  253 + )
  254 + # Displayed in the center
  255 + @element.scrollTop(y - graphHeight / 2)
  256 +
214 257 Raphael::commitTooltip = (x, y, commit) ->
215   - icon = undefined
216   - nameText = undefined
217   - idText = undefined
218   - messageText = undefined
219 258 boxWidth = 300
220 259 boxHeight = 200
221 260 icon = @image(commit.author.icon, x, y, 20, 20)
... ...
app/assets/stylesheets/sections/graph.scss
... ... @@ -12,7 +12,7 @@
12 12 .graph {
13 13 background: #f1f1f1;
14 14 cursor: move;
15   - height: 70%;
  15 + height: 500px;
16 16 overflow: hidden;
17 17 }
18 18 }
... ...
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
... ...
spec/spec_helper.rb
... ... @@ -16,6 +16,7 @@ require &#39;email_spec&#39;
16 16 require 'sidekiq/testing/inline'
17 17 require 'capybara/poltergeist'
18 18 Capybara.javascript_driver = :poltergeist
  19 +Capybara.default_wait_time = 10
19 20  
20 21 # Requires supporting ruby files with custom matchers and macros, etc,
21 22 # in spec/support/ and its subdirectories.
... ...