source: trunk/FACT++/www/smartfact/index.js@ 14031

Last change on this file since 14031 was 14031, checked in by tbretz, 12 years ago
Added audio support; changed order in data-file headers
File size: 41.8 KB
Line 
1"use strict";
2
3var debug = false;
4
5var codedMap = "966676:6:A;68656364626Y?\\?;A=A<AGADAN4K4i5g5h5o506W?Z?]?_?>A@A?AJAIAFACAM4J4H4f5d5e5l5m5n516X?[?^?N?P?AA1ABAVAUAKAHAEAO4L4I4G4E4c5a5b5M6j5k5V6Y6\\6_6G?J?O?Q?S?2A4A3AYAXAWAbA_AnAkAhA3404F4D4B4`5^5_5J6K6L6S6T6W6Z6]6E?H?K?M?R?T?V?5A7A6A\\A[AZAeAdAaA^AmAjAgA24o3m3C4A4?4]5[5\\5G6H6I6P6Q6R6U6X6[6^6F?I?L?<?>?U?;@=@8Ah@9AMALA]ABCACfAcA`AoAlAiA4414n3l3<4@4>425Z5X5Y5D6E6F698N6O608E8H8K8H>K>N>?>B>=???A?<@>@@@i@k@j@PAOANAECDCCC<C9CZCWCTC=3:3734313=4;4943515o4W5U5V5A6B6C6687888m7n7C8F8I8F>I>L>=>@>C>E>@?B?D??@A@C@l@n@m@SARAQAHCGCFC?C>C;C8CYCVCSC<393633303n2:4846405n4l4T5R5S5>6?6@6384858j7k7l7o7D8G8J8G>J>M>>>A>D>4>6>C?3?5?B@2@4@o@_@0ALBKBTA0CoBIC8D7D@C=C:C[CXCUC>3;3835323o2m2k27454j3m4k4i4Q5O5P5C7<6=6g71828o8h7i7S9<8?8B8Q>T>W>@=C=F=e<h<5>7>9>4?6?8?3@5@7@`@b@a@OBNBMB3C2C1C;D:D9D_D\\DQCNCKCF3C3@3>2;282Z1W1l2j2h2k3i3g3j4h4f4N5L5M5@7A7B7d7e7f7l8m8n8P9Q9:8=8@8O>R>U>>=A=D=c<f<i<k<8>:><>7?9?;?6@8@:@c@e@d@RBQBPB6C5C4C>D=D<DbDaD^D[DPCMCJCE3B3?3=2:272Y1V1T1i2g2e2h3f3d3g4e4c4K5I5J5=7>7?7a7b7c7i8j8k8M9N9O9R9;8>8A8P>S>V>?=B=E=d<g<j<Z<\\<;>k=m=:?j>l>9@i?k?f@V@g@CBBBSBgBfB7CoCnC?DSDRDcD`D]DRCOCLCG3D3A3?2<292[1X1U1S1Q1f2d2b2e3c3a3d4b4`4H5F5G5:7;7<7^7_7`7f8g8h8J9K9L97:::=:@:C:F:I:I=L=O=7=:===n<1=[<]<_<l=n=0>k>m>o>j?l?n?W@Y@X@FBEBDBjBiBhB2D1D0DVDUDTDCE@EOELEIEXEUERE5222o1l1i1f1c1`1R1P1N1c2a2_2b3`3^3a4_4]4<5:5;5778797[7\\7]7c8d8e8G9H9I94:5:8:;:>:A:D:G:G=J=M=5=8=;=l<o<2=4=^<`<b<o=1>3>n>0?2?m?o?1@Z@\\@[@IBHBGBmBlBkB5D4D3DYDXDWDFEEEBE?ENEKEHEWETEQE4212n1k1h1e1b1_1]1O1M1K1`2^2\\2_3]3[3^4\\4Z4957585475767X7Y7Z7`8a8b8D9E9F91:2:3:6:9:<:?:B:E:H:H=K=N=6=9=<=m<0=3=d;f;a<H<J<2>b=d=1?a>c>0@`?b?]@D@^@:B9BJB^B]BnBfCeC6DJDIDZDnDmDGEDEAEPEMEJEYEVESE623202m1j1g1d1a1^1\\1[0L1J1?1]2[2Y2\\3Z3X3[4Y4W4654555172737U7V7W7]8^8_8A9B9C9e9o90:n9g:j:m:L:O:R:U:X:[:];`;c;T;W;Z;7<9<e;g;i;I<K<M<c=e=g=b>d>f>a?c?e?E@G@F@=B<B;BaB`B_BiChCgCMDLDKD1E0EoD9E7E<F9F6FaE^E[EjEgEdER0O0L0I0F0C0n0l0\\0Z0X0@1>1<1Z2X2V2Y3W3U3X4V4T4E5C5D5n6o607R7S7T7Z8[8\\8>9?9@9b9c9d9l9m9e:h:k:J:M:P:S:V:Y:[;^;a;R;U;X;6<8<:<;<h;j;l;L<N<P<f=h=j=e>g>i>d?f?h?N@Q@H@@B?B>BdBcBbBlCkCjCPDODND4E3E2E;E:E8E6E;F8F5F`E]EZEiEfEcEQ0N0K0H0E0B0m0k0j0Y0W0U0=1;191W2U2S2V3T3R3U4S4Q4B5@5A5k6l6m6O7P7Q7W8X8Y8;9<9=9_9`9a9j9k9\\:_:f:i:l:K:N:Q:T:W:Z:\\;_;b;S;V;Y;C<E<G<<<m;k;1<2<O<Q<S<i=[=P=h>X>Z>g?M@O@R@U@S@J@I@AB1B0BeBTB\\CmCAD@DQDiDhD5EdD<E4F2F0F=F:F7FbE_E\\EkEhEeES0P0M0J0G0D011o0h0g0e0V0T0`0:181Q2T2R2H2S3Q3P3R4P4K3?5=5>5c6i6j6h6M7N7L7U8V8T899:9W9]9^9\\9g9h9i9]:`:c:5;2;o:>;;;8;P;M;J;G;D;A;?<A<D<F<=<><n;o;3<5<R<T<Y=Z=Q=R=Y>[>\\>^>P@T@L@K@5B4B3B2BVBUB^C]CCDBDkDjDfDeD>E=E3F1FnElE@FCFFFIFLFOF;0>0A0205080513101i0f0d0c0b0_0I1H1D1P2O2G2F2D2O3N3M3J3H3a6b6e6f6g6I7J7K7R8S8397989V9Y9Z9[9f9^:a:d:4;1;n:=;:;7;O;L;I;F;C;@;@<B<0<4<U<V<X<`=]=\\=S=U=W=]>_>`>8B7B6BZBXBWB_CaC`CFDEDDDlDgDoEmE>FAFDFGFJFMF90<0?0003060714121a0^0]0G1C1B1N2L2E2C2B2@2L3I3`6d6E7F7G7H7O8Q8192969T9U9X96;3;0;?;<;9;Q;N;K;H;E;B;W<Y<^=_=a=T=V=X=\\B[BYBdCcCbCHDGD?FBFEFHFKFNF:0=0@0104070F1E1A1M2K2J2I2A2D7L8M8N8P809495961b:";
6var map = new Array(1440);
7
8function $(id) { return document.getElementById(id); }
9function $new(name) { return document.createElement(name); }
10function $txt(txt) { return document.createTextNode(txt); }
11function trim(str) { return str.replace(/^\s\s*/, "").replace(/\s*\s$/, ""); }
12function valid(str) { if (!str) return false; if (str.length==0) return false; return true;}
13function isSliding() { var z = $("body").visiblePage/*getAttribute("data-visible")*/; return $("table"+z) ? $("table"+z).offsetLeft!=0 : false; }
14function htmlDecode(input) { var e = $new('div'); e.innerHTML = input; return e.firstChild ? e.firstChild.nodeValue : input; }
15function setUTC(el, time) { var str = time.toUTCString(); var utc = str.substr(str.length-12, 8); el.innerHTML = "&#8226;&nbsp;"+utc+"&nbsp;UTC&nbsp;&#8226;"; }
16
17function cycleCol(el)
18{
19 var col = el.dotColor;//el.getAttribute("data-color");
20 col++;
21 col %= 31;
22 el.dotColor = col; //setAttribute("data-color", col);
23 if (col>16)
24 col = 31-col;
25 var hex = col.toString(16);
26 el.style.color = "#"+hex+"0"+hex+"0"+hex+"f";
27}
28
29function onload()
30{
31 try { var dummy = new XMLHttpRequest(); }
32 catch(e)
33 {
34 // FIXME: Add a message to the body.
35 alert("Your browser doesn't support dynamic reload.");
36 return;
37 }
38
39 var name = location.hash.length==0 ? "fact" : location.hash.substr(1);
40
41 var args = location.search.substr(1).split('&');
42
43 for (var i=0; i<args.length; i++)
44 {
45 switch (args[i])
46 {
47 //case "max": $("body").setAttribute("data-max", "yes"); continue;
48 //case "noslide": $("body").setAttribute("data-noslide", "yes"); continue;
49 case "max": $("body").displayMax = true; continue;
50 case "noslide": $("body").displayNoslide = true; continue;
51 case "sound": $("body").sound = true; continue;
52 }
53
54 var entry = args[i].split('=');
55 if (entry.length!=2)
56 continue;
57
58 switch (entry[0])
59 {
60 case "w": $("body").displayFixedWidth = entry[1]; break; //setAttribute("data-width", entry[1]); break;
61 case "h": $("body").displayFixedHeight = entry[1]; break; //setAttribute("data-height", entry[1]); break;
62 }
63 }
64
65 $("audio").date = new Date();
66
67
68 /*
69 alert("0 -- "+navigator.appCodeName+"\n"+
70 "1 -- "+navigator.appName+"\n"+
71 "2 -- "+navigator.appVersion+"\n"+
72 "3 -- "+navigator.platform+"\n"+
73 "4 -- "+navigator.userAgent);
74 */
75 loadPage(name, 0, 0);
76}
77
78function onresize()
79{
80 var z = $("body").visiblePage/*getAttribute("data-visible")*/;
81
82 //$("table"+z).style.width="100%";
83 $("image"+z).style.width="1px";
84 $("canvas"+z).width=1;
85
86 doresize(z);
87
88}
89
90function loadPage(name, z, dz)
91{
92 if (isSliding())
93 return;
94
95 var xmlPage = new XMLHttpRequest();
96 xmlPage.open('POST', "struct/"+name+'.page', true);
97 xmlPage.onload = function ()
98 {
99 if (xmlPage.status!=200)
100 {
101 alert("ERROR[0] - HTTP request '"+name+".page': "+xmlPage.statusText+" ["+xmlPage.status+"]");
102 //setTimeout("loadPage('+name+')", 5000);
103 /****** invalidate ******/
104 return;
105 }
106
107 if (!isSliding())
108 {
109 buildPage(name, xmlPage.responseText, z, dz);
110 changePage(z, z+dz);
111 }
112
113 //changePage(name, xmlHttp.resposeText);
114 //slideOut(name, xmlHttp.responseText);
115 //displayPage(name, xmlHttp.responseText);
116 //onresize(true);
117 };
118
119 xmlPage.send(null);
120
121 location.hash = name;
122}
123
124function sendCommand(command)
125{
126 var debug = false;
127
128 var uri = "index.php?";
129 if (debug==true)
130 uri += "debug&";
131 uri += command;
132
133 var xmlCmd = new XMLHttpRequest();
134 xmlCmd.open('POST', uri, true);
135 xmlCmd.onload = function ()
136 {
137 if (xmlCmd.status!=200)
138 {
139 alert("ERROR[1] - HTTP request: "+xmlCmd.statusText+" ["+xmlCmd.status+"]");
140 return;
141 }
142
143 if (xmlCmd.responseText.length==0)
144 {
145 alert("No proper acknowledgment of command execution received.");
146 return;
147 }
148
149 var txt = xmlCmd.responseText.split('\n');
150 switch (txt[0])
151 {
152 case "1": alert("dimctrl unreachable."); break;
153 case "2": /*success*/ break;
154 default: alert("Return code '"+txt[0]+"' unknown."); break;
155 }
156 if (txt.length>1)
157 alert(xmlCmd.responseText);
158 };
159 xmlCmd.send(null);
160}
161
162
163function submit(script)
164{
165 var inputs = document.getElementsByTagName("input");
166
167 var args = "start="+script+".dim";
168 for (var i=0; i<inputs.length; i++)
169 args += "&"+inputs[i].name+"="+inputs[i].value;
170
171 var selects = document.getElementsByTagName("select");
172 for (var i=0; i<selects.length; i++)
173 args += "&"+selects[i].name+"="+selects[i].value;
174
175 sendCommand(args);
176}
177
178function buildPage(name, text, oldz, dz)
179{
180 var fname = dz==0 ? "fact" : $("table"+oldz).pageName;//getAttribute("data-file");
181
182 var z = oldz + dz;
183
184 var lines = text.split('\n');
185
186 if (lines.length==0)
187 {
188 alert("buildPage - received data empty.");
189 return;
190 }
191
192 if (lines[0].length==0)
193 {
194 alert("buildPage - title missing");
195 return;
196 }
197
198 var title = lines[0];
199 var is_cmd = title[0]=='*';
200 if (is_cmd)
201 title = title.substr(1);
202
203 // ==================================================================
204
205 var th = $new("thead");
206 th.colSpan = 3;
207 th.width = "100%";
208
209 var htr = $new("tr");
210 th.appendChild(htr);
211
212 var htd = $new("td");
213 htd.setAttribute("class", "thead");
214 htd.colSpan = 3;
215 htd.width = "100%";
216 htr.appendChild(htd);
217
218 // -------------
219
220 var htab = $new("table");
221 htab.width = "100%";
222 htd.appendChild(htab);
223
224 var hhtr = $new("tr");
225 htab.appendChild(hhtr);
226
227 var htd0 = $new("td");
228 var htd1 = $new("td");
229 var htd2 = $new("td");
230 var htd3 = $new("td");
231 var htd4 = $new("td");
232 var htd5 = $new("td");
233 htd0.setAttribute("class", "tcell1");
234 htd1.setAttribute("class", "tcell2");
235 htd2.setAttribute("class", "tcell1");
236 htd2.setAttribute("width", "1px");
237 htd3.setAttribute("class", "tcell1");
238 htd3.setAttribute("width", "1px");
239 htd4.setAttribute("width", "1px");
240 htd5.setAttribute("width", "1px");
241 hhtr.appendChild(htd4);
242 hhtr.appendChild(htd3);
243 hhtr.appendChild(htd0);
244 hhtr.appendChild(htd1);
245 hhtr.appendChild(htd2);
246 hhtr.appendChild(htd5);
247
248 var div1 = $new("div");
249 var div2 = $new("div");
250 var div3 = $new("div");
251 var div4 = $new("div");
252 var div5 = $new("div");
253 div4.id = "warn"+z;
254 div5.id = "speaker"+z;
255 div2.setAttribute("class", "icon_white");
256 div4.setAttribute("class", "icon_color");
257 div5.setAttribute("class", "icon_color");
258 div2.setAttribute("style", "background-position:-396px 50%;");
259 div4.setAttribute("style", "background-position:-12px -12px;display:none;");
260 div5.setAttribute("style", "background-position:-189px -57px;");
261 div2.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage(fname, z, -dz); };
262 div4.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('error', z, +1); };
263
264 if (name=="fact")
265 {
266 div3.setAttribute("class", "icon_color");
267 div3.setAttribute("style", "background-position:-58px -146px;");
268 }
269 else
270 {
271 div3.setAttribute("class", "icon_white");
272 div3.setAttribute("style", "background-position:-575px 50%;");
273 div3.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('fact', z, -1); };
274 }
275
276 var sp0 = $new("span");
277 var sp1 = $new("span");
278 var sp2 = $new("span");
279 sp0.id = "ldot" +z;
280 sp1.id = "title"+z;
281 sp2.id = "rdot" +z;
282 sp1.setAttribute("style", "font-size:large;");
283 //sp0.setAttribute("data-color", "3");
284 //sp2.setAttribute("data-color", "3");
285 sp0.dotColor = 3;
286 sp2.dotColor = 3;
287 sp0.appendChild($txt(" \u2022 "));
288 sp1.appendChild($txt(title));
289 sp2.appendChild($txt(" \u2022 "));
290 if (is_cmd)
291 {
292 sp1.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; submit(name); this.style.backgroundColor=''; };
293 }
294 else
295 {
296 if (name!='control')
297 sp1.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.15)'; loadPage('control', z, +1); };
298 }
299
300 div1.setAttribute("style", "font-size:small;");
301 div1.id = "reporttime"+z;
302 div1.appendChild($txt("---"));
303
304 div1.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; sendCommand('stop'); this.style.backgroundColor=''; };
305
306 htd0.appendChild(sp0);
307 htd0.appendChild(sp1);
308 htd0.appendChild(sp2);
309
310 htd1.appendChild(div1);
311 if (dz!=0/* && z+dz!=0*/)
312 htd2.appendChild(div2); // back
313 htd3.appendChild(div3); // home
314 htd4.appendChild(div4); // Warning
315 htd5.appendChild(div5); // Warning
316
317 // ==================================================================
318
319 var tf = $new("tfoot");
320
321 var ftr = $new("tr");
322 tf.appendChild(ftr);
323
324 var ftd = $new("td");
325 ftd.setAttribute("class", "tfoot");
326 ftd.width = "100%";
327 ftd.colSpan = 3;
328 ftr.appendChild(ftd);
329
330 var ftab = $new("table");
331 ftab.width = "100%";
332 ftd.appendChild(ftab);
333
334 var ftdH = $new("td");
335 var ftd0 = $new("td");
336 var ftd1 = $new("td");
337 var ftd2 = $new("td");
338 var ftd3 = $new("td");
339 var ftd4 = $new("td");
340 ftdH.setAttribute("width", "1px");
341 ftd2.setAttribute("width", "1px");
342 ftd3.setAttribute("width", "1px");
343 ftd4.setAttribute("width", "1px");
344
345 ftdH.setAttribute("class", "tcell1");
346 ftd0.setAttribute("class", "tcell1");
347 ftd1.setAttribute("class", "tcell2");
348 ftd2.setAttribute("class", "tcell2");
349 ftd3.setAttribute("class", "tcell2");
350 ftd4.setAttribute("class", "tcell2");
351
352 ftab.appendChild(ftdH);
353 ftab.appendChild(ftd0);
354 ftab.appendChild(ftd1);
355 ftab.appendChild(ftd2);
356 ftab.appendChild(ftd3);
357 ftab.appendChild(ftd4);
358
359 var fdivH = $new("div");
360 var fdiv0 = $new("span");
361 var fdiv1 = $new("span");
362 var fdiv2 = $new("div");
363 var fdiv3 = $new("div");
364 var fdiv4 = $new("div");
365 ftd0.style.paddingLeft = "5px";
366 fdiv4.id="cmd"+z;
367
368 fdiv2.setAttribute("class", "icon_white");
369 fdiv3.setAttribute("class", "icon_white");
370 fdiv4.setAttribute("class", "icon_white");
371 fdiv2.setAttribute("style", "background-position:-72px 50%;");
372 fdiv4.setAttribute("style", "background-position:-432px 50%;");
373 fdiv2.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; sendCommand('stop'); this.style.backgroundColor=''; };
374 if (is_cmd)
375 {
376 fdiv3.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; submit(name); this.style.backgroundColor=''; };
377 fdiv3.setAttribute("style", "background-position:-109px 50%;");
378 }
379 else
380 {
381 fdiv3.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('control', z, +1); };
382 fdiv3.setAttribute("style", "background-position:-288px 50%;");
383 }
384
385 if (name.substr(0, 5)=="help-")
386 {
387 fdivH.setAttribute("class", "icon_color");
388 fdivH.setAttribute("style", "background-position:-408px -57px;");
389 //fdivH.setAttribute("style", "background-position:-13px -57px;");
390 }
391 else
392 {
393 fdivH.setAttribute("class", "icon_white");
394 fdivH.setAttribute("style", "background-position:-611px 50%;");
395 fdivH.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('help-'+name, z, +1); };
396 }
397 fdiv4.onclick = function () { this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('scriptlog', z, +1); };
398
399
400 fdiv0.setAttribute("style", "font-size:large;");
401 fdiv1.setAttribute("style", "font-size:small;");
402 fdiv1.id = "localtime"+z;
403
404 fdiv0.appendChild($txt("logbook"));
405 fdiv1.appendChild($txt("loading..."));
406
407 ftdH.appendChild(fdivH);
408 ftd0.appendChild(fdiv0);
409 ftd1.appendChild(fdiv1);
410 ftd2.appendChild(fdiv2);
411 if (name!='control')
412 ftd3.appendChild(fdiv3);
413 if (name!='scriptlog')
414 ftd4.appendChild(fdiv4);
415
416 // ==================================================================
417
418 var tbody = $new("tbody");
419
420 for (var i=0; i<lines.length; i++)
421 {
422 lines[i] = trim(lines[i]);
423
424 if (lines[i][0] == '#')
425 lines.splice(i--, 1);
426 }
427
428 // Concatenate consecutive lines until they have at least two colons
429 for (var i=2; i<lines.length; i++)
430 {
431 if (lines[i].length==0)
432 continue;
433
434 while (i<lines.length)
435 {
436 var cols = lines[i-1].split('|');
437 if (cols.length>=3)
438 break;
439
440 lines[i-1] += lines[i].length==0 ? '<p/>' : " "+lines[i];
441 lines.splice(i,1);
442 }
443 }
444
445 var counter = 1;
446 for (var i=1; i<lines.length; i++)
447 {
448 lines[i] = trim(lines[i]);
449
450 if (lines[i].length==0)
451 continue;
452
453 var cols = lines[i].split('|');
454 if (cols.length != 3 && cols.length !=4)
455 {
456 alert("Wrong number of columns in line #"+i+" in '"+name+"': '"+lines[i]+"' N(cols)="+cols.length);
457 continue;
458 }
459
460 var check = cols[1].split("=");
461
462 if (check.length>1 && (check[0]=="camera" || check[0]=="hist"))
463 {
464 var data = cols[1].substring(check[0].length+1).split("/");
465
466 var tr = $new("tr");
467 tr.setAttribute("class", "row");
468 //tr.setAttribute("style", "margin:0;padding:0;");
469
470 var td = $new("td");
471 td.setAttribute("class", "container");
472 td.id = "container";
473 td.colSpan = 3;
474 tr.appendChild(td);
475
476 var canv = $new("canvas");
477 canv.id = "canvas"+z;
478 canv.width = "1";
479 canv.height = "1";
480 //canv.onclick = function () { save(); }
481 //canv.setAttribute("data-type", check[0]);
482 //canv.setAttribute("data-file", data[0]);
483 //canv.setAttribute("data-data", cols[1].substring(check[0].length+data[0].length+2));
484 canv.dataType = check[0];
485 canv.fileName = data[0];
486 canv.dataUnit = htmlDecode(cols[1].substring(check[0].length+data[0].length+2));
487// canv.setAttribute("style", "display:none;");
488 td.appendChild(canv);
489
490 var img = $new("img");
491 img.src = "img/dummy.png";//needed in firefox
492 img.id = "image"+z;
493 img.setAttribute("style", "width:1px;height:1px;display:none;");
494 td.appendChild(img);
495
496 tbody.appendChild(tr);
497 continue;
498 }
499
500 var tr = $new("tr");
501 tr.setAttribute("class", "row");
502
503 if (valid(cols[0]))
504 {
505 tr.linkName = cols[0];
506 tr.onclick = function () { this.style.background='#ccb'; loadPage(this.linkName, z, -1); };
507 }
508
509 if (valid(cols[3]))
510 {
511 tr.linkName = cols[3];
512 tr.onclick = function () { this.style.background='#cbb'; loadPage(this.linkName, z, +1); };
513 }
514
515 var td0 = $new("td");
516 td0.setAttribute("class", "tcol0");
517 tr.appendChild(td0);
518
519 if (check.length>0 && check[0]=="image")
520 {
521 var img = $new("img");
522 img.style.width="100%";
523 img.style.display="block";
524 img.src = "img/"+check[1];
525 td0.style.paddingLeft=0;
526 td0.style.border=0;
527 td0.colSpan=3;
528 td0.appendChild(img);
529
530 tbody.appendChild(tr);
531 continue;
532 }
533
534 if (valid(cols[0]))
535 {
536 var sp = $new("div");
537 sp.setAttribute("class", "icon_black");
538 sp.setAttribute("style", "background-position: -144px 50%;");
539 td0.appendChild(sp);
540 }
541
542 var td1 = $new("td");
543 td1.setAttribute("class", "tcol1");
544 td1.width = "100%";
545 tr.appendChild(td1);
546
547 var td2 = $new("td");
548 td2.setAttribute("class", "tcol2");
549 td2.width = "18px";
550
551 if (valid(cols[3]))
552 {
553 var sp = $new("div");
554 sp.setAttribute("class", "icon_black");
555 sp.setAttribute("style", "background-position: -108px 50%;");
556 td2.appendChild(sp);
557 }
558 tr.appendChild(td2);
559
560 var tab = $new("table");
561 tab.width = "100%";
562 td1.appendChild(tab);
563
564 var innertr = $new("tr");
565 tab.appendChild(innertr);
566
567 var cell1 = $new("td");
568 cell1.setAttribute("class", "tcell1");
569
570 var cell2 = $new("td");
571 cell2.setAttribute("class", valid(cols[1]) ? "tcell2" : "tcell2l");
572
573 if (check.length>0 && check[0]=="select")
574 {
575 var args = check[1].split('/');
576
577 if (args.length<2)
578 alert("Argument name missing for'"+check[1]+"'");
579 else
580 {
581 var div = $new("div");
582 div.innerHTML = args[0];
583 cell1.appendChild(div);
584
585 var input = $new("SELECT");
586 input.name = args[1];
587 for (var j=2; j<args.length; j++)
588 input.options.add(new Option(args[j]));
589 cell2.appendChild(input);
590 }
591
592 }
593 if (check.length>0 && check[0]=="input")
594 {
595 var opt = check[1].split('/');
596
597 if (opt.length<2)
598 alert("Argument name missing for'"+check[1]+"'");
599 else
600 {
601 var div = $new("div");
602 div.innerHTML = opt[0];
603 cell1.appendChild(div);
604
605 var input = $new("input");
606 input.name = opt[1];
607 input.type = "text";
608 input.maxlength = 80;
609 input.style.textAlign = "right";
610 if (opt.length>2)
611 input.value=opt[2];
612
613 cell2.appendChild(input);
614 }
615 }
616 if (check.length==0 || (check[0]!="input" && check[0]!="select"))
617 {
618 var div = $new("div");
619 div.innerHTML = cols[1];
620 cell1.appendChild(div);
621
622 if (cols.length>2 && cols[2].length>0)
623 {
624 cell2.id = "data"+z+"-"+counter;
625 cell2.dataFormat = cols[2];
626 cell2.appendChild($txt("---"));
627 counter++;
628 }
629 else
630 cell1.setAttribute("class", "description");
631 }
632
633 innertr.appendChild(cell1);
634 innertr.appendChild(cell2);
635
636 tbody.appendChild(tr);
637 }
638
639 // ==================================================================
640
641 if (debug == true)
642 {
643 tr = $new("tr");
644 tr.setAttribute("class", "row");
645
646 td = $new("td");
647 td.id = "debug"+z;
648 td.colSpan = 3;
649 tr.appendChild(td);
650
651 tbody.appendChild(tr);
652 }
653
654 // ==================================================================
655
656 var table = $("table"+z);
657 if (table)
658 $("body").removeChild(table);
659
660 table = $new("table");
661 table.id = "table"+z;
662 table.border = 0;
663 table.cellSpacing = 0;
664 table.cellPadding = "0px";
665 //table.setAttribute("style", "overflow:hidden;position:fixed;top:0px;left:"+window.innerWidth+"px;")
666 table.setAttribute("style",
667 "position:fixed;width:100%;top:0px;"+
668 "left:"+window.innerWidth+"px;");
669
670 table.appendChild(th);
671 table.appendChild(tbody);
672 table.appendChild(tf);
673
674 // ==================================================================
675 /*
676 var audio = $new("AUDIO");
677
678 audio.autoplay = true;
679 audio.date = new Date();
680 audio.id = "audio"+z;
681
682 var ogg = $new("SOURCE");
683 var mp3 = $new("SOURCE");
684 audio.appendChild(ogg);
685 audio.appendChild(mp3);
686
687 $("body").appendChild(audio);
688 */
689
690 $("body").appendChild(table);
691
692 // ==================================================================
693
694 /*
695 // Scrollbar for just the body
696 table.style.position = "fixed";
697 th.style.position = "aboslute";
698 tf.style.position = "aboslute";
699 tbody.style.overflowY = "auto";
700 tbody.style.display = "block";
701 tbody.style.height = (window.innerHeight-th.clientHeight-tf.clientHeight)+"px";
702 tbody.id = "tbody"+z;
703 th.id = "thead"+z;
704 tf.id = "tfoot"+z;
705 */
706
707 // ==================================================================
708
709 table.pageName = name;//setAttribute("data-file", name);
710 doresize(z);
711}
712
713function doresize(z)
714{
715 var img = $("image"+z);
716 var canv = $("canvas"+z);
717 if (!img || !canv)
718 return;
719
720 var h = $("table"+z).offsetHeight;
721 if (h == 0)
722 return;
723
724 // ===========================================
725 /*
726 var tb = $("tbody"+z);
727 var hw = $("thead"+z).clientHeight;
728 var fw = $("tfoot"+z).clientHeight;
729
730 tb.style.height = (window.innerHeight-hw-fw)+"px";
731 */
732 // ===========================================
733
734 var fixedw = $("body").displayFixedWidth;//getAttribute("data-width");
735 var fixedh = $("body").displayFixedHeight;//getAttribute("data-height");
736
737 var W = fixedw>0 ? fixedw : window.innerWidth;
738 var H = fixedh>0 ? fixedh : window.innerHeight;
739
740 //var max = $("body").getAttribute("data-max")=="yes";
741 var max = $("body").displayMax;
742
743 var ih = max ? W : H - h + parseInt(img.style.height, 10);
744
745 // This might create the scroll bar
746 img.style.height = ih+"px";
747 canv.height = ih;
748
749 // now we can evaluate the correct view-port
750 // (-2 is the border size of the parent element 'container')
751 //var sW = (fixedw ? fixedw : $("table"+z).scrollWidth)-2;
752 var sW = fixedw ? fixedw : canv.parentNode.clientWidth;
753
754 img.style.width = sW+"px";
755 canv.width = sW;
756
757 // ------ debug -----
758 if (debug == true)
759 {
760 $('debug'+z).innerHTML = "";
761 $('debug'+z).innerHTML += "|W="+W +"/"+H;
762 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
763 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
764 }
765}
766
767var intervalSlide = null;
768
769function changePage(oldz, newz)
770{
771 // No page displayed yet
772 if (oldz==newz)
773 {
774 $("table"+newz).style.left="0px";
775 $("body").visiblePage = newz; //.setAttribute("data-visible", newz);
776
777 doresize(0);
778
779 //setInterval(refresh_text, 1000);
780 //setInterval(refresh_graphics, 5000);
781
782 refresh_text();
783
784 // first: decode the pixel mapping!
785 var sum = 1036080;
786 for (var i=0; i<1440; i++)
787 {
788 var d0 = codedMap.charCodeAt(i*2) -48;
789 var d1 = codedMap.charCodeAt(i*2+1)-48;
790
791 map[i] = d0 | (d1<<6);
792 sum -= map[i];
793 }
794 if (sum!=0)
795 alert("Pixel mapping table corrupted!");
796
797 refresh_graphics();
798 return;
799 }
800
801 var W = window.innerWidth;
802 if (W==0 || $("body").displayNoslide)//$("body").getAttribute("data-noslide")=="yes")
803 {
804 $("body").visiblePage = newz;//setAttribute("data-visible", newz);
805 $("body").removeChild($("table"+oldz));
806 $("table"+newz).style.left="0px";
807 return;
808 }
809
810 if (newz>oldz)
811 $("table"+newz).style.left = W+"px";
812 else
813 $("table"+newz).style.left = (-W-1)+"px";
814
815 $("body").visiblePage = newz;//setAttribute("data-visible", newz);
816
817 // This is needed on my mobile to ensure that te browser
818 // doesn't try to zoom during shifting
819 $("table"+newz).style.position="fixed";
820 $("table"+oldz).style.position="fixed";
821
822 intervalSlide = setInterval(function (){doShift(oldz,newz);}, 75);
823}
824
825function doShift(oldz, newz)
826{
827 var t0 = $("table"+oldz);
828 var t1 = $("table"+newz);
829
830 if (t0.style.display=="none")
831 {
832 clearInterval(intervalSlide);
833 $("body").removeChild(t0);
834
835 t1.style.position="absolute";
836
837 // Now the scroll bar might have to appear or disappear
838 doresize(newz);
839 return;
840 }
841
842 var x0 = t0.offsetLeft;
843 var x1 = t1.offsetLeft;
844
845 var W = window.innerWidth;
846
847 if (newz<oldz)
848 {
849 x0 += W/5;
850 x1 += W/5;
851 }
852
853 if (newz>oldz)
854 {
855 x0 -= W/5;
856 x1 -= W/5;
857 }
858
859 if ((newz<oldz && x1>=0) || (newz>oldz && x1<=0))
860 {
861 t0.style.display="none";
862 x1 = 0;
863 }
864
865 t0.style.left = x0+"px";
866 t1.style.left = x1+"px";
867}
868
869var timeoutText = null;
870var timeoutGraphics = null;
871
872function refresh_text()
873{
874 var z=$("body").visiblePage;//getAttribute("data-visible");
875
876 var fname = $("table"+z).pageName;//getAttribute("data-file");
877
878 var is_help = fname.substr(0,5)=="help-";
879
880 // Is sliding, no file defined or just help text?
881 if (isSliding() || !valid(fname) || is_help)
882 {
883 if (is_help)
884 {
885 setUTC($("localtime"+z), new Date());
886 $("reporttime"+z).innerHTML="";
887 }
888
889 // invalidate?
890 timeoutText = setTimeout(refresh_text, 1000);
891 return;
892 }
893
894 var xmlText = new XMLHttpRequest();
895 xmlText.open('POST', "data/"+fname+'.data', true);
896 xmlText.onload = function ()
897 {
898 if (xmlText.status!=200)
899 {
900 alert("ERROR[1] - HTTP request '"+fname+".data': "+xmlText.statusText+" ["+xmlText.status+"]");
901 timeoutText = setTimeout(refresh_text, 10000);
902 return;
903 }
904
905 if (!isSliding())
906 {
907 cycleCol($("ldot"+z));
908 update_text(fname, xmlText.responseText);
909 }
910 timeoutText = setTimeout(refresh_text, 3000);
911 };
912 xmlText.send(null);
913}
914
915var date0 = null;
916
917var test = 0;
918function update_text(fname, result)
919{
920 var z=$("body").visiblePage;//getAttribute("data-visible");
921 var table = $("table"+z);
922
923 if (table.pageName/*getAttribute("data-file")*/ != fname)
924 return;
925
926 var tokens = result.split('\n');
927
928 // ----------------------------------------------------
929
930 var rtime = $("reporttime"+z);
931 var ltime = $("localtime"+z);
932
933 var now = new Date();
934
935 var header = tokens[0].split('\t');
936
937 // File corrupted / should we remove the date?)
938 if ((header.length>5 || header.length==2 || header.length==0) && header[0].length!=13)
939 {
940 // we ignore corrupted files for one minute
941 if (date0==null || date0.getTime()+60000<now.getTime())
942 rtime.style.color = "darkred";
943
944 return;
945 }
946
947 // File OK
948 date0 = now;
949
950 var stamp = new Date();
951 stamp.setTime(header[0]);
952
953 // File older than 1min
954 if (stamp.getTime()+60000<now.getTime())
955 rtime.style.color = "darkred";
956 else
957 rtime.style.color = "";
958
959 setUTC(rtime, stamp);
960 setUTC(ltime, now);
961
962 // ----------------------------------------------------
963
964 $("warn"+z).style.display = header.length>=4 && header[3]=='1' ? "" : "none";
965
966 if (header.length>=5)
967 $("cmd"+z).style.backgroundColor = header[4]=='1' ? "darkgreen" : "darkred";
968
969 if (header.length>=3 && $("body").sound)
970 {
971 $("speaker"+z).style.display ="none";
972
973 var audio = $("audio");
974
975 var audio_date = new Date();
976 audio_date.setTime(header[1]);
977
978 // Time stamp of audio file must be newer than page load
979 // or last audio play respecitvely
980 if (audio_date>audio.date)
981 {
982 audio.date = audio_date;
983
984 var name_ogg = "audio/"+header[2]+".ogg";
985 var name_mp3 = "audio/"+header[2]+".mp3";
986
987 var ogg = $new("SOURCE");
988 var mp3 = $new("SOURCE");
989 ogg.type = "audio/ogg";
990 mp3.type = "audio/mp3";
991 ogg.src = name_ogg;
992 mp3.src = name_mp3;
993
994 if (audio.firstChild.src!=ogg.src)
995 {
996 audio.replaceChild(ogg, audio.firstChild);
997 audio.replaceChild(mp3, audio.lastChild);
998 }
999 }
1000 }
1001
1002 // ----------------------------------------------------
1003
1004 //var p = table.tBodies.length==3 ? 1 : 0;
1005 //var tbody = table.tBodies[p];
1006
1007 for (var line=1; line<tokens.length; line++)
1008 {
1009 if (tokens[line].length==0)
1010 continue;
1011
1012 var e = $("data"+z+"-"+line);
1013 if (!e)
1014 continue;
1015
1016 var form = e.dataFormat;//getAttribute("data-form");
1017 if (!form)
1018 continue;
1019
1020 var cols = tokens[line].split('\t');
1021 for (var col=1; col<cols.length; col++)
1022 form = form.replace("\$"+(col-1), cols[col].length==0 ? "&mdash;" : cols[col]);
1023
1024 if (cols.length<=1)
1025 form = "&mdash;";
1026
1027 form = form.replace(/<#(.*?)>/g, "<font color='$1'>");
1028 form = form.replace(/<([\+-])>/g, "<font size='$11'>");
1029 form = form.replace(/<\/([#\+-])>/g, "</font>");
1030 form = form.replace(/([0-9][0-9]):([0-9][0-9]):([0-9][0-9])/g,
1031 "<pre>$1</pre>:<pre>$2</pre>:<pre>$3</pre>");
1032 form = form.replace(/--:--:--/g, "<pre> </pre> <pre> </pre> <pre> </pre>");
1033
1034 var newe = $new("div");
1035 newe.innerHTML = form;
1036 e.replaceChild(newe, e.lastChild);
1037
1038 e.parentNode.parentNode.parentNode.parentNode.style.background=cols[0];
1039 }
1040}
1041
1042// http://billmill.org/static/canvastutorial/index.html
1043// http://www.netmagazine.com/tutorials/learning-basics-html5-canvas
1044// http://www.alistapart.com/articles/responsive-web-design/
1045
1046function refresh_graphics()
1047{
1048 var z = $("body").visiblePage;//getAttribute("data-visible");
1049
1050 var canvas = $("canvas"+z);
1051
1052 // Is sliding or no data file defined?
1053 var fname = canvas==null ? "" : canvas.fileName;//getAttribute("data-file");
1054 if (isSliding() || !valid(fname))
1055 {
1056 // invalidate?
1057 timeoutGraphics = setTimeout(refresh_graphics, 3000);
1058 return;
1059 }
1060
1061 var xmlGfx = new XMLHttpRequest();
1062 xmlGfx.open('POST', "data/"+fname, true);
1063 xmlGfx.onload = function ()
1064 {
1065 if (xmlGfx.status!=200)
1066 {
1067 alert("ERROR[2] - Request '"+fname+"': "+xmlGfx.statusText+" ["+xmlGfx.status+"]");
1068 timeoutGraphics = setTimeout(refresh_graphics, 10000);
1069 //****** invalidate ******
1070 return;
1071 }
1072
1073 if (!isSliding())
1074 {
1075 cycleCol($("rdot"+z));
1076 process_eventdata(xmlGfx.responseText);
1077 }
1078 timeoutGraphics = setTimeout(refresh_graphics, 5000)
1079 };
1080 xmlGfx.send(null);
1081}
1082
1083
1084function hueToRGB(hue)
1085{
1086 hue /= 3;
1087 hue %= 6;
1088
1089 if (hue<1) return parseInt(255*hue, 10);
1090 if (hue<3) return parseInt(255, 10);
1091 if (hue<4) return parseInt(255*(4-hue), 10);
1092
1093 return 0.
1094}
1095
1096function hueToHex(flt)
1097{
1098 var s = hueToRGB(flt).toString(16);
1099 return s.length==2 ? s : "0"+s;
1100}
1101
1102function HLStoRGB(hue)
1103{
1104 hue *= 14;
1105
1106 var sr = hueToHex(20-hue);
1107 var sg = hueToHex(14-hue);
1108 var sb = hueToHex(26-hue);
1109
1110 return sr+sg+sb;
1111}
1112
1113function color(col)
1114{
1115 if (col==65533)
1116 col = 0;
1117
1118 var hue = col/128;
1119 return HLStoRGB(hue);
1120}
1121
1122function toHex(str, idx)
1123{
1124 var ch = str[idx].toString(16);
1125 return ch.length==2 ? ch : "0"+ch;
1126}
1127
1128function drawHex(ctx, x, y, col)
1129{
1130 ctx.fillStyle = "#"+color(col);
1131
1132 ctx.save();
1133
1134 ctx.translate(x, y);
1135 ctx.scale(1/2, 1/3);
1136
1137 ctx.beginPath();
1138 ctx.moveTo( 1, 1);
1139 ctx.lineTo( 0, 2);
1140 ctx.lineTo(-1, 1);
1141 ctx.lineTo(-1, -1);
1142 ctx.lineTo( 0, -2);
1143 ctx.lineTo( 1, -1);
1144 ctx.fill();
1145
1146 ctx.restore();
1147}
1148
1149function drawDisc(ctx, x, y, r, col)
1150{
1151 ctx.fillStyle = "#"+color(col);
1152
1153 ctx.save();
1154
1155 ctx.translate(x, y);
1156
1157 ctx.beginPath();
1158 ctx.arc(0, 0, r, 0, Math.PI*2, true);
1159 ctx.fill();
1160
1161 ctx.restore();
1162}
1163
1164function beginDrawCam(scale)
1165{
1166 var z = $("body").visiblePage;//getAttribute("data-visible");
1167 var canv = $("canvas"+z);
1168
1169 var w = Math.min(canv.width/scale, canv.height/scale);
1170
1171 var ctx = canv.getContext("2d");
1172
1173 ctx.save();
1174 ctx.translate(canv.width/2, canv.height/2);
1175 ctx.scale(w*2, w*2);
1176
1177 return ctx;
1178}
1179
1180/**
1181 * @constructor
1182 */
1183function Position(s, ring, i)
1184{
1185 switch (s)
1186 {
1187 case 1: this.x = ring - i*0.5; this.y = + i; break;
1188 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
1189 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
1190 case 4: this.x = -ring + i*0.5; this.y = - i; break;
1191 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
1192 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
1193 }
1194 this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
1195}
1196
1197function drawFullCam(data)
1198{
1199 if (data.length!=40 && data.length!=160 && data.length!=320 && data.length!=1440)
1200 {
1201 alert("Camera - Received data has invalid size ("+data.length+"b)");
1202 return;
1203 }
1204
1205 var div = map.length/data.length;
1206 var off = data.length==320 ? 0.2 : 0;
1207
1208 var ctx = beginDrawCam(83);
1209 // ctx.rotate(Math.PI/3);
1210
1211 ctx.scale(1, Math.sqrt(3)/2);
1212 ctx.translate(-0.5, 0);
1213
1214 drawHex(ctx, 0, 0, data.charCodeAt(parseInt(map[0]/div+off, 10)));
1215
1216 var cnt = 1;
1217 for (var ring=1; ring<24; ring++)
1218 {
1219 for (var s=0; s<6; s++)
1220 {
1221 for (var i=1; i<=ring; i++)
1222 {
1223 var pos = new Position(s, ring, i);
1224 if (pos.d() - pos.x > 395.75)
1225 continue;
1226
1227 var p = parseInt(map[cnt]/div+off, 10);
1228
1229 drawHex(ctx, pos.x, pos.y, data.charCodeAt(p));
1230 cnt++;
1231 }
1232 }
1233 }
1234
1235 drawHex(ctx, 7, -22, data.charCodeAt(parseInt(map[1438]/div+off, 10)));
1236 drawHex(ctx, 7, 22, data.charCodeAt(parseInt(map[1439]/div+off, 10)));
1237
1238 ctx.restore();
1239}
1240
1241function drawCam(data)
1242{
1243 var ctx = beginDrawCam(27);
1244 ctx.rotate(Math.PI/6);
1245 ctx.scale(1, Math.sqrt(3)/2);
1246
1247 drawHex(ctx, 0, 0, data.charCodeAt(0));
1248
1249 var cnt = 1;
1250 for (var ring=1; ring<=7; ring++)
1251 {
1252 for (var s=0; s<6; s++)
1253 {
1254 for (var i=1; i<=ring; i++)
1255 {
1256 var pos = new Position(s, ring, i);
1257 if (pos.d() > 44)
1258 continue;
1259
1260 if (ring==7)
1261 {
1262 if (i==6 && (s==0 || s==3))
1263 continue;
1264 if (i==1 && (s==1 || s==4))
1265 continue;
1266 }
1267
1268 drawHex(ctx, pos.x, pos.y, data.charCodeAt(cnt++));
1269 }
1270 }
1271 }
1272
1273 ctx.restore();
1274}
1275
1276function drawCamLegend(canv, data)
1277{
1278 var unit = canv.dataUnit;//htmlDecode(canv.getAttribute("data-data"));
1279
1280 var umin = data[1];
1281 var umax = data[2];
1282
1283 var min = data[3]+unit
1284 var med = data[4]+unit;
1285 var max = data[5]+unit;
1286
1287 var v0 = parseFloat(umin);
1288 var v1 = parseFloat(umax);
1289
1290 var diff = v1-v0;
1291
1292 var cw = canv.width;
1293 //var ch = canv.height;
1294
1295 var ctx = canv.getContext("2d");
1296
1297 ctx.font = "8pt Arial";
1298 ctx.textAlign = "right";
1299 ctx.textBaseline = "top";
1300
1301 for (var i=0; i<11; i++)
1302 {
1303 ctx.strokeStyle = "#"+color(16*i);
1304 ctx.strokeText((v0+diff*i/10).toPrecision(3)+unit, cw-5, 125-i*12);
1305 }
1306
1307 var mw = Math.max(ctx.measureText(min).width,
1308 ctx.measureText(med).width,
1309 ctx.measureText(max).width);
1310
1311 ctx.textBaseline = "top";
1312 ctx.strokeStyle = "#000";
1313
1314 ctx.strokeText(min, 5+mw, 5+24);
1315 ctx.strokeText(med, 5+mw, 5+12);
1316 ctx.strokeText(max, 5+mw, 5);
1317}
1318
1319function drawGraph(canv, vals, data)
1320{
1321 var unit = canv.dataUnit;//htmlDecode(canv.getAttribute("data-data"));//.split("/");
1322
1323 var umin = vals[1]+unit;
1324 var umax = vals[2]+unit;
1325
1326 var stat = vals[3]+unit+" / "+vals[4]+unit+" / "+vals[5]+unit;
1327
1328 var cw = canv.width;
1329 var ch = canv.height;
1330
1331 var ctx = canv.getContext("2d");
1332
1333 var dw = 3; // tick width
1334 var fs = 8; // font size
1335
1336 ctx.font = fs+"pt Arial";
1337 ctx.textAlign = "right";
1338
1339 var dim0 = ctx.measureText(umin);
1340 var dim1 = ctx.measureText(umax);
1341
1342 var tw = Math.max(dim0.width, dim1.width)+dw+2;
1343
1344 var ml = 5+tw; // margin left
1345 var mr = 10; // margin right
1346
1347 var mt = 5+2*fs+4; // margin top
1348 var mb = fs/2+4; // margin bottom
1349
1350 var nx = 20;
1351 var ny = 10;
1352
1353 var w = cw-ml-mr;
1354 var h = ch-mt-mb;
1355
1356 ctx.strokeStyle = "#666";
1357
1358 // --- data ---
1359 if (data.length>1)
1360 {
1361 ctx.beginPath();
1362 ctx.moveTo(ml, ch-mb-data.charCodeAt(0)/128*h);
1363 for (var i=1; i<data.length; i++)
1364 ctx.lineTo(ml+w/(data.length-1)*i, ch-mb-data.charCodeAt(i)/128*h);
1365
1366 // --- finalize data ---
1367 ctx.lineTo(cw-mr, ch-mb);
1368 ctx.lineTo(ml, ch-mb);
1369 ctx.fillStyle = "#"+color(100);
1370 ctx.stroke();
1371 ctx.fill();
1372 }
1373
1374 ctx.beginPath();
1375
1376 // --- grid ---
1377
1378 ctx.strokeStyle = "#eee";
1379
1380 for (var i=1; i<=nx; i++)
1381 {
1382 ctx.moveTo(ml+w*i/nx, ch-mb);
1383 ctx.lineTo(ml+w*i/nx, mt);
1384 }
1385 for (var i=0; i<ny; i++)
1386 {
1387 ctx.moveTo(ml, mt+h*i/ny);
1388 ctx.lineTo(ml+w, mt+h*i/ny);
1389 }
1390 ctx.stroke();
1391 ctx.closePath();
1392 ctx.beginPath();
1393
1394 ctx.strokeStyle = "#000";
1395
1396 // --- axes ---
1397 ctx.moveTo(ml, mt);
1398 ctx.lineTo(ml, ch-mb);
1399 ctx.lineTo(cw-mr, ch-mb);
1400
1401 for (var i=1; i<=nx; i++)
1402 {
1403 ctx.moveTo(ml+w*i/nx, ch-mb-dw);
1404 ctx.lineTo(ml+w*i/nx, ch-mb+dw);
1405 }
1406 for (var i=0; i<ny; i++)
1407 {
1408 ctx.moveTo(ml-dw, mt+h*i/ny);
1409 ctx.lineTo(ml+dw, mt+h*i/ny);
1410 }
1411 ctx.stroke();
1412 ctx.closePath();
1413
1414 ctx.textBaseline = "bottom";
1415 ctx.strokeText(umin, ml-dw-2, ch-1);
1416
1417 ctx.textBaseline = mt>fs/2 ? "middle" : "top";
1418 ctx.strokeText(umax, ml-dw-2, mt);
1419
1420 ctx.textBaseline = "top";
1421 ctx.textAlign = "center";
1422 ctx.strokeText(stat, ml+w/2, 5);
1423}
1424
1425function process_eventdata(result)
1426{
1427 if (result.length==0)
1428 return;
1429
1430 var z = $("body").visiblePage;//getAttribute("data-visible");
1431 var canv = $("canvas"+z);
1432 if (!canv)
1433 return;
1434
1435 var type = canv.dataType;//getAttribute("data-type");
1436
1437 var ctx = canv.getContext("2d");
1438 ctx.clearRect(0, 0, canv.width, canv.height);
1439
1440 var data = result.split('\n');
1441 if (result.length<4)
1442 return;
1443
1444 var len = 0;
1445 for (var i=0; i<6; i++)
1446 len += data[i].length+1;
1447
1448 switch (type)
1449 {
1450 //case "camera": drawCam(result); break;
1451 case "hist":
1452 drawGraph(canv, data, result.substr(len));
1453 break;
1454 case "camera":
1455 drawFullCam(result.substr(len));
1456 drawCamLegend(canv, data);
1457 break;
1458 }
1459
1460 var now = new Date();
1461 var tm = new Date();
1462 tm.setTime(data[0]);
1463 if (tm.getTime()+60000<now.getTime())
1464 {
1465 ctx.fillStyle = "rgba(255, 255, 255, 0.75)";
1466 ctx.fillRect(0, 0, canv.width, canv.height);
1467 }
1468
1469 //$("image"+z).src = canv.toDataURL("image/png");
1470}
1471
1472function save()
1473{
1474 var z = $("body").visiblePage;//getAttribute("data-visible");
1475
1476 var canvas = $("canvas"+z);
1477 var img = canvas.toDataURL("image/png");
1478
1479 img = img.replace("image/png", "image/octet-stream");
1480
1481 document.location.href = img;
1482}
1483
1484window['onload'] = onload;
Note: See TracBrowser for help on using the repository browser.