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

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