Merge branch 'raphael-update' of https://github.com/koenpunt/gitlabhq into koenpunt-raphael-update

Conflicts:
	Gemfile.lock
4-1-stable
Dmitriy Zaporozhets 2013-01-05 23:17:50 +02:00
commit 47dd9e42f7
6 changed files with 160 additions and 76 deletions

View File

@ -108,7 +108,7 @@ group :assets do
gem "jquery-rails", "2.1.3"
gem "jquery-ui-rails", "2.0.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 "font-awesome-sass-rails", "~> 2.0.0"
gem "gemoji", "~> 1.2.1", require: 'emoji/railtie'

View File

@ -48,6 +48,12 @@ GIT
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
GIT
remote: https://github.com/gitlabhq/raphael-rails.git
revision: cb2c92a040b9b941a5f1aa1ea866cc26e944fe58
specs:
raphael-rails (2.1.0)
GIT
remote: https://github.com/gitlabhq/resque.git
revision: 9ef4700306dd946a3ac000612428967ce0c32213
@ -355,7 +361,6 @@ GEM
thor (>= 0.14.6, < 2.0)
raindrops (0.10.0)
rake (10.0.3)
raphael-rails (1.5.2)
rb-fsevent (0.9.2)
rb-inotify (0.8.8)
ffi (>= 0.5.0)
@ -525,7 +530,7 @@ DEPENDENCIES
rails (= 3.2.10)
rails-dev-tweaks
rails_best_practices
raphael-rails (= 1.5.2)
raphael-rails!
rb-fsevent
rb-inotify
redcarpet (~> 2.2.2)

View File

@ -22,14 +22,16 @@ module Gitlab
h[:parents] = self.parents.collect do |p|
[p.id,0,0]
end
h[:author] = author.name
h[:author] = {
name: author.name,
email: author.email
}
h[:time] = time
h[:space] = space
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha
h[:date] = date
h[:message] = message
h[:login] = author.email
h
end

View File

@ -85,7 +85,7 @@
if(cuday != this.days[mm][0]){
// Dates
r.text(offsetX + mm * 20, 31, this.days[mm][0]).attr({
font: "12px Monaco, Arial",
font: "12px Monaco, monospace",
fill: "#DDD"
});
cuday = this.days[mm][0];
@ -93,7 +93,7 @@
if(cumonth != this.days[mm][1]){
// Months
r.text(offsetX + mm * 20, 11, this.days[mm][1]).attr({
font: "12px Monaco, Arial",
font: "12px Monaco, monospace",
fill: "#EEE"
});
cumonth = this.days[mm][1];
@ -103,29 +103,16 @@
for (i = 0; i < this.commitCount; i++) {
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({
fill: this.colors[this.commits[i].space],
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();
t.translate(textbox.height/-4, textbox.width/2);
}
var c;
// Draw lines
for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) {
c = this.preparedCommits[this.commits[i].parents[j][0]];
if (c) {
@ -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);
}
top.toFront();
@ -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
, options = this.options
, anchor;
@ -218,16 +260,13 @@
cursor: "pointer"
})
.click(function(){
window.location = options.commit_url.replace('%s', c.id);
window.location = options.commit_url.replace('%s', commit.id);
})
.hover(function(){
var text = r.text(100, 100, c.author + "\n \n" + c.id + "\n \n" + c.message).attr({
fill: "#fff"
});
this.popup = r.tooltip(x, y + 5, text, 0);
top.push(this.popup.insertBefore(this));
this.tooltip = r.commitTooltip(x, y + 5, commit);
top.push(this.tooltip.insertBefore(this));
}, function(){
this.popup && this.popup.remove() && delete this.popup;
this.tooltip && this.tooltip.remove() && delete this.tooltip;
});
top.push(anchor);
};
@ -235,23 +274,81 @@
this.BranchGraph = BranchGraph;
}(this);
Raphael.fn.tooltip = function (x, y, set, dir, size) {
dir = dir == null ? 2 : dir;
size = size || 5;
x = Math.round(x);
y = Math.round(y);
var mmax = Math.max
, bb = set.getBBox()
, w = Math.round(bb.width / 2)
, h = Math.round(bb.height / 2)
, dx = [0, w + size * 2, 0, -w - size * 2]
, dy = [-h * 2 - size * 3, -h - size, 0, -h - size]
, 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,
"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,
"l", -mmax(w - size, 0), 0, "z"].join(",")
, 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];
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);
Raphael.fn.commitTooltip = function(x, y, commit){
var nameText, idText, messageText
, boxWidth = 300
, boxHeight = 200;
nameText = this.text(x, y + 10, commit.author.name);
idText = this.text(x, y + 35, commit.id);
messageText = this.text(x, y + 50, commit.message);
textSet = this.set(nameText, idText, messageText).attr({
"text-anchor": "start",
"font": "12px Monaco, monospace"
});
nameText.attr({
"font": "14px Arial",
"font-weight": "bold"
});
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
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long