annotate pylons_app/public/hg_static/graph.js @ 50:73f413946c14

user managment implementation continued update/delete/create works + templating changes
author Marcin Kuzminski <marcin@python-blog.com>
date Thu, 08 Apr 2010 03:22:32 +0200
parents bbaab7501c1a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
1 // branch_renderer.js - Rendering of branch DAGs on the client side
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
2 //
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
3 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
4 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
5 //
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
6 // derived from code written by Scott James Remnant <scott@ubuntu.com>
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
7 // Copyright 2005 Canonical Ltd.
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
8 //
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
9 // This software may be used and distributed according to the terms
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
10 // of the GNU General Public License, incorporated herein by reference.
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
11
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
12 var colors = [
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
13 [ 1.0, 0.0, 0.0 ],
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
14 [ 1.0, 1.0, 0.0 ],
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
15 [ 0.0, 1.0, 0.0 ],
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
16 [ 0.0, 1.0, 1.0 ],
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
17 [ 0.0, 0.0, 1.0 ],
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
18 [ 1.0, 0.0, 1.0 ]
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
19 ];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
21 function Graph() {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
22
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
23 this.canvas = document.getElementById('graph');
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
24 if (navigator.userAgent.indexOf('MSIE') >= 0) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
25 this.ctx = this.canvas.getContext('2d');
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
26 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
27 this.ctx.fillStyle = 'rgb(0, 0, 0)';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
28 this.cur = [0, 0];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
29 this.line_width = 3;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
30 this.bg = [0, 4];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
31 this.cell = [2, 0];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
32 this.columns = 0;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
33 this.revlink = '';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
34
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
35 this.scale = function(height) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
36 this.bg_height = height;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
37 this.box_size = Math.floor(this.bg_height / 1.2);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
38 this.cell_height = this.box_size;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
39 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
40
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
41 function colorPart(num) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
42 num *= 255
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
43 num = num < 0 ? 0 : num;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
44 num = num > 255 ? 255 : num;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
45 var digits = Math.round(num).toString(16);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
46 if (num < 16) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
47 return '0' + digits;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
48 } else {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
49 return digits;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
50 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
51 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
52
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
53 this.setColor = function(color, bg, fg) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
54
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
55 // Set the colour.
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
56 //
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
57 // Picks a distinct colour based on an internal wheel; the bg
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
58 // parameter provides the value that should be assigned to the 'zero'
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
59 // colours and the fg parameter provides the multiplier that should be
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
60 // applied to the foreground colours.
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
61
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
62 color %= colors.length;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
63 var red = (colors[color][0] * fg) || bg;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
64 var green = (colors[color][1] * fg) || bg;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
65 var blue = (colors[color][2] * fg) || bg;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
66 red = Math.round(red * 255);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
67 green = Math.round(green * 255);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
68 blue = Math.round(blue * 255);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
69 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
70 this.ctx.strokeStyle = s;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
71 this.ctx.fillStyle = s;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
72 return s;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
73
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
74 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
75
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
76 this.render = function(data) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
77
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
78 var backgrounds = '';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
79 var nodedata = '';
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
80
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
81 for (var i in data) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
82
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
83 var parity = i % 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
84 this.cell[1] += this.bg_height;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
85 this.bg[1] += this.bg_height;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
86
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
87 var cur = data[i];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
88 var node = cur[1];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
89 var edges = cur[2];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
90 var fold = false;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
91
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
92 for (var j in edges) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
93
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
94 line = edges[j];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
95 start = line[0];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
96 end = line[1];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
97 color = line[2];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
98
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
99 if (end > this.columns || start > this.columns) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
100 this.columns += 1;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
101 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
102
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
103 if (start == this.columns && start > end) {
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
104 var fold = true;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
105 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
106
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
107 x0 = this.cell[0] + this.box_size * start + this.box_size / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
108 y0 = this.bg[1] - this.bg_height / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
109 x1 = this.cell[0] + this.box_size * end + this.box_size / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
110 y1 = this.bg[1] + this.bg_height / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
111
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
112 this.edge(x0, y0, x1, y1, color);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
113
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
114 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
115
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
116 // Draw the revision node in the right column
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
117
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
118 column = node[0]
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
119 color = node[1]
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
120
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
121 radius = this.box_size / 8;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
122 x = this.cell[0] + this.box_size * column + this.box_size / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
123 y = this.bg[1] - this.bg_height / 2;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
124 var add = this.vertex(x, y, color, parity, cur);
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
125 backgrounds += add[0];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
126 nodedata += add[1];
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
127
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
128 if (fold) this.columns -= 1;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
129
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
130 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
131
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
132 document.getElementById('nodebgs').innerHTML += backgrounds;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
133 document.getElementById('graphnodes').innerHTML += nodedata;
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
134
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
135 }
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
136
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
diff changeset
137 }