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