Commit d6338a8482920fc69cc016e5da796194034a1861
Exists in
master
and in
4 other branches
Merge pull request #3258 from hiroponz/display-commit-msg
Display commit message on network graph.
Showing
4 changed files
with
132 additions
and
103 deletions
Show diff stats
app/assets/javascripts/branch-graph.js.coffee
| @@ -5,6 +5,10 @@ class BranchGraph | @@ -5,6 +5,10 @@ class BranchGraph | ||
| 5 | @mspace = 0 | 5 | @mspace = 0 |
| 6 | @parents = {} | 6 | @parents = {} |
| 7 | @colors = ["#000"] | 7 | @colors = ["#000"] |
| 8 | + @offsetX = 120 | ||
| 9 | + @offsetY = 20 | ||
| 10 | + @unitTime = 30 | ||
| 11 | + @unitSpace = 10 | ||
| 8 | @load() | 12 | @load() |
| 9 | 13 | ||
| 10 | load: -> | 14 | load: -> |
| @@ -20,8 +24,6 @@ class BranchGraph | @@ -20,8 +24,6 @@ class BranchGraph | ||
| 20 | 24 | ||
| 21 | prepareData: (@days, @commits) -> | 25 | prepareData: (@days, @commits) -> |
| 22 | @collectParents() | 26 | @collectParents() |
| 23 | - @mtime += 4 | ||
| 24 | - @mspace += 10 | ||
| 25 | 27 | ||
| 26 | for c in @commits | 28 | for c in @commits |
| 27 | c.isParent = true if c.id of @parents | 29 | c.isParent = true if c.id of @parents |
| @@ -35,6 +37,7 @@ class BranchGraph | @@ -35,6 +37,7 @@ class BranchGraph | ||
| 35 | @mspace = Math.max(@mspace, c.space) | 37 | @mspace = Math.max(@mspace, c.space) |
| 36 | for p in c.parents | 38 | for p in c.parents |
| 37 | @parents[p[0]] = true | 39 | @parents[p[0]] = true |
| 40 | + @mspace = Math.max(@mspace, p[1]) | ||
| 38 | 41 | ||
| 39 | collectColors: -> | 42 | collectColors: -> |
| 40 | k = 0 | 43 | k = 0 |
| @@ -46,25 +49,23 @@ class BranchGraph | @@ -46,25 +49,23 @@ class BranchGraph | ||
| 46 | k++ | 49 | k++ |
| 47 | 50 | ||
| 48 | buildGraph: -> | 51 | buildGraph: -> |
| 52 | + graphHeight = $(@element).height() | ||
| 49 | graphWidth = $(@element).width() | 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 | top = r.set() | 57 | top = r.set() |
| 54 | cuday = 0 | 58 | cuday = 0 |
| 55 | cumonth = "" | 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 | for day, mm in @days | 65 | for day, mm in @days |
| 65 | if cuday isnt day[0] | 66 | if cuday isnt day[0] |
| 66 | # Dates | 67 | # Dates |
| 67 | - r.text(offsetX + mm * 20, 31, day[0]) | 68 | + r.text(30, @offsetY + @unitTime * mm, day[0]) |
| 68 | .attr( | 69 | .attr( |
| 69 | font: "12px Monaco, monospace" | 70 | font: "12px Monaco, monospace" |
| 70 | fill: "#DDD" | 71 | fill: "#DDD" |
| @@ -73,7 +74,7 @@ class BranchGraph | @@ -73,7 +74,7 @@ class BranchGraph | ||
| 73 | 74 | ||
| 74 | if cumonth isnt day[1] | 75 | if cumonth isnt day[1] |
| 75 | # Months | 76 | # Months |
| 76 | - r.text(offsetX + mm * 20, 11, day[1]) | 77 | + r.text(10, @offsetY + @unitTime * mm, day[1]) |
| 77 | .attr( | 78 | .attr( |
| 78 | font: "12px Monaco, monospace" | 79 | font: "12px Monaco, monospace" |
| 79 | fill: "#EEE" | 80 | fill: "#EEE" |
| @@ -81,61 +82,20 @@ class BranchGraph | @@ -81,61 +82,20 @@ class BranchGraph | ||
| 81 | cumonth = day[1] | 82 | cumonth = day[1] |
| 82 | 83 | ||
| 83 | for commit in @commits | 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 | top.toFront() | 98 | top.toFront() |
| 138 | - @element.scrollLeft scrollLeft | ||
| 139 | @bindEvents() | 99 | @bindEvents() |
| 140 | 100 | ||
| 141 | bindEvents: -> | 101 | bindEvents: -> |
| @@ -167,35 +127,37 @@ class BranchGraph | @@ -167,35 +127,37 @@ class BranchGraph | ||
| 167 | element.scrollTop element.scrollTop() + 50 if event.keyCode is 40 | 127 | element.scrollTop element.scrollTop() + 50 if event.keyCode is 40 |
| 168 | 128 | ||
| 169 | appendLabel: (x, y, refs) -> | 129 | appendLabel: (x, y, refs) -> |
| 170 | - r = @raphael | 130 | + r = @r |
| 171 | shortrefs = refs | 131 | shortrefs = refs |
| 172 | # Truncate if longer than 15 chars | 132 | # Truncate if longer than 15 chars |
| 173 | shortrefs = shortrefs.substr(0, 15) + "…" if shortrefs.length > 17 | 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 | font: "10px Monaco, monospace" | 136 | font: "10px Monaco, monospace" |
| 176 | fill: "#FFF" | 137 | fill: "#FFF" |
| 177 | title: refs | 138 | title: refs |
| 178 | ) | 139 | ) |
| 179 | textbox = text.getBBox() | 140 | textbox = text.getBBox() |
| 180 | - text.transform ["t", textbox.height / -4, textbox.width / 2 + 5, "r90"] | ||
| 181 | # Create rectangle based on the size of the textbox | 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 | fill: "#000" | 143 | fill: "#000" |
| 184 | - "fill-opacity": .7 | 144 | + "fill-opacity": .5 |
| 185 | stroke: "none" | 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 | fill: "#000" | 148 | fill: "#000" |
| 189 | - "fill-opacity": .7 | 149 | + "fill-opacity": .5 |
| 190 | stroke: "none" | 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 | # Set text to front | 156 | # Set text to front |
| 195 | text.toFront() | 157 | text.toFront() |
| 196 | 158 | ||
| 197 | appendAnchor: (top, commit, x, y) -> | 159 | appendAnchor: (top, commit, x, y) -> |
| 198 | - r = @raphael | 160 | + r = @r |
| 199 | options = @options | 161 | options = @options |
| 200 | anchor = r.circle(x, y, 10).attr( | 162 | anchor = r.circle(x, y, 10).attr( |
| 201 | fill: "#000" | 163 | fill: "#000" |
| @@ -204,18 +166,95 @@ class BranchGraph | @@ -204,18 +166,95 @@ class BranchGraph | ||
| 204 | ).click(-> | 166 | ).click(-> |
| 205 | window.open options.commit_url.replace("%s", commit.id), "_blank" | 167 | window.open options.commit_url.replace("%s", commit.id), "_blank" |
| 206 | ).hover(-> | 168 | ).hover(-> |
| 207 | - @tooltip = r.commitTooltip(x, y + 5, commit) | 169 | + @tooltip = r.commitTooltip(x + 5, y, commit) |
| 208 | top.push @tooltip.insertBefore(this) | 170 | top.push @tooltip.insertBefore(this) |
| 209 | , -> | 171 | , -> |
| 210 | @tooltip and @tooltip.remove() and delete @tooltip | 172 | @tooltip and @tooltip.remove() and delete @tooltip |
| 211 | ) | 173 | ) |
| 212 | top.push anchor | 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 | Raphael::commitTooltip = (x, y, commit) -> | 257 | Raphael::commitTooltip = (x, y, commit) -> |
| 215 | - icon = undefined | ||
| 216 | - nameText = undefined | ||
| 217 | - idText = undefined | ||
| 218 | - messageText = undefined | ||
| 219 | boxWidth = 300 | 258 | boxWidth = 300 |
| 220 | boxHeight = 200 | 259 | boxHeight = 200 |
| 221 | icon = @image(commit.author.icon, x, y, 20, 20) | 260 | icon = @image(commit.author.icon, x, y, 20, 20) |
app/assets/stylesheets/sections/graph.scss
app/models/network/graph.rb
| @@ -40,15 +40,12 @@ module Network | @@ -40,15 +40,12 @@ module Network | ||
| 40 | def index_commits | 40 | def index_commits |
| 41 | days = [] | 41 | days = [] |
| 42 | @map = {} | 42 | @map = {} |
| 43 | + @reserved = {} | ||
| 43 | 44 | ||
| 44 | - @commits.reverse.each_with_index do |c,i| | 45 | + @commits.each_with_index do |c,i| |
| 45 | c.time = i | 46 | c.time = i |
| 46 | days[i] = c.committed_date | 47 | days[i] = c.committed_date |
| 47 | @map[c.id] = c | 48 | @map[c.id] = c |
| 48 | - end | ||
| 49 | - | ||
| 50 | - @reserved = {} | ||
| 51 | - days.each_index do |i| | ||
| 52 | @reserved[i] = [] | 49 | @reserved[i] = [] |
| 53 | end | 50 | end |
| 54 | 51 | ||
| @@ -135,11 +132,7 @@ module Network | @@ -135,11 +132,7 @@ module Network | ||
| 135 | spaces = [] | 132 | spaces = [] |
| 136 | 133 | ||
| 137 | commit.parents(@map).each do |parent| | 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 | space = if commit.space >= parent.space then | 137 | space = if commit.space >= parent.space then |
| 145 | find_free_parent_space(range, parent.space, -1, commit.space) | 138 | find_free_parent_space(range, parent.space, -1, commit.space) |
| @@ -166,7 +159,7 @@ module Network | @@ -166,7 +159,7 @@ module Network | ||
| 166 | range.each do |i| | 159 | range.each do |i| |
| 167 | if i != range.first && | 160 | if i != range.first && |
| 168 | i != range.last && | 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 | return true; | 164 | return true; |
| 172 | end | 165 | end |
| @@ -184,7 +177,7 @@ module Network | @@ -184,7 +177,7 @@ module Network | ||
| 184 | return | 177 | return |
| 185 | end | 178 | end |
| 186 | 179 | ||
| 187 | - time_range = leaves.last.time..leaves.first.time | 180 | + time_range = leaves.first.time..leaves.last.time |
| 188 | space_base = get_space_base(leaves) | 181 | space_base = get_space_base(leaves) |
| 189 | space = find_free_space(time_range, 2, space_base) | 182 | space = find_free_space(time_range, 2, space_base) |
| 190 | leaves.each do |l| | 183 | leaves.each do |l| |
| @@ -198,17 +191,17 @@ module Network | @@ -198,17 +191,17 @@ module Network | ||
| 198 | end | 191 | end |
| 199 | 192 | ||
| 200 | # and mark it as reserved | 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 | if parent_time.nil? | 194 | if parent_time.nil? |
| 209 | - max_time = leaves.first.time | 195 | + min_time = leaves.first.time |
| 210 | else | 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 | end | 205 | end |
| 213 | mark_reserved(min_time..max_time, space) | 206 | mark_reserved(min_time..max_time, space) |
| 214 | 207 | ||
| @@ -289,9 +282,5 @@ module Network | @@ -289,9 +282,5 @@ module Network | ||
| 289 | end | 282 | end |
| 290 | refs_cache | 283 | refs_cache |
| 291 | end | 284 | end |
| 292 | - | ||
| 293 | - def reversed_index(index) | ||
| 294 | - -index - 1 | ||
| 295 | - end | ||
| 296 | end | 285 | end |
| 297 | end | 286 | end |
spec/spec_helper.rb
| @@ -16,6 +16,7 @@ require 'email_spec' | @@ -16,6 +16,7 @@ require 'email_spec' | ||
| 16 | require 'sidekiq/testing/inline' | 16 | require 'sidekiq/testing/inline' |
| 17 | require 'capybara/poltergeist' | 17 | require 'capybara/poltergeist' |
| 18 | Capybara.javascript_driver = :poltergeist | 18 | Capybara.javascript_driver = :poltergeist |
| 19 | +Capybara.default_wait_time = 10 | ||
| 19 | 20 | ||
| 20 | # Requires supporting ruby files with custom matchers and macros, etc, | 21 | # Requires supporting ruby files with custom matchers and macros, etc, |
| 21 | # in spec/support/ and its subdirectories. | 22 | # in spec/support/ and its subdirectories. |