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

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