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