|
| 1 | +var commits = chunk1.commits, |
| 2 | + comms = {}, |
| 3 | + pixelsX = [], |
| 4 | + pixelsY = [], |
| 5 | + mmax = Math.max, |
| 6 | + mtime = 0, |
| 7 | + mspace = 0, |
| 8 | + parents = {}; |
| 9 | +for (var i = 0, ii = commits.length; i < ii; i++) { |
| 10 | + for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { |
| 11 | + parents[commits[i].parents[j][0]] = true; |
| 12 | + } |
| 13 | + mtime = Math.max(mtime, commits[i].time); |
| 14 | + mspace = Math.max(mspace, commits[i].space); |
| 15 | +} |
| 16 | +mtime = mtime + 4; |
| 17 | +mspace = mspace + 10; |
| 18 | +for (i = 0; i < ii; i++) { |
| 19 | + if (commits[i].id in parents) { |
| 20 | + commits[i].isParent = true; |
| 21 | + } |
| 22 | + comms[commits[i].id] = commits[i]; |
| 23 | +} |
| 24 | +var colors = ["#000"]; |
| 25 | +for (var k = 0; k < mspace; k++) { |
| 26 | + colors.push(Raphael.getColor()); |
| 27 | +} |
| 28 | +function branchGraph(holder) { |
| 29 | + var ch = mspace * 20 + 20, cw = mtime * 20 + 20, |
| 30 | + r = Raphael("holder", cw, ch), |
| 31 | + top = r.set(); |
| 32 | + var cuday = 0, cumonth = ""; |
| 33 | + r.rect(0,0,days.length*20+20,40).attr({fill: "#999"}); |
| 34 | + |
| 35 | + for (mm = 0; mm < days.length; mm++) { |
| 36 | + if(days[mm] != null){ |
| 37 | + if(cuday != days[mm][0]){ |
| 38 | + r.text(10+mm*20,30,days[mm][0]).attr({font: "12px Fontin-Sans, Arial", fill: "#444"}); |
| 39 | + cuday = days[mm][0] |
| 40 | + } |
| 41 | + if(cumonth != days[mm][1]){ |
| 42 | + r.text(10+mm*20,10,days[mm][1]).attr({font: "12px Fontin-Sans, Arial", fill: "#444"}); |
| 43 | + cumonth = days[mm][1] |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + } |
| 48 | + for (i = 0; i < ii; i++) { |
| 49 | + var x = 10 + 20 * commits[i].time, |
| 50 | + y = 70 + 20 * commits[i].space; |
| 51 | + r.circle(x, y, 3).attr({fill: colors[commits[i].space], stroke: "none"}); |
| 52 | + if (commits[i].refs != null && commits[i].refs != "") { |
| 53 | + var longrefs = commits[i].refs |
| 54 | + var shortrefs = commits[i].refs; |
| 55 | + if (shortrefs.length > 15){ |
| 56 | + shortrefs = shortrefs.substr(0,13) + "..."; |
| 57 | + } |
| 58 | + var t = r.text(x+5,y+5,shortrefs).attr({font: "12px Fontin-Sans, Arial", fill: "#666", |
| 59 | + title: longrefs, cursor: "pointer", rotation: "90"}); |
| 60 | + |
| 61 | + var textbox = t.getBBox(); |
| 62 | + t.translate(textbox.height/-4,textbox.width/2); |
| 63 | + } |
| 64 | + for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { |
| 65 | + var c = comms[commits[i].parents[j][0]]; |
| 66 | + if (c) { |
| 67 | + var cx = 10 + 20 * c.time, |
| 68 | + cy = 70 + 20 * c.space; |
| 69 | + if (c.space == commits[i].space) { |
| 70 | + r.path("M" + (x - 5) + "," + (y + .0001) + "L" + (15 + 20 * c.time) + "," + (y + .0001)) |
| 71 | + .attr({stroke: colors[c.space], "stroke-width": 2}); |
| 72 | + |
| 73 | + } else if (c.space < commits[i].space) { |
| 74 | + r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C",x-5,y,x -17, y+2, x -20, y-10,"L", cx,y-10,cx , cy]) |
| 75 | + .attr({stroke: colors[commits[i].space], "stroke-width": 2}); |
| 76 | + } else { |
| 77 | + r.path(["M", x-5, y, "l-5-2,0,4,5,-2C",x-5,y,x -17, y-2, x -20, y+10,"L", cx,y+10,cx , cy]) |
| 78 | + .attr({stroke: colors[commits[i].space], "stroke-width": 2}); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + (function (c, x, y) { |
| 83 | + top.push(r.circle(x, y, 10).attr({fill: "#000", opacity: 0, cursor: "pointer"}) |
| 84 | + .hover(function () { |
| 85 | + var s = r.text(100, 100,c.author + "\n \n" +c.id + "\n \n" + c.message).attr({fill: "#fff"}); |
| 86 | + this.popup = r.popupit(x, y + 5, s, 0); |
| 87 | + top.push(this.popup.insertBefore(this)); |
| 88 | + }, function () { |
| 89 | + this.popup && this.popup.remove() && delete this.popup; |
| 90 | + })); |
| 91 | + }(commits[i], x, y)); |
| 92 | + } |
| 93 | + top.toFront(); |
| 94 | + var hw = holder.offsetWidth, |
| 95 | + hh = holder.offsetHeight, |
| 96 | + v = r.rect(hw - 8, 0, 4, Math.pow(hh, 2) / ch, 2).attr({fill: "#000", opacity: 0}), |
| 97 | + h = r.rect(0, hh - 8, Math.pow(hw, 2) / cw, 4, 2).attr({fill: "#000", opacity: 0}), |
| 98 | + bars = r.set(v, h), |
| 99 | + drag, |
| 100 | + dragger = function (e) { |
| 101 | + if (drag) { |
| 102 | + e = e || window.event; |
| 103 | + holder.scrollLeft = drag.sl - (e.clientX - drag.x); |
| 104 | + holder.scrollTop = drag.st - (e.clientY - drag.y); |
| 105 | + } |
| 106 | + }; |
| 107 | + holder.onmousedown = function (e) { |
| 108 | + e = e || window.event; |
| 109 | + drag = {x: e.clientX, y: e.clientY, st: holder.scrollTop, sl: holder.scrollLeft}; |
| 110 | + document.onmousemove = dragger; |
| 111 | + bars.animate({opacity: .5}, 300); |
| 112 | + }; |
| 113 | + document.onmouseup = function () { |
| 114 | + drag = false; |
| 115 | + document.onmousemove = null; |
| 116 | + bars.animate({opacity: 0}, 300); |
| 117 | + }; |
| 118 | + holder.scrollLeft = cw; |
| 119 | +}; |
| 120 | +Raphael.fn.popupit = function (x, y, set, dir, size) { |
| 121 | + dir = dir == null ? 2 : dir; |
| 122 | + size = size || 5; |
| 123 | + x = Math.round(x); |
| 124 | + y = Math.round(y); |
| 125 | + var bb = set.getBBox(), |
| 126 | + w = Math.round(bb.width / 2), |
| 127 | + h = Math.round(bb.height / 2), |
| 128 | + dx = [0, w + size * 2, 0, -w - size * 2], |
| 129 | + dy = [-h * 2 - size * 3, -h - size, 0, -h - size], |
| 130 | + 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, |
| 131 | + "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, |
| 132 | + "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, |
| 133 | + "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, |
| 134 | + "l", -mmax(w - size, 0), 0, "z"].join(","), |
| 135 | + 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]; |
| 136 | + set.translate(xy.x - w - bb.x, xy.y - h - bb.y); |
| 137 | + return this.set(this.path(p).attr({fill: "#234", stroke: "none"}).insertBefore(set.node ? set : set[0]), set); |
| 138 | +}; |
| 139 | +Raphael.fn.popup = function (x, y, text, dir, size) { |
| 140 | + dir = dir == null ? 2 : dir > 3 ? 3 : dir; |
| 141 | + size = size || 5; |
| 142 | + text = text || "$9.99"; |
| 143 | + var res = this.set(), |
| 144 | + d = 3; |
| 145 | + res.push(this.path().attr({fill: "#000", stroke: "#000"})); |
| 146 | + res.push(this.text(x, y, text).attr(this.g.txtattr).attr({fill: "#fff", "font-family": "Helvetica, Arial"})); |
| 147 | + res.update = function (X, Y, withAnimation) { |
| 148 | + X = X || x; |
| 149 | + Y = Y || y; |
| 150 | + var bb = this[1].getBBox(), |
| 151 | + w = bb.width / 2, |
| 152 | + h = bb.height / 2, |
| 153 | + dx = [0, w + size * 2, 0, -w - size * 2], |
| 154 | + dy = [-h * 2 - size * 3, -h - size, 0, -h - size], |
| 155 | + 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, |
| 156 | + "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, |
| 157 | + "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, |
| 158 | + "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, |
| 159 | + "l", -mmax(w - size, 0), 0, "z"].join(","), |
| 160 | + 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]; |
| 161 | + xy.path = p; |
| 162 | + if (withAnimation) { |
| 163 | + this.animate(xy, 500, ">"); |
| 164 | + } else { |
| 165 | + this.attr(xy); |
| 166 | + } |
| 167 | + return this; |
| 168 | + }; |
| 169 | + return res.update(x, y); |
| 170 | +}; |
0 commit comments