Mercurial > kallithea
annotate pylons_app/public/js/graph.js @ 289:1dbe02063123
graph fixes.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 23 Jun 2010 00:31:00 +0200 |
parents | ab1afe7444f3 |
children | 68dc70295a76 |
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 // |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
3 // 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
|
4 // 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
|
5 // 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
|
6 // |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 // 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
|
8 // Copyright 2005 Canonical Ltd. |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 // |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 // 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
|
11 // 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
|
12 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 var colors = [ |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 [ 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
|
15 [ 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
|
16 [ 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
|
17 [ 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
|
18 [ 0.0, 0.0, 1.0 ], |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
19 [ 1.0, 0.0, 1.0 ], |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
20 [ 1.0, 1.0, 0.0 ], |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
21 [ 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
|
22 ]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
24 function BranchRenderer() { |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
26 this.canvas = document.getElementById("graph_canvas"); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
27 |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
28 //if ($.browser.msie) |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
29 // 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
|
30 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
|
31 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
|
32 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
|
33 this.cur = [0, 0]; |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
34 this.max_column = 1; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 this.line_width = 3; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 this.bg = [0, 4]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 this.cell = [2, 0]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 this.revlink = ''; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 this.scale = function(height) { |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
41 this.box_size = Math.floor(height/1.2); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
42 this.cell_height = this.box_size; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 this.bg_height = height; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 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
|
47 color %= colors.length; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 red = Math.round(red * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 green = Math.round(green * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 blue = Math.round(blue * 255); |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 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
|
55 this.ctx.strokeStyle = s; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 this.ctx.fillStyle = s; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 this.render = function(data) { |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
60 var idx = 1; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
61 var rela = document.getElementById('graph'); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
62 var pad = 160; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
63 var scale = 20; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 for (var i in data) { |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
66 this.scale(scale); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
67 var row = document.getElementById("chg_"+idx); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
68 var next = document.getElementById("chg_"+idx+1); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
69 var extra = 0; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
71 //skip this since i don't have DATE in my app |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
72 //if (next.is('.changesets-date')) { |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
73 // extra = next.outerHeight(); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
74 //} |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
75 |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
76 |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
77 this.cell[1] += row.clientWidth; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 this.bg[1] += this.bg_height; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
80 cur = data[i]; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
81 nodeid = cur[0]; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
82 node = cur[1]; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
83 in_l = cur[2]; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
85 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
|
86 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
87 line = in_l[j]; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 start = line[0]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 end = line[1]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 color = line[2]; |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
92 if (start > this.max_column) { |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
93 this.max_column = start; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
96 if (end > this.max_column) { |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
97 this.max_column = end; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
100 this.setColor(color, 0.0, 0.65); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
101 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
103 y = row.offsetTop-rela.offsetTop+4; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
104 x = pad-((this.cell[0] + this.box_size * start - 1) + this.bg_height-2); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
105 this.ctx.beginPath(); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
106 this.ctx.moveTo(x, y); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 |
289 | 108 //i don't know why it's +1 just fixes some drawing graph. |
109 y += row.clientHeight+1; | |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
110 x = pad-((1 + this.box_size * end) + this.bg_height-2); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
111 this.ctx.lineTo(x,y+extra); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
112 this.ctx.stroke(); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 column = node[0] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 color = node[1] |
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 radius = 4; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
119 y = row.offsetTop-rela.offsetTop+4; |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
120 x = pad-(Math.round(this.cell[0] * scale/2 * column + radius) + 15 - (column*4)); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
121 |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
122 this.ctx.beginPath(); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
123 this.setColor(color, 0.25, 0.75); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
124 this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); |
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
125 this.ctx.fill(); |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
127 idx++; |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 } |
288
ab1afe7444f3
Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
129 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 } |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 } |