##// END OF EJS Templates
js: clean-up of trailing whitespace in graph.js
Mads Kiilerich -
r5953:42d1e1ab default
parent child Browse files
Show More
@@ -1,222 +1,222 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(canvas_id, content_id, row_id_prefix) {
25 function BranchRenderer(canvas_id, content_id, row_id_prefix) {
26 // canvas_id is canvas to render into
26 // canvas_id is canvas to render into
27 // content_id's height is applied to canvas
27 // content_id's height is applied to canvas
28 // row_id_prefix is prefix that is applied to get row id's
28 // row_id_prefix is prefix that is applied to get row id's
29 this.canvas = document.getElementById(canvas_id);
29 this.canvas = document.getElementById(canvas_id);
30 var content = document.getElementById(content_id);
30 var content = document.getElementById(content_id);
31
31
32 if (!document.createElement("canvas").getContext)
32 if (!document.createElement("canvas").getContext)
33 this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
33 this.canvas = window.G_vmlCanvasManager.initElement(this.canvas);
34 if (!this.canvas) { // canvas creation did for some reason fail - fail silently
34 if (!this.canvas) { // canvas creation did for some reason fail - fail silently
35 this.render = function(data,canvasWidth) {};
35 this.render = function(data,canvasWidth) {};
36 return;
36 return;
37 }
37 }
38 this.ctx = this.canvas.getContext('2d');
38 this.ctx = this.canvas.getContext('2d');
39 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
39 this.ctx.strokeStyle = 'rgb(0, 0, 0)';
40 this.ctx.fillStyle = 'rgb(0, 0, 0)';
40 this.ctx.fillStyle = 'rgb(0, 0, 0)';
41 this.cur = [0, 0];
41 this.cur = [0, 0];
42 this.line_width = 2.0;
42 this.line_width = 2.0;
43 this.dot_radius = 3.5;
43 this.dot_radius = 3.5;
44 this.close_x = 1.5 * this.dot_radius;
44 this.close_x = 1.5 * this.dot_radius;
45 this.close_y = 0.5 * this.dot_radius;
45 this.close_y = 0.5 * this.dot_radius;
46
46
47 this.calcColor = function(color, bg, fg) {
47 this.calcColor = function(color, bg, fg) {
48 color %= colors.length;
48 color %= colors.length;
49 var red = (colors[color][0] * fg) || bg;
49 var red = (colors[color][0] * fg) || bg;
50 var green = (colors[color][1] * fg) || bg;
50 var green = (colors[color][1] * fg) || bg;
51 var blue = (colors[color][2] * fg) || bg;
51 var blue = (colors[color][2] * fg) || bg;
52 red = Math.round(red * 255);
52 red = Math.round(red * 255);
53 green = Math.round(green * 255);
53 green = Math.round(green * 255);
54 blue = Math.round(blue * 255);
54 blue = Math.round(blue * 255);
55 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
55 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
56 return s;
56 return s;
57 }
57 }
58
58
59 this.setColor = function(color, bg, fg) {
59 this.setColor = function(color, bg, fg) {
60 var s = this.calcColor(color, bg, fg);
60 var s = this.calcColor(color, bg, fg);
61 this.ctx.strokeStyle = s;
61 this.ctx.strokeStyle = s;
62 this.ctx.fillStyle = s;
62 this.ctx.fillStyle = s;
63 }
63 }
64
64
65 this.render = function(data,canvasWidth) {
65 this.render = function(data,canvasWidth) {
66 var idx = 1;
66 var idx = 1;
67
67
68 this.canvas.setAttribute('width',canvasWidth);
68 this.canvas.setAttribute('width',canvasWidth);
69 this.canvas.setAttribute('height',content.clientHeight);
69 this.canvas.setAttribute('height',content.clientHeight);
70
70
71 // HiDPI version needs to be scaled by 2x then halved via css
71 // HiDPI version needs to be scaled by 2x then halved via css
72 // Note: Firefox on OS X fails scaling if the canvas height is more than 32k
72 // Note: Firefox on OS X fails scaling if the canvas height is more than 32k
73 if (window.devicePixelRatio && content.clientHeight * window.devicePixelRatio < 32768) {
73 if (window.devicePixelRatio && content.clientHeight * window.devicePixelRatio < 32768) {
74 this.canvas.setAttribute('width', canvasWidth * window.devicePixelRatio);
74 this.canvas.setAttribute('width', canvasWidth * window.devicePixelRatio);
75 this.canvas.setAttribute('height', content.clientHeight * window.devicePixelRatio);
75 this.canvas.setAttribute('height', content.clientHeight * window.devicePixelRatio);
76 this.canvas.style.width = canvasWidth + "px";
76 this.canvas.style.width = canvasWidth + "px";
77 this.canvas.style.height = content.clientHeight + "px";
77 this.canvas.style.height = content.clientHeight + "px";
78 this.ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
78 this.ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
79 }
79 }
80
80
81 var lineCount = 1;
81 var lineCount = 1;
82 for (var i=0;i<data.length;i++) {
82 for (var i=0;i<data.length;i++) {
83 var in_l = data[i][1];
83 var in_l = data[i][1];
84 for (var j in in_l) {
84 for (var j in in_l) {
85 var m = in_l[j][0];
85 var m = in_l[j][0];
86 if (m > lineCount)
86 if (m > lineCount)
87 lineCount = m;
87 lineCount = m;
88 }
88 }
89 }
89 }
90
90
91 var edge_pad = this.dot_radius + 2;
91 var edge_pad = this.dot_radius + 2;
92 var box_size = Math.min(18, (canvasWidth - edge_pad * 2) / lineCount);
92 var box_size = Math.min(18, (canvasWidth - edge_pad * 2) / lineCount);
93 var base_x = canvasWidth - edge_pad;
93 var base_x = canvasWidth - edge_pad;
94
94
95 for (var i=0; i < data.length; ++i) {
95 for (var i=0; i < data.length; ++i) {
96 var row = document.getElementById(row_id_prefix+idx);
96 var row = document.getElementById(row_id_prefix+idx);
97 if (row == null) {
97 if (row == null) {
98 console.log("error: row "+row_id_prefix+idx+" not found");
98 console.log("error: row "+row_id_prefix+idx+" not found");
99 continue;
99 continue;
100 }
100 }
101 var next = document.getElementById(row_id_prefix+(idx+1));
101 var next = document.getElementById(row_id_prefix+(idx+1));
102 var extra = 0;
102 var extra = 0;
103
103
104 cur = data[i];
104 cur = data[i];
105 node = cur[0];
105 node = cur[0];
106 in_l = cur[1];
106 in_l = cur[1];
107 closing = cur[2];
107 closing = cur[2];
108 obsolete_node = cur[3];
108 obsolete_node = cur[3];
109
109
110 var rowY = row.offsetTop + row.offsetHeight/2;
110 var rowY = row.offsetTop + row.offsetHeight/2;
111 var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2;
111 var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2;
112
112
113 for (var j in in_l) {
113 for (var j in in_l) {
114 line = in_l[j];
114 line = in_l[j];
115 start = line[0];
115 start = line[0];
116 end = line[1];
116 end = line[1];
117 color = line[2];
117 color = line[2];
118 obsolete_line = line[3];
118 obsolete_line = line[3];
119
119
120 x = Math.floor(base_x - box_size * start);
120 x = Math.floor(base_x - box_size * start);
121
121
122 // figure out if this is a dead-end;
122 // figure out if this is a dead-end;
123 // we want to fade away this line
123 // we want to fade away this line
124 var dead_end = true;
124 var dead_end = true;
125 if (next != null) {
125 if (next != null) {
126 nextdata = data[i+1];
126 nextdata = data[i+1];
127 next_l = nextdata[1];
127 next_l = nextdata[1];
128 for (var k=0; k < next_l.length; ++k) {
128 for (var k=0; k < next_l.length; ++k) {
129 if (next_l[k][0] == end) {
129 if (next_l[k][0] == end) {
130 dead_end = false;
130 dead_end = false;
131 break;
131 break;
132 }
132 }
133 }
133 }
134 if (nextdata[0][0] == end) // this is a root - not a dead end
134 if (nextdata[0][0] == end) // this is a root - not a dead end
135 dead_end = false;
135 dead_end = false;
136 }
136 }
137
137
138 if (dead_end) {
138 if (dead_end) {
139 var gradient = this.ctx.createLinearGradient(x,rowY,x,nextY);
139 var gradient = this.ctx.createLinearGradient(x,rowY,x,nextY);
140 gradient.addColorStop(0,this.calcColor(color, 0.0, 0.65));
140 gradient.addColorStop(0,this.calcColor(color, 0.0, 0.65));
141 gradient.addColorStop(1,this.calcColor(color, 1.0, 0.0));
141 gradient.addColorStop(1,this.calcColor(color, 1.0, 0.0));
142 this.ctx.strokeStyle = gradient;
142 this.ctx.strokeStyle = gradient;
143 this.ctx.fillStyle = gradient;
143 this.ctx.fillStyle = gradient;
144 }
144 }
145 // if this is a merge of differently
145 // if this is a merge of differently
146 // colored line, make it a gradient towards
146 // colored line, make it a gradient towards
147 // the merged color
147 // the merged color
148 else if (color != node[1] && start == node[0])
148 else if (color != node[1] && start == node[0])
149 {
149 {
150 var gradient = this.ctx.createLinearGradient(x,rowY,x,nextY);
150 var gradient = this.ctx.createLinearGradient(x,rowY,x,nextY);
151 gradient.addColorStop(0,this.calcColor(node[1], 0.0, 0.65));
151 gradient.addColorStop(0,this.calcColor(node[1], 0.0, 0.65));
152 gradient.addColorStop(1,this.calcColor(color, 0.0, 0.65));
152 gradient.addColorStop(1,this.calcColor(color, 0.0, 0.65));
153 this.ctx.strokeStyle = gradient;
153 this.ctx.strokeStyle = gradient;
154 this.ctx.fillStyle = gradient;
154 this.ctx.fillStyle = gradient;
155 }
155 }
156 else
156 else
157 {
157 {
158 this.setColor(color, 0.0, 0.65);
158 this.setColor(color, 0.0, 0.65);
159 }
159 }
160
160
161 this.ctx.lineWidth=this.line_width;
161 this.ctx.lineWidth=this.line_width;
162 this.ctx.beginPath();
162 this.ctx.beginPath();
163 if (obsolete_line)
163 if (obsolete_line)
164 {
164 {
165 this.ctx.setLineDash([5]);
165 this.ctx.setLineDash([5]);
166 }
166 }
167 this.ctx.beginPath();
167 this.ctx.beginPath();
168 this.ctx.moveTo(x, rowY);
168 this.ctx.moveTo(x, rowY);
169 if (start == end)
169 if (start == end)
170 {
170 {
171 this.ctx.lineTo(x,nextY+extra,3);
171 this.ctx.lineTo(x,nextY+extra,3);
172 }
172 }
173 else
173 else
174 {
174 {
175 var x2 = Math.floor(base_x - box_size * end);
175 var x2 = Math.floor(base_x - box_size * end);
176 var ymid = (rowY+nextY) / 2;
176 var ymid = (rowY+nextY) / 2;
177 if (obsolete_node)
177 if (obsolete_node)
178 {
178 {
179 this.ctx.setLineDash([5]);
179 this.ctx.setLineDash([5]);
180 }
180 }
181 this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY);
181 this.ctx.bezierCurveTo (x,ymid,x2,ymid,x2,nextY);
182 }
182 }
183 this.ctx.stroke();
183 this.ctx.stroke();
184 this.ctx.setLineDash([]); // reset the dashed line, if any
184 this.ctx.setLineDash([]); // reset the dashed line, if any
185 }
185 }
186
186
187 column = node[0];
187 column = node[0];
188 color = node[1];
188 color = node[1];
189
189
190 x = Math.floor(base_x - box_size * column);
190 x = Math.floor(base_x - box_size * column);
191
191
192 this.setColor(color, 0.25, 0.75);
192 this.setColor(color, 0.25, 0.75);
193
193
194
194
195 r = this.dot_radius
195 r = this.dot_radius
196 if (obsolete_node)
196 if (obsolete_node)
197 {
197 {
198 this.ctx.beginPath();
198 this.ctx.beginPath();
199 this.ctx.moveTo(x - this.close_x, rowY - this.close_y - 3);
199 this.ctx.moveTo(x - this.close_x, rowY - this.close_y - 3);
200 this.ctx.lineTo(x - this.close_x + 2*this.close_x, rowY - this.close_y + 4*this.close_y - 1);
200 this.ctx.lineTo(x - this.close_x + 2*this.close_x, rowY - this.close_y + 4*this.close_y - 1);
201 this.ctx.moveTo(x - this.close_x, rowY - this.close_y + 4*this.close_y - 1);
201 this.ctx.moveTo(x - this.close_x, rowY - this.close_y + 4*this.close_y - 1);
202 this.ctx.lineTo(x - this.close_x + 2*this.close_x, rowY - this.close_y - 3);
202 this.ctx.lineTo(x - this.close_x + 2*this.close_x, rowY - this.close_y - 3);
203 this.ctx.stroke();
203 this.ctx.stroke();
204 r -= 0.5
204 r -= 0.5
205 }
205 }
206 if (closing)
206 if (closing)
207 {
207 {
208 this.ctx.fillRect(x - this.close_x, rowY - this.close_y, 2*this.close_x, 2*this.close_y);
208 this.ctx.fillRect(x - this.close_x, rowY - this.close_y, 2*this.close_x, 2*this.close_y);
209 }
209 }
210 else
210 else
211 {
211 {
212 this.ctx.beginPath();
212 this.ctx.beginPath();
213 this.ctx.arc(x, rowY, r, 0, Math.PI * 2, true);
213 this.ctx.arc(x, rowY, r, 0, Math.PI * 2, true);
214 this.ctx.fill();
214 this.ctx.fill();
215 }
215 }
216
216
217 idx++;
217 idx++;
218 }
218 }
219
219
220 }
220 }
221
221
222 }
222 }
@@ -1,25 +1,26 b''
1 #!/bin/bash -x
1 #!/bin/bash -x
2
2
3 # Enforce some consistency in whitespace - just to avoid spurious whitespaces changes
3 # Enforce some consistency in whitespace - just to avoid spurious whitespaces changes
4
4
5 files=`hg loc '*.py' '*.html' '*.css' '*.rst' '*.txt' '*.js' '*.ini' '*.cfg' CONTRIBUTORS LICENSE.md | egrep -v '/lockfiles.py|LICENSE-MERGELY.html|/codemirror/|/fontello/|(graph|mergely|native.history|select2/select2|yui.flot|yui.2.9|jquery.dataTables)\.js$'`
5 files=`hg loc '*.py' '*.html' '*.css' '*.rst' '*.txt' '*.js' '*.ini' '*.cfg' CONTRIBUTORS LICENSE.md | egrep -v '/lockfiles.py|LICENSE-MERGELY.html|/codemirror/|/fontello/|(graph|mergely|native.history|select2/select2|yui.flot|yui.2.9|jquery.dataTables)\.js$'`
6
6
7 sed -i -e "s,`printf '\t'`, ,g" $files
7 sed -i -e "s,`printf '\t'`, ,g" $files
8 sed -i -e "s, *$,,g" $files
8 sed -i -e "s, *$,,g" $files
9 sed -i -e 's,\([^ ]\)\\$,\1 \\,g' -e 's,\(["'"'"']["'"'"']["'"'"']\) \\$,\1\\,g' $files
9 sed -i -e 's,\([^ ]\)\\$,\1 \\,g' -e 's,\(["'"'"']["'"'"']["'"'"']\) \\$,\1\\,g' $files
10 # ensure one trailing newline - remove empty last line and make last line include trailing newline:
10 # ensure one trailing newline - remove empty last line and make last line include trailing newline:
11 sed -i -e '$,${/^$/d}' -e '$a\' $files
11 sed -i -e '$,${/^$/d}' -e '$a\' $files
12
12
13 sed -i -e 's,\([^ /]\){,\1 {,g' `hg loc '*.css'`
13 sed -i -e 's,\([^ /]\){,\1 {,g' `hg loc '*.css'`
14 sed -i -e 's|^\([^ /].*,\)\([^ ]\)|\1 \2|g' `hg loc '*.css'`
14 sed -i -e 's|^\([^ /].*,\)\([^ ]\)|\1 \2|g' `hg loc '*.css'`
15
15
16 sed -i -e 's/^\( [^: ]*\) *: *\([^/]\)/\1: \2/g' kallithea/public/css/{style,contextbar}.css
16 sed -i -e 's/^\( [^: ]*\) *: *\([^/]\)/\1: \2/g' kallithea/public/css/{style,contextbar}.css
17 sed -i -e '1s|, |,|g' kallithea/public/css/{style,contextbar}.css
17 sed -i -e '1s|, |,|g' kallithea/public/css/{style,contextbar}.css
18 sed -i -e 's/^\([^ ,/]\+ [^,]*[^ ,]\) *, *\(.\)/\1,\n\2/g' kallithea/public/css/{style,contextbar}.css
18 sed -i -e 's/^\([^ ,/]\+ [^,]*[^ ,]\) *, *\(.\)/\1,\n\2/g' kallithea/public/css/{style,contextbar}.css
19 sed -i -e 's/^\([^ ,/].*\) */\1 /g' kallithea/public/css/{style,contextbar}.css
19 sed -i -e 's/^\([^ ,/].*\) */\1 /g' kallithea/public/css/{style,contextbar}.css
20 sed -i -e 's,^--$,-- ,g' kallithea/templates/email_templates/main.txt
20 sed -i -e 's,^--$,-- ,g' kallithea/templates/email_templates/main.txt
21 sed -i -e 's,[ ][ ]*$,,g' -e 's, , ,g' kallithea/public/js/graph.js
21
22
22 hg mani | xargs chmod -x
23 hg mani | xargs chmod -x
23 hg loc 'set:!binary()&grep("^#!")&!(**_tmpl.py)&!(**/template**)' | xargs chmod +x
24 hg loc 'set:!binary()&grep("^#!")&!(**_tmpl.py)&!(**/template**)' | xargs chmod +x
24
25
25 hg diff
26 hg diff
General Comments 0
You need to be logged in to leave comments. Login now