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