Commit 85c468ec480a1541de36da07fc5fb4ca73c9ad5e
1 parent
63b58b94
Exists in
master
and in
4 other branches
Render graph partially.
Showing
1 changed file
with
55 additions
and
27 deletions
Show diff stats
app/assets/javascripts/branch-graph.js.coffee
| ... | ... | @@ -9,6 +9,7 @@ class BranchGraph |
| 9 | 9 | @offsetY = 20 |
| 10 | 10 | @unitTime = 30 |
| 11 | 11 | @unitSpace = 10 |
| 12 | + @prev_start = -1 | |
| 12 | 13 | @load() |
| 13 | 14 | |
| 14 | 15 | load: -> |
| ... | ... | @@ -24,10 +25,18 @@ class BranchGraph |
| 24 | 25 | |
| 25 | 26 | prepareData: (@days, @commits) -> |
| 26 | 27 | @collectParents() |
| 28 | + @graphHeight = $(@element).height() | |
| 29 | + @graphWidth = $(@element).width() | |
| 30 | + ch = Math.max(@graphHeight, @offsetY + @unitTime * @mtime + 150) | |
| 31 | + cw = Math.max(@graphWidth, @offsetX + @unitSpace * @mspace + 300) | |
| 32 | + @r = Raphael(@element.get(0), cw, ch) | |
| 33 | + @top = @r.set() | |
| 34 | + @barHeight = Math.max(@graphHeight, @unitTime * @days.length + 320) | |
| 27 | 35 | |
| 28 | 36 | for c in @commits |
| 29 | 37 | c.isParent = true if c.id of @parents |
| 30 | 38 | @preparedCommits[c.id] = c |
| 39 | + @markCommit(c) | |
| 31 | 40 | |
| 32 | 41 | @collectColors() |
| 33 | 42 | |
| ... | ... | @@ -49,18 +58,12 @@ class BranchGraph |
| 49 | 58 | k++ |
| 50 | 59 | |
| 51 | 60 | buildGraph: -> |
| 52 | - graphHeight = $(@element).height() | |
| 53 | - graphWidth = $(@element).width() | |
| 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) | |
| 57 | - top = r.set() | |
| 61 | + r = @r | |
| 58 | 62 | cuday = 0 |
| 59 | 63 | cumonth = "" |
| 60 | - barHeight = Math.max(graphHeight, @unitTime * @days.length + 320) | |
| 61 | 64 | |
| 62 | - r.rect(0, 0, 26, barHeight).attr fill: "#222" | |
| 63 | - r.rect(26, 0, 20, barHeight).attr fill: "#444" | |
| 65 | + r.rect(0, 0, 26, @barHeight).attr fill: "#222" | |
| 66 | + r.rect(26, 0, 20, @barHeight).attr fill: "#444" | |
| 64 | 67 | |
| 65 | 68 | for day, mm in @days |
| 66 | 69 | if cuday isnt day[0] |
| ... | ... | @@ -81,22 +84,40 @@ class BranchGraph |
| 81 | 84 | ) |
| 82 | 85 | cumonth = day[1] |
| 83 | 86 | |
| 84 | - for commit in @commits | |
| 85 | - x = @offsetX + @unitSpace * (@mspace - commit.space) | |
| 86 | - y = @offsetY + @unitTime * commit.time | |
| 87 | + @renderPartialGraph() | |
| 87 | 88 | |
| 88 | - @drawDot(x, y, commit) | |
| 89 | + @bindEvents() | |
| 89 | 90 | |
| 90 | - @drawLines(x, y, commit) | |
| 91 | + renderPartialGraph: -> | |
| 92 | + start = Math.floor((@element.scrollTop() - @offsetY) / @unitTime) - 10 | |
| 93 | + start = 0 if start < 0 | |
| 94 | + end = start + 40 | |
| 95 | + end = @commits.length if @commits.length < end | |
| 91 | 96 | |
| 92 | - @appendLabel(x, y, commit.refs) if commit.refs | |
| 97 | + if @prev_start == -1 or Math.abs(@prev_start - start) > 10 | |
| 98 | + i = start | |
| 93 | 99 | |
| 94 | - @appendAnchor(top, commit, x, y) | |
| 100 | + @prev_start = start | |
| 95 | 101 | |
| 96 | - @markCommit(x, y, commit, graphHeight) | |
| 102 | + while i < end | |
| 103 | + commit = @commits[i] | |
| 104 | + i += 1 | |
| 97 | 105 | |
| 98 | - top.toFront() | |
| 99 | - @bindEvents() | |
| 106 | + if commit.hasDrawn isnt true | |
| 107 | + x = @offsetX + @unitSpace * (@mspace - commit.space) | |
| 108 | + y = @offsetY + @unitTime * commit.time | |
| 109 | + | |
| 110 | + @drawDot(x, y, commit) | |
| 111 | + | |
| 112 | + @drawLines(x, y, commit) | |
| 113 | + | |
| 114 | + @appendLabel(x, y, commit) | |
| 115 | + | |
| 116 | + @appendAnchor(x, y, commit) | |
| 117 | + | |
| 118 | + commit.hasDrawn = true | |
| 119 | + | |
| 120 | + @top.toFront() | |
| 100 | 121 | |
| 101 | 122 | bindEvents: -> |
| 102 | 123 | drag = {} |
| ... | ... | @@ -114,9 +135,10 @@ class BranchGraph |
| 114 | 135 | $(window).on "mousemove", dragger |
| 115 | 136 | |
| 116 | 137 | $(window).on |
| 117 | - mouseup: -> | |
| 138 | + mouseup: => | |
| 118 | 139 | $(window).off "mousemove", dragger |
| 119 | - keydown: (event) -> | |
| 140 | + @renderPartialGraph() | |
| 141 | + keydown: (event) => | |
| 120 | 142 | # left |
| 121 | 143 | element.scrollLeft element.scrollLeft() - 50 if event.keyCode is 37 |
| 122 | 144 | # top |
| ... | ... | @@ -125,17 +147,20 @@ class BranchGraph |
| 125 | 147 | element.scrollLeft element.scrollLeft() + 50 if event.keyCode is 39 |
| 126 | 148 | # bottom |
| 127 | 149 | element.scrollTop element.scrollTop() + 50 if event.keyCode is 40 |
| 150 | + @renderPartialGraph() | |
| 151 | + | |
| 152 | + appendLabel: (x, y, commit) -> | |
| 153 | + return unless commit.refs | |
| 128 | 154 | |
| 129 | - appendLabel: (x, y, refs) -> | |
| 130 | 155 | r = @r |
| 131 | - shortrefs = refs | |
| 156 | + shortrefs = commit.refs | |
| 132 | 157 | # Truncate if longer than 15 chars |
| 133 | 158 | shortrefs = shortrefs.substr(0, 15) + "…" if shortrefs.length > 17 |
| 134 | 159 | text = r.text(x + 4, y, shortrefs).attr( |
| 135 | 160 | "text-anchor": "start" |
| 136 | 161 | font: "10px Monaco, monospace" |
| 137 | 162 | fill: "#FFF" |
| 138 | - title: refs | |
| 163 | + title: commit.refs | |
| 139 | 164 | ) |
| 140 | 165 | textbox = text.getBBox() |
| 141 | 166 | # Create rectangle based on the size of the textbox |
| ... | ... | @@ -156,8 +181,9 @@ class BranchGraph |
| 156 | 181 | # Set text to front |
| 157 | 182 | text.toFront() |
| 158 | 183 | |
| 159 | - appendAnchor: (top, commit, x, y) -> | |
| 184 | + appendAnchor: (x, y, commit) -> | |
| 160 | 185 | r = @r |
| 186 | + top = @top | |
| 161 | 187 | options = @options |
| 162 | 188 | anchor = r.circle(x, y, 10).attr( |
| 163 | 189 | fill: "#000" |
| ... | ... | @@ -240,16 +266,18 @@ class BranchGraph |
| 240 | 266 | stroke: color |
| 241 | 267 | "stroke-width": 2) |
| 242 | 268 | |
| 243 | - markCommit: (x, y, commit, graphHeight) -> | |
| 269 | + markCommit: (commit) -> | |
| 244 | 270 | if commit.id is @options.commit_id |
| 245 | 271 | r = @r |
| 272 | + x = @offsetX + @unitSpace * (@mspace - commit.space) | |
| 273 | + y = @offsetY + @unitTime * commit.time | |
| 246 | 274 | r.path(["M", x + 5, y, "L", x + 15, y + 4, "L", x + 15, y - 4, "Z"]).attr( |
| 247 | 275 | fill: "#000" |
| 248 | 276 | "fill-opacity": .5 |
| 249 | 277 | stroke: "none" |
| 250 | 278 | ) |
| 251 | 279 | # Displayed in the center |
| 252 | - @element.scrollTop(y - graphHeight / 2) | |
| 280 | + @element.scrollTop(y - @graphHeight / 2) | |
| 253 | 281 | |
| 254 | 282 | Raphael::commitTooltip = (x, y, commit) -> |
| 255 | 283 | boxWidth = 300 | ... | ... |