Commit fed9a3d5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'koenpunt-raphael-update'

parents e142ebde 47dd9e42
...@@ -108,7 +108,7 @@ group :assets do ...@@ -108,7 +108,7 @@ group :assets do
gem "jquery-rails", "2.1.3" gem "jquery-rails", "2.1.3"
gem "jquery-ui-rails", "2.0.2" gem "jquery-ui-rails", "2.0.2"
gem "modernizr", "2.6.2" gem "modernizr", "2.6.2"
gem "raphael-rails", "1.5.2" gem "raphael-rails", git: "https://github.com/gitlabhq/raphael-rails.git"
gem 'bootstrap-sass', "2.2.1.1" gem 'bootstrap-sass', "2.2.1.1"
gem "font-awesome-sass-rails", "~> 2.0.0" gem "font-awesome-sass-rails", "~> 2.0.0"
gem "gemoji", "~> 1.2.1", require: 'emoji/railtie' gem "gemoji", "~> 1.2.1", require: 'emoji/railtie'
......
...@@ -48,6 +48,12 @@ GIT ...@@ -48,6 +48,12 @@ GIT
posix-spawn (~> 0.3.6) posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0) yajl-ruby (~> 1.1.0)
GIT
remote: https://github.com/gitlabhq/raphael-rails.git
revision: cb2c92a040b9b941a5f1aa1ea866cc26e944fe58
specs:
raphael-rails (2.1.0)
GIT GIT
remote: https://github.com/gitlabhq/resque.git remote: https://github.com/gitlabhq/resque.git
revision: 9ef4700306dd946a3ac000612428967ce0c32213 revision: 9ef4700306dd946a3ac000612428967ce0c32213
...@@ -355,7 +361,6 @@ GEM ...@@ -355,7 +361,6 @@ GEM
thor (>= 0.14.6, < 2.0) thor (>= 0.14.6, < 2.0)
raindrops (0.10.0) raindrops (0.10.0)
rake (10.0.3) rake (10.0.3)
raphael-rails (1.5.2)
rb-fsevent (0.9.2) rb-fsevent (0.9.2)
rb-inotify (0.8.8) rb-inotify (0.8.8)
ffi (>= 0.5.0) ffi (>= 0.5.0)
...@@ -525,7 +530,7 @@ DEPENDENCIES ...@@ -525,7 +530,7 @@ DEPENDENCIES
rails (= 3.2.10) rails (= 3.2.10)
rails-dev-tweaks rails-dev-tweaks
rails_best_practices rails_best_practices
raphael-rails (= 1.5.2) raphael-rails!
rb-fsevent rb-fsevent
rb-inotify rb-inotify
redcarpet (~> 2.2.2) redcarpet (~> 2.2.2)
......
...@@ -22,14 +22,16 @@ module Gitlab ...@@ -22,14 +22,16 @@ module Gitlab
h[:parents] = self.parents.collect do |p| h[:parents] = self.parents.collect do |p|
[p.id,0,0] [p.id,0,0]
end end
h[:author] = author.name h[:author] = {
name: author.name,
email: author.email
}
h[:time] = time h[:time] = time
h[:space] = space h[:space] = space
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha h[:id] = sha
h[:date] = date h[:date] = date
h[:message] = message h[:message] = message
h[:login] = author.email
h h
end end
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
if(cuday != this.days[mm][0]){ if(cuday != this.days[mm][0]){
// Dates // Dates
r.text(offsetX + mm * 20, 31, this.days[mm][0]).attr({ r.text(offsetX + mm * 20, 31, this.days[mm][0]).attr({
font: "12px Monaco, Arial", font: "12px Monaco, monospace",
fill: "#DDD" fill: "#DDD"
}); });
cuday = this.days[mm][0]; cuday = this.days[mm][0];
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
if(cumonth != this.days[mm][1]){ if(cumonth != this.days[mm][1]){
// Months // Months
r.text(offsetX + mm * 20, 11, this.days[mm][1]).attr({ r.text(offsetX + mm * 20, 11, this.days[mm][1]).attr({
font: "12px Monaco, Arial", font: "12px Monaco, monospace",
fill: "#EEE" fill: "#EEE"
}); });
cumonth = this.days[mm][1]; cumonth = this.days[mm][1];
...@@ -103,29 +103,16 @@ ...@@ -103,29 +103,16 @@
for (i = 0; i < this.commitCount; i++) { for (i = 0; i < this.commitCount; i++) {
var x = offsetX + 20 * this.commits[i].time var x = offsetX + 20 * this.commits[i].time
, y = offsetY + 20 * this.commits[i].space; , y = offsetY + 20 * this.commits[i].space
, c;
// Draw dot
r.circle(x, y, 3).attr({ r.circle(x, y, 3).attr({
fill: this.colors[this.commits[i].space], fill: this.colors[this.commits[i].space],
stroke: "none" stroke: "none"
}); });
if (this.commits[i].refs != null && this.commits[i].refs != "") {
var longrefs = this.commits[i].refs
, shortrefs = this.commits[i].refs;
if (shortrefs.length > 15){
shortrefs = shortrefs.substr(0,13) + "...";
}
var t = r.text(x+5, y+8, shortrefs).attr({
font: "12px Monaco, Arial",
fill: "#666",
title: longrefs,
cursor: "pointer",
rotation: "90"
});
var textbox = t.getBBox(); // Draw lines
t.translate(textbox.height/-4, textbox.width/2);
}
var c;
for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) { for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) {
c = this.preparedCommits[this.commits[i].parents[j][0]]; c = this.preparedCommits[this.commits[i].parents[j][0]];
if (c) { if (c) {
...@@ -155,6 +142,11 @@ ...@@ -155,6 +142,11 @@
} }
} }
} }
if (this.commits[i].refs) {
this.appendLabel(x, y, this.commits[i].refs);
}
this.appendAnchor(top, this.commits[i], x, y); this.appendAnchor(top, this.commits[i], x, y);
} }
top.toFront(); top.toFront();
...@@ -208,7 +200,57 @@ ...@@ -208,7 +200,57 @@
}); });
}; };
BranchGraph.prototype.appendAnchor = function(top, c, x, y) { BranchGraph.prototype.appendLabel = function(x, y, refs){
var r = this.raphael
, shortrefs = refs
, text, textbox, rect;
if (shortrefs.length > 17){
// Truncate if longer than 15 chars
shortrefs = shortrefs.substr(0,15) + "";
}
text = r.text(x+5, y+8 + 10, shortrefs).attr({
font: "10px Monaco, monospace",
fill: "#FFF",
title: refs
});
textbox = text.getBBox();
text.transform([
't', textbox.height/-4, textbox.width/2 + 5,
'r90'
]);
// Create rectangle based on the size of the textbox
rect = r.rect(x, y, textbox.width + 15, textbox.height + 5, 4).attr({
"fill": "#000",
"fill-opacity": .7,
"stroke": "none"
});
triangle = r.path([
'M', x, y + 5,
'L', x + 4, y + 15,
'L', x - 4, y + 15,
'Z'
]).attr({
"fill": "#000",
"fill-opacity": .7,
"stroke": "none"
});
// Rotate and reposition rectangle over text
rect.transform([
'r', 90, x, y,
't', 15, -9
]);
// Set text to front
text.toFront();
};
BranchGraph.prototype.appendAnchor = function(top, commit, x, y) {
var r = this.raphael var r = this.raphael
, options = this.options , options = this.options
, anchor; , anchor;
...@@ -218,16 +260,13 @@ ...@@ -218,16 +260,13 @@
cursor: "pointer" cursor: "pointer"
}) })
.click(function(){ .click(function(){
window.location = options.commit_url.replace('%s', c.id); window.location = options.commit_url.replace('%s', commit.id);
}) })
.hover(function(){ .hover(function(){
var text = r.text(100, 100, c.author + "\n \n" + c.id + "\n \n" + c.message).attr({ this.tooltip = r.commitTooltip(x, y + 5, commit);
fill: "#fff" top.push(this.tooltip.insertBefore(this));
});
this.popup = r.tooltip(x, y + 5, text, 0);
top.push(this.popup.insertBefore(this));
}, function(){ }, function(){
this.popup && this.popup.remove() && delete this.popup; this.tooltip && this.tooltip.remove() && delete this.tooltip;
}); });
top.push(anchor); top.push(anchor);
}; };
...@@ -235,23 +274,81 @@ ...@@ -235,23 +274,81 @@
this.BranchGraph = BranchGraph; this.BranchGraph = BranchGraph;
}(this); }(this);
Raphael.fn.tooltip = function (x, y, set, dir, size) { Raphael.fn.commitTooltip = function(x, y, commit){
dir = dir == null ? 2 : dir; var nameText, idText, messageText
size = size || 5; , boxWidth = 300
x = Math.round(x); , boxHeight = 200;
y = Math.round(y);
var mmax = Math.max nameText = this.text(x, y + 10, commit.author.name);
, bb = set.getBBox() idText = this.text(x, y + 35, commit.id);
, w = Math.round(bb.width / 2) messageText = this.text(x, y + 50, commit.message);
, h = Math.round(bb.height / 2)
, dx = [0, w + size * 2, 0, -w - size * 2] textSet = this.set(nameText, idText, messageText).attr({
, dy = [-h * 2 - size * 3, -h - size, 0, -h - size] "text-anchor": "start",
, 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, "font": "12px Monaco, monospace"
"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, });
"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,
"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, nameText.attr({
"l", -mmax(w - size, 0), 0, "z"].join(",") "font": "14px Arial",
, 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]; "font-weight": "bold"
set.translate(xy.x - w - bb.x, xy.y - h - bb.y); });
return this.set(this.path(p).attr({fill: "#234", stroke: "none"}).insertBefore(set.node ? set : set[0]), set);
idText.attr({
"fill": "#AAA"
});
textWrap(messageText, boxWidth - 50);
var rect = this.rect(x - 10, y - 10, boxWidth, 100, 4).attr({
"fill": "#FFF",
"stroke": "#000",
"stroke-linecap": "round",
"stroke-width": 2
});
var tooltip = this.set(rect, textSet);
rect.attr({
"height" : tooltip.getBBox().height + 10,
"width" : tooltip.getBBox().width + 10
});
tooltip.transform([
't', 20, 20
]);
return tooltip;
}; };
function textWrap(t, width) {
var content = t.attr("text");
var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
t.attr({
"text" : abc
});
var letterWidth = t.getBBox().width / abc.length;
t.attr({
"text" : content
});
var words = content.split(" ");
var x = 0, s = [];
for ( var i = 0; i < words.length; i++) {
var l = words[i].length;
if (x + (l * letterWidth) > width) {
s.push("\n");
x = 0;
}
x += l * letterWidth;
s.push(words[i] + " ");
}
t.attr({
"text" : s.join("")
});
var b = t.getBBox()
, h = Math.abs(b.y2) - Math.abs(b.y) + 1;
t.attr({
"y": b.y + h
});
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment