Mercurial > kallithea
annotate rhodecode/public/js/graph.js @ 3237:f5dd76e2a7af beta
disable file editing when not on branch head fixes issue #462
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 27 Jan 2013 00:18:49 +0100 |
parents | bd97aba292f1 |
children | 729859bd1e6a 2792019caf67 |
rev | line source |
---|---|
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 // branch_renderer.js - Rendering of branch DAGs on the client side |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 // |
322
46b7d108ea7a
made graphg ticker, and fixes a paging bug caused grapgh disaligment
Marcin Kuzminski <marcin@python-works.com>
parents:
293
diff
changeset
|
3 // Copyright 2010 Marcin Kuzminski <marcin AT python-works DOT com> |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
4 // Copyright 2008 Jesper Noehr <jesper AT noehr DOT org> |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 // |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 // derived from code written by Scott James Remnant <scott@ubuntu.com> |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 // Copyright 2005 Canonical Ltd. |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 // |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 // This software may be used and distributed according to the terms |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 // of the GNU General Public License, incorporated herein by reference. |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 var colors = [ |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 [ 1.0, 0.0, 0.0 ], |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 [ 1.0, 1.0, 0.0 ], |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 [ 0.0, 1.0, 0.0 ], |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 [ 0.0, 1.0, 1.0 ], |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 [ 0.0, 0.0, 1.0 ], |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
20 [ 1.0, 0.0, 1.0 ], |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
21 [ 1.0, 1.0, 0.0 ], |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
22 [ 0.0, 0.0, 0.0 ] |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 ]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
25 function BranchRenderer() { |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
27 this.canvas = document.getElementById("graph_canvas"); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
28 |
293
68dc70295a76
Ie graph support.
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
29 if (navigator.userAgent.indexOf('MSIE') >= 0) |
68dc70295a76
Ie graph support.
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
30 this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 this.ctx = this.canvas.getContext('2d'); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 this.ctx.strokeStyle = 'rgb(0, 0, 0)'; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 this.ctx.fillStyle = 'rgb(0, 0, 0)'; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 this.cur = [0, 0]; |
2948
bd97aba292f1
graph: thinner lines/circles
Aras Pranckevicius <aras@unity3d.com>
parents:
2924
diff
changeset
|
35 this.line_width = 2.0; |
bd97aba292f1
graph: thinner lines/circles
Aras Pranckevicius <aras@unity3d.com>
parents:
2924
diff
changeset
|
36 this.dot_radius = 3.5; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 this.setColor = function(color, bg, fg) { |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 color %= colors.length; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 var red = (colors[color][0] * fg) || bg; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 var green = (colors[color][1] * fg) || bg; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 var blue = (colors[color][2] * fg) || bg; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 red = Math.round(red * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 green = Math.round(green * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 blue = Math.round(blue * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 this.ctx.strokeStyle = s; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 this.ctx.fillStyle = s; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
51 this.render = function(data,canvasWidth,lineCount) { |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
52 var idx = 1; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
53 var rela = document.getElementById('graph'); |
2923
1ab6b1cb849a
graph: replaced some super complicated looking math with something that tries to make sense
Aras Pranckevicius <aras@unity3d.com>
parents:
2922
diff
changeset
|
54 |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
55 if (lineCount == 0) |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
56 lineCount = 1; |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
57 |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
58 var edge_pad = this.dot_radius + 2; |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
59 var box_size = Math.min(18, Math.floor((canvasWidth - edge_pad*2)/(lineCount))); |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
60 var base_x = canvasWidth - edge_pad; |
1865 | 61 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 for (var i in data) { |
1865 | 63 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
64 var row = document.getElementById("chg_"+idx); |
1880
e2b6bc77619a
graph: fix null check lost in last merge
Aras Pranckevicius <aras@unity3d.com>
parents:
1877
diff
changeset
|
65 if (row == null) |
e2b6bc77619a
graph: fix null check lost in last merge
Aras Pranckevicius <aras@unity3d.com>
parents:
1877
diff
changeset
|
66 continue; |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
67 var next = document.getElementById("chg_"+(idx+1)); |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
68 var extra = 0; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
70 cur = data[i]; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
71 node = cur[1]; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
72 in_l = cur[2]; |
1865 | 73 |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
74 var rowY = row.offsetTop + row.offsetHeight/2 - rela.offsetTop; |
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
75 var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2 - rela.offsetTop; |
1865 | 76 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
77 for (var j in in_l) { |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
79 line = in_l[j]; |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
80 start = line[0]; |
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
81 end = line[1]; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 color = line[2]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
84 this.setColor(color, 0.0, 0.65); |
1877
395a3196de73
merge upstream (keeping my graph.js changes)
Aras Pranckevicius <aras@unity3d.com>
diff
changeset
|
85 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
86 |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
87 x = base_x - box_size * start; |
1464
31ed19b1fdb9
fixed chrome DAG graph rendering issue - simplified graph.js
Marcin Kuzminski <marcin@python-works.com>
parents:
1429
diff
changeset
|
88 |
322
46b7d108ea7a
made graphg ticker, and fixes a paging bug caused grapgh disaligment
Marcin Kuzminski <marcin@python-works.com>
parents:
293
diff
changeset
|
89 this.ctx.lineWidth=this.line_width; |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
90 this.ctx.beginPath(); |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
91 this.ctx.moveTo(x, rowY); |
1464
31ed19b1fdb9
fixed chrome DAG graph rendering issue - simplified graph.js
Marcin Kuzminski <marcin@python-works.com>
parents:
1429
diff
changeset
|
92 |
1863
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
93 if (start == end) |
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
94 { |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
95 this.ctx.lineTo(x,nextY+extra,3); |
1863
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
96 } |
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
97 else |
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
98 { |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
99 var x2 = base_x - box_size * end; |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
100 var ymid = (rowY+nextY) / 2; |
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
101 this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY); |
1863
941437fdfe59
graph: bezier curve for curved merge lines
Aras Pranckevicius <aras@unity3d.com>
parents:
1852
diff
changeset
|
102 } |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
103 this.ctx.stroke(); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
106 column = node[0]; |
2923
1ab6b1cb849a
graph: replaced some super complicated looking math with something that tries to make sense
Aras Pranckevicius <aras@unity3d.com>
parents:
2922
diff
changeset
|
107 color = node[1]; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 |
322
46b7d108ea7a
made graphg ticker, and fixes a paging bug caused grapgh disaligment
Marcin Kuzminski <marcin@python-works.com>
parents:
293
diff
changeset
|
109 radius = this.dot_radius; |
1877
395a3196de73
merge upstream (keeping my graph.js changes)
Aras Pranckevicius <aras@unity3d.com>
diff
changeset
|
110 |
2924
fcbcef60be02
graph: fix counting of "heads" for graph, condense graph into more narrow lines instead of trying to increase its width (past certain width produces really bad html layout)
Aras Pranckevicius <aras@unity3d.com>
parents:
2923
diff
changeset
|
111 x = base_x - box_size * column; |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
112 |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
113 this.ctx.beginPath(); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
114 this.setColor(color, 0.25, 0.75); |
1873
cc5dc31859d4
graph: make it handle different row heights while still doing dots in the middle of each row
Aras Pranckevicius <aras@unity3d.com>
parents:
1863
diff
changeset
|
115 this.ctx.arc(x, rowY, radius, 0, Math.PI * 2, true); |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
116 this.ctx.fill(); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
118 idx++; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 } |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
120 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 } |