Commit 4398bdf2c953bf159cef1b8e34c5ec44f582b814
Exists in
master
and in
4 other branches
Merge branch 'koenpunt-gh-issue-1509'
Showing
8 changed files
with
274 additions
and
199 deletions
Show diff stats
8.17 KB
app/assets/javascripts/projects.js.coffee
... | ... | @@ -18,10 +18,3 @@ $ -> |
18 | 18 | # Ref switcher |
19 | 19 | $('.project-refs-select').on 'change', -> |
20 | 20 | $(@).parents('form').submit() |
21 | - | |
22 | -class @GraphNav | |
23 | - @init: -> | |
24 | - $('.graph svg').css 'position', 'relative' | |
25 | - $('body').bind 'keyup', (e) -> | |
26 | - $('.graph svg').animate(left: '+=400') if e.keyCode is 37 # left | |
27 | - $('.graph svg').animate(left: '-=400') if e.keyCode is 39 # right | ... | ... |
app/assets/stylesheets/common.scss
app/controllers/projects_controller.rb
... | ... | @@ -58,12 +58,12 @@ class ProjectsController < ProjectResourceController |
58 | 58 | |
59 | 59 | respond_to do |format| |
60 | 60 | format.html do |
61 | - unless @project.empty_repo? | |
62 | - @last_push = current_user.recent_push(@project.id) | |
63 | - render :show | |
64 | - else | |
65 | - render "projects/empty" | |
66 | - end | |
61 | + unless @project.empty_repo? | |
62 | + @last_push = current_user.recent_push(@project.id) | |
63 | + render :show | |
64 | + else | |
65 | + render "projects/empty" | |
66 | + end | |
67 | 67 | end |
68 | 68 | format.js |
69 | 69 | end |
... | ... | @@ -87,9 +87,13 @@ class ProjectsController < ProjectResourceController |
87 | 87 | end |
88 | 88 | |
89 | 89 | def graph |
90 | - graph = Gitlab::Graph::JsonBuilder.new(project) | |
91 | - | |
92 | - @days_json, @commits_json = graph.days_json, graph.commits_json | |
90 | + respond_to do |format| | |
91 | + format.html | |
92 | + format.json do | |
93 | + graph = Gitlab::Graph::JsonBuilder.new(project) | |
94 | + render :json => graph.to_json | |
95 | + end | |
96 | + end | |
93 | 97 | end |
94 | 98 | |
95 | 99 | def destroy | ... | ... |
app/views/projects/graph.html.haml
... | ... | @@ -2,13 +2,15 @@ |
2 | 2 | %br |
3 | 3 | .graph_holder |
4 | 4 | %h4 |
5 | - %small You can move around the graph by using arrow keys. | |
5 | + %small You can move around the graph by using the arrow keys. | |
6 | 6 | #holder.graph |
7 | + .loading.loading-gray | |
8 | + | |
7 | 9 | :javascript |
8 | - var chunk1={commits:#{@commits_json}}; | |
9 | - var days=#{@days_json}; | |
10 | - initGraph(); | |
10 | + var branch_graph; | |
11 | 11 | $(function(){ |
12 | - branchGraph($("#holder")[0]); | |
13 | - GraphNav.init(); | |
12 | + branch_graph = new BranchGraph($("#holder"), { | |
13 | + url: '#{url_for controller: 'projects', action: 'graph', format: :json}', | |
14 | + commit_url: '#{url_for controller: 'projects', action: 'show'}/commits/%s' | |
15 | + }); | |
14 | 16 | }); | ... | ... |
lib/gitlab/graph/commit.rb
lib/gitlab/graph/json_builder.rb
... | ... | @@ -17,16 +17,15 @@ module Gitlab |
17 | 17 | @commits = collect_commits |
18 | 18 | @days = index_commits |
19 | 19 | end |
20 | - | |
21 | - def days_json | |
22 | - @days_json = @days.compact.map { |d| [d.day, d.strftime("%b")] }.to_json | |
23 | - end | |
24 | - | |
25 | - def commits_json | |
26 | - @commits_json = @commits.map(&:to_graph_hash).to_json | |
20 | + | |
21 | + def to_json(*args) | |
22 | + { | |
23 | + days: @days.compact.map { |d| [d.day, d.strftime("%b")] }, | |
24 | + commits: @commits.map(&:to_graph_hash) | |
25 | + }.to_json(*args) | |
27 | 26 | end |
28 | - | |
29 | - protected | |
27 | + | |
28 | + protected | |
30 | 29 | |
31 | 30 | # Get commits from repository |
32 | 31 | # | ... | ... |
vendor/assets/javascripts/branch-graph.js
1 | -var commits = {}, | |
2 | - comms = {}, | |
3 | - pixelsX = [], | |
4 | - pixelsY = [], | |
5 | - mmax = Math.max, | |
6 | - mtime = 0, | |
7 | - mspace = 0, | |
8 | - parents = {}, | |
9 | - ii = 0, | |
10 | - colors = ["#000"]; | |
1 | +!function(){ | |
11 | 2 | |
12 | -function initGraph(){ | |
13 | - commits = chunk1.commits; | |
14 | - ii = commits.length; | |
15 | - for (var i = 0; i < ii; i++) { | |
16 | - for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { | |
17 | - parents[commits[i].parents[j][0]] = true; | |
3 | + var BranchGraph = function(element, options){ | |
4 | + this.element = element; | |
5 | + this.options = options; | |
6 | + | |
7 | + this.preparedCommits = {}; | |
8 | + this.mtime = 0; | |
9 | + this.mspace = 0; | |
10 | + this.parents = {}; | |
11 | + this.colors = ["#000"]; | |
12 | + | |
13 | + this.load(); | |
14 | + }; | |
15 | + | |
16 | + BranchGraph.prototype.load = function(){ | |
17 | + $.ajax({ | |
18 | + url: this.options.url, | |
19 | + method: 'get', | |
20 | + dataType: 'json', | |
21 | + success: $.proxy(function(data){ | |
22 | + $('.loading', this.element).hide(); | |
23 | + this.prepareData(data.days, data.commits); | |
24 | + this.buildGraph(); | |
25 | + }, this) | |
26 | + }); | |
27 | + }; | |
28 | + | |
29 | + BranchGraph.prototype.prepareData = function(days, commits){ | |
30 | + this.days = days; | |
31 | + this.dayCount = days.length; | |
32 | + this.commits = commits; | |
33 | + this.commitCount = commits.length; | |
34 | + | |
35 | + this.collectParents(); | |
36 | + | |
37 | + this.mtime += 4; | |
38 | + this.mspace += 10; | |
39 | + for (var i = 0; i < this.commitCount; i++) { | |
40 | + if (this.commits[i].id in this.parents) { | |
41 | + this.commits[i].isParent = true; | |
18 | 42 | } |
19 | - mtime = Math.max(mtime, commits[i].time); | |
20 | - mspace = Math.max(mspace, commits[i].space); | |
21 | - } | |
22 | - mtime = mtime + 4; | |
23 | - mspace = mspace + 10; | |
24 | - for (i = 0; i < ii; i++) { | |
25 | - if (commits[i].id in parents) { | |
26 | - commits[i].isParent = true; | |
43 | + this.preparedCommits[this.commits[i].id] = this.commits[i]; | |
44 | + } | |
45 | + this.collectColors(); | |
46 | + }; | |
47 | + | |
48 | + BranchGraph.prototype.collectParents = function(){ | |
49 | + for (var i = 0; i < this.commitCount; i++) { | |
50 | + for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) { | |
51 | + this.parents[this.commits[i].parents[j][0]] = true; | |
27 | 52 | } |
28 | - comms[commits[i].id] = commits[i]; | |
29 | - } | |
30 | - for (var k = 0; k < mspace; k++) { | |
31 | - colors.push(Raphael.getColor()); | |
32 | - } | |
33 | -} | |
34 | - | |
35 | -function branchGraph(holder) { | |
36 | - var ch = mspace * 20 + 20, cw = mtime * 20 + 20, | |
37 | - r = Raphael("holder", cw, ch), | |
38 | - top = r.set(); | |
39 | - var cuday = 0, cumonth = ""; | |
40 | - r.rect(0, 0, days.length * 20 + 80, 30).attr({fill: "#222"}); | |
41 | - r.rect(0, 30, days.length * 20 + 80, 20).attr({fill: "#444"}); | |
42 | - | |
43 | - for (mm = 0; mm < days.length; mm++) { | |
44 | - if(days[mm] != null){ | |
45 | - if(cuday != days[mm][0]){ | |
46 | - r.text(10 + mm * 20, 40, days[mm][0]).attr({font: "14px Fontin-Sans, Arial", fill: "#DDD"}); | |
47 | - cuday = days[mm][0] | |
48 | - } | |
49 | - if(cumonth != days[mm][1]){ | |
50 | - r.text(10 + mm * 20, 15, days[mm][1]).attr({font: "14px Fontin-Sans, Arial", fill: "#EEE"}); | |
51 | - cumonth = days[mm][1] | |
52 | - } | |
53 | + this.mtime = Math.max(this.mtime, this.commits[i].time); | |
54 | + this.mspace = Math.max(this.mspace, this.commits[i].space); | |
55 | + } | |
56 | + }; | |
57 | + | |
58 | + BranchGraph.prototype.collectColors = function(){ | |
59 | + for (var k = 0; k < this.mspace; k++) { | |
60 | + this.colors.push(Raphael.getColor()); | |
61 | + } | |
62 | + }; | |
53 | 63 | |
64 | + BranchGraph.prototype.buildGraph = function(){ | |
65 | + var graphWidth = $(this.element).width() | |
66 | + , ch = this.mspace * 20 + 20 | |
67 | + , cw = Math.max(graphWidth, this.mtime * 20 + 20) | |
68 | + , r = Raphael(this.element.get(0), cw, ch) | |
69 | + , top = r.set() | |
70 | + , cuday = 0 | |
71 | + , cumonth = "" | |
72 | + , offsetX = 20 | |
73 | + , offsetY = 60 | |
74 | + , barWidth = Math.max(graphWidth, this.dayCount * 20 + 80); | |
75 | + | |
76 | + this.raphael = r; | |
77 | + | |
78 | + r.rect(0, 0, barWidth, 20).attr({fill: "#222"}); | |
79 | + r.rect(0, 20, barWidth, 20).attr({fill: "#444"}); | |
80 | + | |
81 | + for (mm = 0; mm < this.dayCount; mm++) { | |
82 | + if(this.days[mm] != null){ | |
83 | + if(cuday != this.days[mm][0]){ | |
84 | + // Dates | |
85 | + r.text(offsetX + mm * 20, 31, this.days[mm][0]).attr({ | |
86 | + font: "12px Monaco, Arial", | |
87 | + fill: "#DDD" | |
88 | + }); | |
89 | + cuday = this.days[mm][0]; | |
90 | + } | |
91 | + if(cumonth != this.days[mm][1]){ | |
92 | + // Months | |
93 | + r.text(offsetX + mm * 20, 11, this.days[mm][1]).attr({ | |
94 | + font: "12px Monaco, Arial", | |
95 | + fill: "#EEE" | |
96 | + }); | |
97 | + cumonth = this.days[mm][1]; | |
54 | 98 | } |
99 | + } | |
55 | 100 | } |
56 | - for (i = 0; i < ii; i++) { | |
57 | - var x = 10 + 20 * commits[i].time, | |
58 | - y = 70 + 20 * commits[i].space; | |
59 | - r.circle(x, y, 3).attr({fill: colors[commits[i].space], stroke: "none"}); | |
60 | - if (commits[i].refs != null && commits[i].refs != "") { | |
61 | - var longrefs = commits[i].refs | |
62 | - var shortrefs = commits[i].refs; | |
63 | - if (shortrefs.length > 15){ | |
64 | - shortrefs = shortrefs.substr(0,13) + "..."; | |
65 | - } | |
66 | - var t = r.text(x+5, y+5, shortrefs).attr({font: "12px Fontin-Sans, Arial", fill: "#666", | |
67 | - title: longrefs, cursor: "pointer", rotation: "90"}); | |
68 | - | |
69 | - var textbox = t.getBBox(); | |
70 | - t.translate(textbox.height/-4,textbox.width/2); | |
101 | + | |
102 | + for (i = 0; i < this.commitCount; i++) { | |
103 | + var x = offsetX + 20 * this.commits[i].time | |
104 | + , y = offsetY + 20 * this.commits[i].space; | |
105 | + r.circle(x, y, 3).attr({ | |
106 | + fill: this.colors[this.commits[i].space], | |
107 | + stroke: "none" | |
108 | + }); | |
109 | + if (this.commits[i].refs != null && this.commits[i].refs != "") { | |
110 | + var longrefs = this.commits[i].refs | |
111 | + , shortrefs = this.commits[i].refs; | |
112 | + if (shortrefs.length > 15){ | |
113 | + shortrefs = shortrefs.substr(0,13) + "..."; | |
71 | 114 | } |
72 | - for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { | |
73 | - var c = comms[commits[i].parents[j][0]]; | |
74 | - if (c) { | |
75 | - var cx = 10 + 20 * c.time, | |
76 | - cy = 70 + 20 * c.space; | |
77 | - if (c.space == commits[i].space) { | |
78 | - r.path("M" + (x - 5) + "," + (y + .0001) + "L" + (15 + 20 * c.time) + "," + (y + .0001)) | |
79 | - .attr({stroke: colors[c.space], "stroke-width": 2}); | |
115 | + var t = r.text(x+5, y+8, shortrefs).attr({ | |
116 | + font: "12px Monaco, Arial", | |
117 | + fill: "#666", | |
118 | + title: longrefs, | |
119 | + cursor: "pointer", | |
120 | + rotation: "90" | |
121 | + }); | |
80 | 122 | |
81 | - } else if (c.space < commits[i].space) { | |
82 | - r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 5, "L", cx, y - 5, cx, cy]) | |
83 | - .attr({stroke: colors[commits[i].space], "stroke-width": 2}); | |
84 | - } else { | |
85 | - r.path(["M", x - 3, y + 6, "l-4,3,4,2,0,-5L", x - 10, y + 20, "L", x - 10, cy, cx, cy]) | |
86 | - .attr({stroke: colors[c.space], "stroke-width": 2}); | |
87 | - } | |
88 | - } | |
123 | + var textbox = t.getBBox(); | |
124 | + t.translate(textbox.height/-4, textbox.width/2); | |
125 | + } | |
126 | + var c; | |
127 | + for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) { | |
128 | + c = this.preparedCommits[this.commits[i].parents[j][0]]; | |
129 | + if (c) { | |
130 | + var cx = offsetX + 20 * c.time | |
131 | + , cy = offsetY + 20 * c.space; | |
132 | + if (c.space == this.commits[i].space) { | |
133 | + r.path([ | |
134 | + "M", x, y, | |
135 | + "L", x - 20 * (c.time + 1), y | |
136 | + ]).attr({ | |
137 | + stroke: this.colors[c.space], | |
138 | + "stroke-width": 2 | |
139 | + }); | |
140 | + | |
141 | + } else if (c.space < this.commits[i].space) { | |
142 | + r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 5, "L", cx, y - 5, cx, cy]) | |
143 | + .attr({ | |
144 | + stroke: this.colors[this.commits[i].space], | |
145 | + "stroke-width": 2 | |
146 | + }); | |
147 | + } else { | |
148 | + r.path(["M", x - 3, y + 6, "l-4,3,4,2,0,-5L", x - 10, y + 20, "L", x - 10, cy, cx, cy]) | |
149 | + .attr({ | |
150 | + stroke: this.colors[c.space], | |
151 | + "stroke-width": 2 | |
152 | + }); | |
153 | + } | |
89 | 154 | } |
90 | - (function (c, x, y) { | |
91 | - top.push(r.circle(x, y, 10).attr({fill: "#000", opacity: 0, cursor: "pointer"}) | |
92 | - .click(function(){ | |
93 | - location.href = location.href.replace("graph", "commit/" + c.id); | |
94 | - }) | |
95 | - .hover(function () { | |
96 | - var s = r.text(100, 100,c.author + "\n \n" +c.id + "\n \n" + c.message).attr({fill: "#fff"}); | |
97 | - this.popup = r.popupit(x, y + 5, s, 0); | |
98 | - top.push(this.popup.insertBefore(this)); | |
99 | - }, function () { | |
100 | - this.popup && this.popup.remove() && delete this.popup; | |
101 | - })); | |
102 | - }(commits[i], x, y)); | |
155 | + } | |
156 | + this.appendAnchor(top, this.commits[i], x, y); | |
103 | 157 | } |
104 | 158 | top.toFront(); |
105 | - var hw = holder.offsetWidth, | |
106 | - hh = holder.offsetHeight, | |
107 | - v = r.rect(hw - 8, 0, 4, Math.pow(hh, 2) / ch, 2).attr({fill: "#000", opacity: 0}), | |
108 | - h = r.rect(0, hh - 8, Math.pow(hw, 2) / cw, 4, 2).attr({fill: "#000", opacity: 0}), | |
109 | - bars = r.set(v, h), | |
110 | - drag, | |
111 | - dragger = function (e) { | |
112 | - if (drag) { | |
113 | - e = e || window.event; | |
114 | - holder.scrollLeft = drag.sl - (e.clientX - drag.x); | |
115 | - holder.scrollTop = drag.st - (e.clientY - drag.y); | |
116 | - } | |
117 | - }; | |
118 | - holder.onmousedown = function (e) { | |
119 | - e = e || window.event; | |
120 | - drag = {x: e.clientX, y: e.clientY, st: holder.scrollTop, sl: holder.scrollLeft}; | |
121 | - document.onmousemove = dragger; | |
122 | - bars.animate({opacity: .5}, 300); | |
123 | - }; | |
124 | - document.onmouseup = function () { | |
125 | - drag = false; | |
126 | - document.onmousemove = null; | |
127 | - bars.animate({opacity: 0}, 300); | |
159 | + this.element.scrollLeft(cw); | |
160 | + this.bindEvents(); | |
161 | + }; | |
162 | + | |
163 | + BranchGraph.prototype.bindEvents = function(){ | |
164 | + var drag = {} | |
165 | + , element = this.element; | |
166 | + | |
167 | + var dragger = function(event){ | |
168 | + element.scrollLeft(drag.sl - (event.clientX - drag.x)); | |
169 | + element.scrollTop(drag.st - (event.clientY - drag.y)); | |
128 | 170 | }; |
129 | - holder.scrollLeft = cw; | |
130 | -}; | |
131 | -Raphael.fn.popupit = function (x, y, set, dir, size) { | |
132 | - dir = dir == null ? 2 : dir; | |
133 | - size = size || 5; | |
134 | - x = Math.round(x); | |
135 | - y = Math.round(y); | |
136 | - var bb = set.getBBox(), | |
137 | - w = Math.round(bb.width / 2), | |
138 | - h = Math.round(bb.height / 2), | |
139 | - dx = [0, w + size * 2, 0, -w - size * 2], | |
140 | - dy = [-h * 2 - size * 3, -h - size, 0, -h - size], | |
141 | - p = ["M", x - dx[dir], y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size, | |
142 | - "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size, | |
143 | - "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size, | |
144 | - "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size, | |
145 | - "l", -mmax(w - size, 0), 0, "z"].join(","), | |
146 | - xy = [{x: x, y: y + size * 2 + h}, {x: x - size * 2 - w, y: y}, {x: x, y: y - size * 2 - h}, {x: x + size * 2 + w, y: y}][dir]; | |
147 | - set.translate(xy.x - w - bb.x, xy.y - h - bb.y); | |
148 | - return this.set(this.path(p).attr({fill: "#234", stroke: "none"}).insertBefore(set.node ? set : set[0]), set); | |
149 | -}; | |
150 | -Raphael.fn.popup = function (x, y, text, dir, size) { | |
151 | - dir = dir == null ? 2 : dir > 3 ? 3 : dir; | |
152 | - size = size || 5; | |
153 | - text = text || "$9.99"; | |
154 | - var res = this.set(), | |
155 | - d = 3; | |
156 | - res.push(this.path().attr({fill: "#000", stroke: "#000"})); | |
157 | - res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"})); | |
158 | - res.update = function (X, Y, withAnimation) { | |
159 | - X = X || x; | |
160 | - Y = Y || y; | |
161 | - var bb = this[1].getBBox(), | |
162 | - w = bb.width / 2, | |
163 | - h = bb.height / 2, | |
164 | - dx = [0, w + size * 2, 0, -w - size * 2], | |
165 | - dy = [-h * 2 - size * 3, -h - size, 0, -h - size], | |
166 | - p = ["M", X - dx[dir], Y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size, | |
167 | - "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size, | |
168 | - "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size, | |
169 | - "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size, | |
170 | - "l", -mmax(w - size, 0), 0, "z"].join(","), | |
171 | - xy = [{x: X, y: Y + size * 2 + h}, {x: X - size * 2 - w, y: Y}, {x: X, y: Y - size * 2 - h}, {x: X + size * 2 + w, y: Y}][dir]; | |
172 | - xy.path = p; | |
173 | - if (withAnimation) { | |
174 | - this.animate(xy, 500, ">"); | |
175 | - } else { | |
176 | - this.attr(xy); | |
171 | + | |
172 | + element.on({ | |
173 | + mousedown: function (event) { | |
174 | + drag = { | |
175 | + x: event.clientX, | |
176 | + y: event.clientY, | |
177 | + st: element.scrollTop(), | |
178 | + sl: element.scrollLeft() | |
179 | + }; | |
180 | + $(window).on('mousemove', dragger); | |
181 | + } | |
182 | + }); | |
183 | + $(window).on({ | |
184 | + mouseup: function(){ | |
185 | + //bars.animate({opacity: 0}, 300); | |
186 | + $(window).off('mousemove', dragger); | |
187 | + }, | |
188 | + keydown: function(event){ | |
189 | + if(event.keyCode == 37){ | |
190 | + // left | |
191 | + element.scrollLeft( element.scrollLeft() - 50); | |
177 | 192 | } |
178 | - return this; | |
179 | - }; | |
180 | - return res.update(x, y); | |
193 | + if(event.keyCode == 38){ | |
194 | + // top | |
195 | + element.scrollTop( element.scrollTop() - 50); | |
196 | + } | |
197 | + if(event.keyCode == 39){ | |
198 | + // right | |
199 | + element.scrollLeft( element.scrollLeft() + 50); | |
200 | + } | |
201 | + if(event.keyCode == 40){ | |
202 | + // bottom | |
203 | + element.scrollTop( element.scrollTop() + 50); | |
204 | + } | |
205 | + } | |
206 | + }); | |
207 | + }; | |
208 | + | |
209 | + BranchGraph.prototype.appendAnchor = function(top, c, x, y) { | |
210 | + var r = this.raphael | |
211 | + , options = this.options | |
212 | + , anchor; | |
213 | + anchor = r.circle(x, y, 10).attr({ | |
214 | + fill: "#000", | |
215 | + opacity: 0, | |
216 | + cursor: "pointer" | |
217 | + }) | |
218 | + .click(function(){ | |
219 | + window.location = options.commit_url.replace('%s', c.id); | |
220 | + }) | |
221 | + .hover(function(){ | |
222 | + var text = r.text(100, 100, c.author + "\n \n" + c.id + "\n \n" + c.message).attr({ | |
223 | + fill: "#fff" | |
224 | + }); | |
225 | + this.popup = r.tooltip(x, y + 5, text, 0); | |
226 | + top.push(this.popup.insertBefore(this)); | |
227 | + }, function(){ | |
228 | + this.popup && this.popup.remove() && delete this.popup; | |
229 | + }); | |
230 | + top.push(anchor); | |
231 | + }; | |
232 | + | |
233 | + this.BranchGraph = BranchGraph; | |
234 | + | |
235 | +}(this); | |
236 | +Raphael.fn.tooltip = function (x, y, set, dir, size) { | |
237 | + dir = dir == null ? 2 : dir; | |
238 | + size = size || 5; | |
239 | + x = Math.round(x); | |
240 | + y = Math.round(y); | |
241 | + var mmax = Math.max | |
242 | + , bb = set.getBBox() | |
243 | + , w = Math.round(bb.width / 2) | |
244 | + , h = Math.round(bb.height / 2) | |
245 | + , dx = [0, w + size * 2, 0, -w - size * 2] | |
246 | + , dy = [-h * 2 - size * 3, -h - size, 0, -h - size] | |
247 | + , p = ["M", x - dx[dir], y - dy[dir], "l", -size, (dir == 2) * -size, -mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, -size, -size, | |
248 | + "l", 0, -mmax(h - size, 0), (dir == 3) * -size, -size, (dir == 3) * size, -size, 0, -mmax(h - size, 0), "a", size, size, 0, 0, 1, size, -size, | |
249 | + "l", mmax(w - size, 0), 0, size, !dir * -size, size, !dir * size, mmax(w - size, 0), 0, "a", size, size, 0, 0, 1, size, size, | |
250 | + "l", 0, mmax(h - size, 0), (dir == 1) * size, size, (dir == 1) * -size, size, 0, mmax(h - size, 0), "a", size, size, 0, 0, 1, -size, size, | |
251 | + "l", -mmax(w - size, 0), 0, "z"].join(",") | |
252 | + , xy = [{x: x, y: y + size * 2 + h}, {x: x - size * 2 - w, y: y}, {x: x, y: y - size * 2 - h}, {x: x + size * 2 + w, y: y}][dir]; | |
253 | + set.translate(xy.x - w - bb.x, xy.y - h - bb.y); | |
254 | + return this.set(this.path(p).attr({fill: "#234", stroke: "none"}).insertBefore(set.node ? set : set[0]), set); | |
181 | 255 | }; | ... | ... |