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

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