Commit 916c61fc64292bf4ae2fd84cbbbc86a5afa943bf
1 parent
1f6b6b6c
Exists in
master
and in
4 other branches
Refactor: clean up code.
Showing
1 changed file
with
21 additions
and
20 deletions
Show diff stats
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 = 20 | |
11 | + @unitSpace = 10 | |
8 | 12 | @load() |
9 | 13 | |
10 | 14 | load: -> |
... | ... | @@ -47,24 +51,21 @@ class BranchGraph |
47 | 51 | buildGraph: -> |
48 | 52 | graphHeight = $(@element).height() |
49 | 53 | graphWidth = $(@element).width() |
50 | - ch = Math.max(graphHeight, @mtime * 20 + 100) | |
51 | - cw = Math.max(graphWidth, @mspace * 10 + 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 = 120 | |
57 | - @offsetY = 20 | |
58 | - barHeight = Math.max(graphHeight, @days.length * 20 + 320) | |
59 | - @scrollLeft = cw | |
60 | - @raphael = r | |
60 | + barHeight = Math.max(graphHeight, @unitTime * @days.length + 320) | |
61 | + | |
61 | 62 | r.rect(0, 0, 20, barHeight).attr fill: "#222" |
62 | 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(30, @offsetY + mm * 20, 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(10, @offsetY + mm * 20, 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,8 +82,8 @@ class BranchGraph |
81 | 82 | cumonth = day[1] |
82 | 83 | |
83 | 84 | for commit in @commits |
84 | - x = @offsetX + 10 * (@mspace - commit.space) | |
85 | - y = @offsetY + 20 * commit.time | |
85 | + x = @offsetX + @unitSpace * (@mspace - commit.space) | |
86 | + y = @offsetY + @unitTime * commit.time | |
86 | 87 | |
87 | 88 | @drawDot(x, y, commit) |
88 | 89 | |
... | ... | @@ -126,7 +127,7 @@ class BranchGraph |
126 | 127 | element.scrollTop element.scrollTop() + 50 if event.keyCode is 40 |
127 | 128 | |
128 | 129 | appendLabel: (x, y, refs) -> |
129 | - r = @raphael | |
130 | + r = @r | |
130 | 131 | shortrefs = refs |
131 | 132 | # Truncate if longer than 15 chars |
132 | 133 | shortrefs = shortrefs.substr(0, 15) + "…" if shortrefs.length > 17 |
... | ... | @@ -156,7 +157,7 @@ class BranchGraph |
156 | 157 | text.toFront() |
157 | 158 | |
158 | 159 | appendAnchor: (top, commit, x, y) -> |
159 | - r = @raphael | |
160 | + r = @r | |
160 | 161 | options = @options |
161 | 162 | anchor = r.circle(x, y, 10).attr( |
162 | 163 | fill: "#000" |
... | ... | @@ -173,19 +174,19 @@ class BranchGraph |
173 | 174 | top.push anchor |
174 | 175 | |
175 | 176 | drawDot: (x, y, commit) -> |
176 | - r = @raphael | |
177 | + r = @r | |
177 | 178 | r.circle(x, y, 3).attr( |
178 | 179 | fill: @colors[commit.space] |
179 | 180 | stroke: "none" |
180 | 181 | ) |
181 | 182 | |
182 | 183 | drawLines: (x, y, commit) -> |
183 | - r = @raphael | |
184 | + r = @r | |
184 | 185 | for parent in commit.parents |
185 | 186 | parentCommit = @preparedCommits[parent[0]] |
186 | - parentY = @offsetY + 20 * parentCommit.time | |
187 | - parentX1 = @offsetX + 10 * (@mspace - parentCommit.space) | |
188 | - parentX2 = @offsetX + 10 * (@mspace - parent[1]) | |
187 | + parentY = @offsetY + @unitTime * parentCommit.time | |
188 | + parentX1 = @offsetX + @unitSpace * (@mspace - parentCommit.space) | |
189 | + parentX2 = @offsetX + @unitSpace * (@mspace - parent[1]) | |
189 | 190 | |
190 | 191 | if parentCommit.space is commit.space and parentCommit.space is parent[1] |
191 | 192 | r.path(["M", x, y, "L", parentX1, parentY]).attr( |
... | ... | @@ -235,7 +236,7 @@ class BranchGraph |
235 | 236 | |
236 | 237 | markCommit: (x, y, commit, graphHeight) -> |
237 | 238 | if commit.id is @options.commit_id |
238 | - r = @raphael | |
239 | + r = @r | |
239 | 240 | r.path(["M", x + 5, y, "L", x + 15, y + 4, "L", x + 15, y - 4, "Z"]).attr( |
240 | 241 | fill: "#000" |
241 | 242 | "fill-opacity": .5 | ... | ... |