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

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