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

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