annotate pylons_app/public/js/graph.js @ 106:a86c8de926b4

some fixes in graph tab. Little fixes in files
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 25 Apr 2010 23:26:14 +0200
parents
children ab1afe7444f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 // 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
4 // 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
5 //
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 // 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
7 // Copyright 2005 Canonical Ltd.
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 //
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 // 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
10 // 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
11
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 var colors = [
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 [ 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
14 [ 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
15 [ 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
16 [ 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
17 [ 0.0, 0.0, 1.0 ],
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 [ 1.0, 0.0, 1.0 ]
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 ];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 function Graph() {
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 this.canvas = document.getElementById('graph');
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 if (navigator.userAgent.indexOf('MSIE') >= 0) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 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
26 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
27 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
28 this.cur = [0, 0];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 this.line_width = 3;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 this.bg = [0, 4];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 this.cell = [2, 0];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 this.columns = 0;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 this.revlink = '';
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 this.scale = function(height) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 this.bg_height = height;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 this.box_size = Math.floor(this.bg_height / 1.2);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 this.cell_height = this.box_size;
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
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 function colorPart(num) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 num *= 255
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 num = num < 0 ? 0 : num;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 num = num > 255 ? 255 : num;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 var digits = Math.round(num).toString(16);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 if (num < 16) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 return '0' + digits;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 } else {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 return digits;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 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
54
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 // Set the colour.
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 //
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 // Picks a distinct colour based on an internal wheel; the bg
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 // parameter provides the value that should be assigned to the 'zero'
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 // colours and the fg parameter provides the multiplier that should be
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 // applied to the foreground colours.
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 color %= colors.length;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 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
64 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
65 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
66 red = Math.round(red * 255);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 green = Math.round(green * 255);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 blue = Math.round(blue * 255);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 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
70 this.ctx.strokeStyle = s;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 this.ctx.fillStyle = s;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 return s;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 this.render = function(data) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 var backgrounds = '';
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 var nodedata = '';
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 for (var i in data) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 var parity = i % 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 this.cell[1] += this.bg_height;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 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
86
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 var cur = data[i];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 var node = cur[1];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 var edges = cur[2];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 var fold = false;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 for (var j in edges) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 line = edges[j];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 start = line[0];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 end = line[1];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 color = line[2];
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 if (end > this.columns || start > this.columns) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 this.columns += 1;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 if (start == this.columns && start > end) {
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 var fold = true;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 x0 = this.cell[0] + this.box_size * start + this.box_size / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 y0 = this.bg[1] - this.bg_height / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 x1 = this.cell[0] + this.box_size * end + this.box_size / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 y1 = this.bg[1] + this.bg_height / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 this.edge(x0, y0, x1, y1, color);
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
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 // Draw the revision node in the right column
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 column = node[0]
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 color = node[1]
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 radius = this.box_size / 8;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 x = this.cell[0] + this.box_size * column + this.box_size / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 y = this.bg[1] - this.bg_height / 2;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 var add = this.vertex(x, y, color, parity, cur);
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 backgrounds += add[0];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 nodedata += add[1];
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 if (fold) this.columns -= 1;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129
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 document.getElementById('nodebgs').innerHTML += backgrounds;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 document.getElementById('graphnodes').innerHTML += nodedata;
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 }
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 }