Show More
@@ -1,135 +1,122 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; |
|
|||
36 | this.line_width = 2.5; |
|
35 | this.line_width = 2.5; | |
37 | this.dot_radius = 5.5; |
|
36 | this.dot_radius = 5.5; | |
38 |
|
37 | |||
39 | this.scale = function(height) { |
|
|||
40 | this.box_size = Math.floor(height/1.2); |
|
|||
41 | } |
|
|||
42 |
|
||||
43 | this.setColor = function(color, bg, fg) { |
|
38 | this.setColor = function(color, bg, fg) { | |
44 | color %= colors.length; |
|
39 | color %= colors.length; | |
45 | var red = (colors[color][0] * fg) || bg; |
|
40 | var red = (colors[color][0] * fg) || bg; | |
46 | var green = (colors[color][1] * fg) || bg; |
|
41 | var green = (colors[color][1] * fg) || bg; | |
47 | var blue = (colors[color][2] * fg) || bg; |
|
42 | var blue = (colors[color][2] * fg) || bg; | |
48 | red = Math.round(red * 255); |
|
43 | red = Math.round(red * 255); | |
49 | green = Math.round(green * 255); |
|
44 | green = Math.round(green * 255); | |
50 | blue = Math.round(blue * 255); |
|
45 | blue = Math.round(blue * 255); | |
51 | var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; |
|
46 | var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; | |
52 | this.ctx.strokeStyle = s; |
|
47 | this.ctx.strokeStyle = s; | |
53 | this.ctx.fillStyle = s; |
|
48 | this.ctx.fillStyle = s; | |
54 | } |
|
49 | } | |
55 |
|
50 | |||
56 | this.render = function(data,width) { |
|
51 | this.render = function(data,width) { | |
57 | var idx = 1; |
|
52 | var idx = 1; | |
58 | var rela = document.getElementById('graph'); |
|
53 | var rela = document.getElementById('graph'); | |
59 | var pad = width; |
|
54 | var pad = width; | |
60 | var scale = 22; |
|
55 | var scale = 22; | |
|
56 | var box_size = Math.floor(scale/1.2); | |||
61 |
|
57 | |||
62 | for (var i in data) { |
|
58 | for (var i in data) { | |
63 | this.scale(scale); |
|
|||
64 |
|
59 | |||
65 | var row = document.getElementById("chg_"+idx); |
|
60 | var row = document.getElementById("chg_"+idx); | |
66 | if (row == null) |
|
61 | if (row == null) | |
67 | continue; |
|
62 | continue; | |
68 | var next = document.getElementById("chg_"+(idx+1)); |
|
63 | var next = document.getElementById("chg_"+(idx+1)); | |
69 | var extra = 0; |
|
64 | var extra = 0; | |
70 |
|
65 | |||
71 | cur = data[i]; |
|
66 | cur = data[i]; | |
72 | nodeid = cur[0]; |
|
67 | nodeid = cur[0]; | |
73 | node = cur[1]; |
|
68 | node = cur[1]; | |
74 | in_l = cur[2]; |
|
69 | in_l = cur[2]; | |
75 |
|
70 | |||
76 | var rowY = row.offsetTop + row.offsetHeight/2 - rela.offsetTop; |
|
71 | var rowY = row.offsetTop + row.offsetHeight/2 - rela.offsetTop; | |
77 | var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2 - rela.offsetTop; |
|
72 | var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2 - rela.offsetTop; | |
78 |
|
73 | |||
79 | for (var j in in_l) { |
|
74 | for (var j in in_l) { | |
80 |
|
75 | |||
81 | line = in_l[j]; |
|
76 | line = in_l[j]; | |
82 | start = line[0]; |
|
77 | start = line[0]; | |
83 | end = line[1]; |
|
78 | end = line[1]; | |
84 | color = line[2]; |
|
79 | color = line[2]; | |
85 |
|
80 | |||
86 | if (start > this.max_column) { |
|
|||
87 | this.max_column = start; |
|
|||
88 | } |
|
|||
89 |
|
||||
90 | if (end > this.max_column) { |
|
|||
91 | this.max_column = end; |
|
|||
92 | } |
|
|||
93 |
|
||||
94 | this.setColor(color, 0.0, 0.65); |
|
81 | this.setColor(color, 0.0, 0.65); | |
95 |
|
82 | |||
96 |
|
83 | |||
97 |
x = pad-( |
|
84 | x = pad-(box_size * start - 1 + scale); | |
98 |
|
85 | |||
99 | this.ctx.lineWidth=this.line_width; |
|
86 | this.ctx.lineWidth=this.line_width; | |
100 | this.ctx.beginPath(); |
|
87 | this.ctx.beginPath(); | |
101 | this.ctx.moveTo(x, rowY); |
|
88 | this.ctx.moveTo(x, rowY); | |
102 |
|
89 | |||
103 |
|
90 | |||
104 | if (start == end) |
|
91 | if (start == end) | |
105 | { |
|
92 | { | |
106 |
x = pad-((1 + |
|
93 | x = pad-((1 + box_size * end) + scale-2); | |
107 | this.ctx.lineTo(x,nextY+extra,3); |
|
94 | this.ctx.lineTo(x,nextY+extra,3); | |
108 | } |
|
95 | } | |
109 | else |
|
96 | else | |
110 | { |
|
97 | { | |
111 |
var x2 = pad-((1 + |
|
98 | var x2 = pad-((1 + box_size * end) + scale-2); | |
112 | var ymid = (rowY+nextY) / 2; |
|
99 | var ymid = (rowY+nextY) / 2; | |
113 | this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY); |
|
100 | this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY); | |
114 | } |
|
101 | } | |
115 | this.ctx.stroke(); |
|
102 | this.ctx.stroke(); | |
116 | } |
|
103 | } | |
117 |
|
104 | |||
118 | column = node[0] |
|
105 | column = node[0] | |
119 | color = node[1] |
|
106 | color = node[1] | |
120 |
|
107 | |||
121 | radius = this.dot_radius; |
|
108 | radius = this.dot_radius; | |
122 |
|
109 | |||
123 | x = pad-(Math.round(scale * column + radius) + 15 - (column*4)); |
|
110 | x = pad-(Math.round(scale * column + radius) + 15 - (column*4)); | |
124 |
|
111 | |||
125 | this.ctx.beginPath(); |
|
112 | this.ctx.beginPath(); | |
126 | this.setColor(color, 0.25, 0.75); |
|
113 | this.setColor(color, 0.25, 0.75); | |
127 | this.ctx.arc(x, rowY, radius, 0, Math.PI * 2, true); |
|
114 | this.ctx.arc(x, rowY, radius, 0, Math.PI * 2, true); | |
128 | this.ctx.fill(); |
|
115 | this.ctx.fill(); | |
129 |
|
116 | |||
130 | idx++; |
|
117 | idx++; | |
131 | } |
|
118 | } | |
132 |
|
119 | |||
133 | } |
|
120 | } | |
134 |
|
121 | |||
135 | } |
|
122 | } |
General Comments 0
You need to be logged in to leave comments.
Login now