##// END OF EJS Templates
graph: remove unused stuff, simplify
Aras Pranckevicius -
r2921:58222452 beta
parent child Browse files
Show More
@@ -1,143 +1,135 b''
1 1 // branch_renderer.js - Rendering of branch DAGs on the client side
2 2 //
3 3 // Copyright 2010 Marcin Kuzminski <marcin AT python-works DOT com>
4 4 // Copyright 2008 Jesper Noehr <jesper AT noehr DOT org>
5 5 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl>
6 6 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de>
7 7 //
8 8 // derived from code written by Scott James Remnant <scott@ubuntu.com>
9 9 // Copyright 2005 Canonical Ltd.
10 10 //
11 11 // This software may be used and distributed according to the terms
12 12 // of the GNU General Public License, incorporated herein by reference.
13 13
14 14 var colors = [
15 15 [ 1.0, 0.0, 0.0 ],
16 16 [ 1.0, 1.0, 0.0 ],
17 17 [ 0.0, 1.0, 0.0 ],
18 18 [ 0.0, 1.0, 1.0 ],
19 19 [ 0.0, 0.0, 1.0 ],
20 20 [ 1.0, 0.0, 1.0 ],
21 21 [ 1.0, 1.0, 0.0 ],
22 22 [ 0.0, 0.0, 0.0 ]
23 23 ];
24 24
25 25 function BranchRenderer() {
26 26
27 27 this.canvas = document.getElementById("graph_canvas");
28 28
29 29 if (navigator.userAgent.indexOf('MSIE') >= 0)
30 30 this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
31 31 this.ctx = this.canvas.getContext('2d');
32 32 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
33 33 this.ctx.fillStyle = 'rgb(0, 0, 0)';
34 34 this.cur = [0, 0];
35 35 this.max_column = 1;
36 36 this.line_width = 2.5;
37 37 this.dot_radius = 5.5;
38 this.bg = [0, 4];
39 this.cell = [2, 0];
40 this.revlink = '';
41 38
42 39 this.scale = function(height) {
43 40 this.box_size = Math.floor(height/1.2);
44 this.cell_height = this.box_size;
45 this.bg_height = height;
46 41 }
47 42
48 43 this.setColor = function(color, bg, fg) {
49 44 color %= colors.length;
50 45 var red = (colors[color][0] * fg) || bg;
51 46 var green = (colors[color][1] * fg) || bg;
52 47 var blue = (colors[color][2] * fg) || bg;
53 48 red = Math.round(red * 255);
54 49 green = Math.round(green * 255);
55 50 blue = Math.round(blue * 255);
56 51 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
57 52 this.ctx.strokeStyle = s;
58 53 this.ctx.fillStyle = s;
59 54 }
60 55
61 this.render = function(data,pad) {
56 this.render = function(data,width) {
62 57 var idx = 1;
63 58 var rela = document.getElementById('graph');
64 var pad = pad;
59 var pad = width;
65 60 var scale = 22;
66 61
67 62 for (var i in data) {
68 63 this.scale(scale);
69 64
70 65 var row = document.getElementById("chg_"+idx);
71 66 if (row == null)
72 67 continue;
73 68 var next = document.getElementById("chg_"+(idx+1));
74 69 var extra = 0;
75 70
76 this.cell[1] += row.clientWidth;
77 this.bg[1] += this.bg_height;
78
79 71 cur = data[i];
80 72 nodeid = cur[0];
81 73 node = cur[1];
82 74 in_l = cur[2];
83 75
84 76 var rowY = row.offsetTop + row.offsetHeight/2 - rela.offsetTop;
85 77 var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2 - rela.offsetTop;
86 78
87 79 for (var j in in_l) {
88 80
89 81 line = in_l[j];
90 82 start = line[0];
91 83 end = line[1];
92 84 color = line[2];
93 85
94 86 if (start > this.max_column) {
95 87 this.max_column = start;
96 88 }
97 89
98 90 if (end > this.max_column) {
99 91 this.max_column = end;
100 92 }
101 93
102 94 this.setColor(color, 0.0, 0.65);
103 95
104 96
105 x = pad-((this.cell[0] + this.box_size * start - 1) + this.bg_height-2);
97 x = pad-(this.box_size * start - 1 + scale);
106 98
107 99 this.ctx.lineWidth=this.line_width;
108 100 this.ctx.beginPath();
109 101 this.ctx.moveTo(x, rowY);
110 102
111 103
112 104 if (start == end)
113 105 {
114 x = pad-((1 + this.box_size * end) + this.bg_height-2);
106 x = pad-((1 + this.box_size * end) + scale-2);
115 107 this.ctx.lineTo(x,nextY+extra,3);
116 108 }
117 109 else
118 110 {
119 var x2 = pad-((1 + this.box_size * end) + this.bg_height-2);
111 var x2 = pad-((1 + this.box_size * end) + scale-2);
120 112 var ymid = (rowY+nextY) / 2;
121 113 this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY);
122 114 }
123 115 this.ctx.stroke();
124 116 }
125 117
126 118 column = node[0]
127 119 color = node[1]
128 120
129 121 radius = this.dot_radius;
130 122
131 x = pad-(Math.round(this.cell[0] * scale/2 * column + radius) + 15 - (column*4));
123 x = pad-(Math.round(scale * column + radius) + 15 - (column*4));
132 124
133 125 this.ctx.beginPath();
134 126 this.setColor(color, 0.25, 0.75);
135 127 this.ctx.arc(x, rowY, radius, 0, Math.PI * 2, true);
136 128 this.ctx.fill();
137 129
138 130 idx++;
139 131 }
140 132
141 133 }
142 134
143 135 }
General Comments 0
You need to be logged in to leave comments. Login now