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

Last change on this file since 17689 was 17680, checked in by tbretz, 11 years ago
Opacity of 'gray out' to 50%
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 login(txt[0]);
196 if (txt.length>1)
197 alert(xmlCmd.responseText);
198 else
199 alert("Command submitted.");
200 };
201 xmlCmd.send(null);
202}
203
204
205function submit(script, isIrq)
206{
207 var inputs = document.getElementsByTagName("input");
208
209 var args = isIrq ? "interrupt="+script : "start="+script+".js";
210
211 for (var i=0; i<inputs.length; i++)
212 args += "&"+inputs[i].name+"="+inputs[i].value;
213
214 var selects = document.getElementsByTagName("select");
215 for (var i=0; i<selects.length; i++)
216 args += "&"+selects[i].name+"="+selects[i].value;
217
218 sendCommand(args);
219}
220
221function buildPage(name, text, oldz, dz)
222{
223 var fname = dz==0 ? "fact" : $("table"+oldz).pageName;//getAttribute("data-file");
224
225 var z = oldz + dz;
226
227 var lines = text.split('\n');
228
229 if (lines.length==0)
230 {
231 alert("buildPage - received data empty.");
232 return;
233 }
234
235 if (lines[0].length==0)
236 {
237 alert("buildPage - title missing");
238 return;
239 }
240
241 $("audio").date = new Date();
242
243 var title = lines[0];
244 var is_cmd = title[0]=='*' || title[0]=='!';
245 var is_irq = title[0]=='!';
246 var script = title.split('|');
247 if (is_cmd)
248 {
249 title = script.length>=1 ? script[0].substr(1) : title.substr(1);
250 script = script.length>=1 ? script[1] : name;
251 }
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(script, is_irq); 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(script); 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:-289px 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 (is_cmd || 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]=="checkbox")
679 {
680 var opt = check[1].split('/');
681
682 var div = $new("div");
683 div.innerHTML = opt[0];
684 cell1.appendChild(div);
685
686 var input = $new("input");
687 input.type = "checkbox";
688 input.name = opt[1];
689 input.onclick = function() { this.value=this.checked; };
690 var c = opt.length>2 && opt[2]=="1";
691 input.checked = c;
692 input.value = c;
693
694 cell2.appendChild(input);
695 }
696 if (check.length==0 || (check[0]!="input" && check[0]!="select" && check[0]!="checkbox"))
697 {
698 var div = $new("div");
699 div.innerHTML = cols[1];
700 cell1.appendChild(div);
701
702 if (cols.length>2 && cols[2].length>0)
703 {
704 cell2.id = "data"+z+"-"+counter;
705 cell2.dataFormat = cols[2];
706 cell2.appendChild($txt("---"));
707 counter++;
708 }
709 else
710 cell1.setAttribute("class", "description");
711 }
712
713 innertr.appendChild(cell1);
714 innertr.appendChild(cell2);
715
716 tbody.appendChild(tr);
717 }
718
719 // ==================================================================
720
721 if (debug == true)
722 {
723 tr = $new("tr");
724 tr.setAttribute("class", "row");
725
726 td = $new("td");
727 td.id = "debug"+z;
728 td.colSpan = 3;
729 tr.appendChild(td);
730
731 tbody.appendChild(tr);
732 }
733
734 // ==================================================================
735
736 var table = $("table"+z);
737 if (table)
738 $("body").removeChild(table);
739
740 table = $new("table");
741 table.id = "table"+z;
742 table.border = 0;
743 table.cellSpacing = 0;
744 table.cellPadding = "0px";
745 //table.setAttribute("style", "overflow:hidden;position:fixed;top:0px;left:"+window.innerWidth+"px;")
746 table.setAttribute("style",
747 "position:fixed;width:100%;top:0px;"+
748 "left:"+window.innerWidth+"px;");
749
750 table.appendChild(th);
751 table.appendChild(tbody);
752 table.appendChild(tf);
753
754 $("body").appendChild(table);
755
756 // ==================================================================
757
758 /*
759 // Scrollbar for just the body
760 table.style.position = "fixed";
761 th.style.position = "aboslute";
762 tf.style.position = "aboslute";
763 tbody.style.overflowY = "auto";
764 tbody.style.display = "block";
765 tbody.style.height = (window.innerHeight-th.clientHeight-tf.clientHeight)+"px";
766 tbody.id = "tbody"+z;
767 th.id = "thead"+z;
768 tf.id = "tfoot"+z;
769 */
770
771 // ==================================================================
772
773 table.pageName = name;//setAttribute("data-file", name);
774 table.counter = counter;
775
776 // This is needed so that the page is extended in height
777 // _before_ the sliding (in case it contains graphics
778 doresize(z);
779}
780
781function doresize(z)
782{
783 var img = $("image"+z);
784 var canv = $("canvas"+z);
785 if (!img || !canv)
786 return;
787
788 var h = $("table"+z).offsetHeight;
789 if (h == 0)
790 return;
791
792 // ===========================================
793 /*
794 var tb = $("tbody"+z);
795 var hw = $("thead"+z).clientHeight;
796 var fw = $("tfoot"+z).clientHeight;
797
798 tb.style.height = (window.innerHeight-hw-fw)+"px";
799 */
800 // ===========================================
801
802 var fixedw = $("body").displayFixedWidth;//getAttribute("data-width");
803 var fixedh = $("body").displayFixedHeight;//getAttribute("data-height");
804
805 var W = fixedw>0 ? fixedw : window.innerWidth;
806 var H = fixedh>0 ? fixedh : window.innerHeight;
807
808 //var max = $("body").getAttribute("data-max")=="yes";
809 var max = $("body").displayMax;
810
811 var ih = max ? W : H - h + parseInt(img.style.height, 10);
812
813 // This might create the scroll bar
814
815 if (img.style.height!=ih+"px")
816 img.style.height = ih+"px";
817 if (canv.height!=ih)
818 canv.height = ih;
819
820 // now we can evaluate the correct view-port
821 // (-2 is the border size of the parent element 'container')
822 //var sW = (fixedw ? fixedw : $("table"+z).scrollWidth)-2;
823 var sW = fixedw ? fixedw : canv.parentNode.clientWidth;
824
825 if (img.style.width!=sW+"px")
826 img.style.width = sW+"px";
827 if (canv.width!=sW)
828 canv.width = sW;
829
830 // ------ debug -----
831 if (debug == true)
832 {
833 $('debug'+z).innerHTML = "";
834 $('debug'+z).innerHTML += "|W="+W +"/"+H;
835 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
836 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
837 }
838}
839
840var intervalSlide = null;
841
842function changePage(oldz, newz)
843{
844 // No page displayed yet
845 if (oldz==newz)
846 {
847 var tab = $("table"+newz);
848
849 tab.style.left="0px";
850 tab.style.position="absolute";
851
852 $("body").visiblePage = newz; //.setAttribute("data-visible", newz);
853
854 doresize(newz);
855
856 //setInterval(refresh_text, 1000);
857 //setInterval(refresh_graphics, 5000);
858
859 refresh_text();
860
861 // first: decode the pixel mapping!
862 var sum = 1036080;
863 for (var i=0; i<1440; i++)
864 {
865 var d0 = codedMap.charCodeAt(i*2) -48;
866 var d1 = codedMap.charCodeAt(i*2+1)-48;
867
868 map[i] = d0 | (d1<<6);
869 sum -= map[i];
870 }
871 if (sum!=0)
872 alert("Pixel mapping table corrupted!");
873
874 refresh_graphics();
875 return;
876 }
877
878 var W = window.innerWidth;
879 if (W==0 || $("body").displayNoslide)//$("body").getAttribute("data-noslide")=="yes")
880 {
881 $("body").visiblePage = newz;//setAttribute("data-visible", newz);
882 $("body").removeChild($("table"+oldz));
883 $("table"+newz).style.left="0px";
884 return;
885 }
886
887 if (newz>oldz)
888 $("table"+newz).style.left = W+"px";
889 else
890 $("table"+newz).style.left = (-W-1)+"px";
891
892 $("body").visiblePage = newz;//setAttribute("data-visible", newz);
893
894 // This is needed on my mobile to ensure that te browser
895 // doesn't try to zoom during shifting
896 $("table"+newz).style.position="fixed";
897 $("table"+oldz).style.position="fixed";
898
899 intervalSlide = setInterval(function (){doShift(oldz,newz);}, 75);
900}
901
902function doShift(oldz, newz)
903{
904 var t0 = $("table"+oldz);
905 var t1 = $("table"+newz);
906
907 if (t0.style.display=="none")
908 {
909 clearInterval(intervalSlide);
910 $("body").removeChild(t0);
911
912 t1.style.position="absolute";
913
914 // Now the scroll bar might have to appear or disappear
915 doresize(newz);
916 return;
917 }
918
919 var x0 = t0.offsetLeft;
920 var x1 = t1.offsetLeft;
921
922 var W = window.innerWidth;
923
924 if (newz<oldz)
925 {
926 x0 += W/5;
927 x1 += W/5;
928 }
929
930 if (newz>oldz)
931 {
932 x0 -= W/5;
933 x1 -= W/5;
934 }
935
936 if ((newz<oldz && x1>=0) || (newz>oldz && x1<=0))
937 {
938 t0.style.display="none";
939 x1 = 0;
940 }
941
942 t0.style.left = x0+"px";
943 t1.style.left = x1+"px";
944}
945
946var timeoutText = null;
947var timeoutGraphics = null;
948
949var test_counter = 0;
950
951function refresh_text()
952{
953 var z=$("body").visiblePage;//getAttribute("data-visible");
954
955 var fname = $("table"+z).pageName;//getAttribute("data-file");
956 var counter = $("table"+z).counter;//getAttribute("data-file");
957
958 var is_help = fname.substr(0,5)=="help-";
959
960 // Is sliding, no file defined or just help text?
961 if (isSliding() || !valid(fname) || is_help)
962 {
963 if (is_help)
964 {
965 setUTC($("localtime"+z), new Date());
966 $("reporttime"+z).innerHTML="";
967 }
968
969 // invalidate?
970 timeoutText = setTimeout(refresh_text, 1000);
971 return;
972 }
973
974 var xmlText = new XMLHttpRequest();
975 xmlText.open('GET', "data/"+fname+'.data', true);
976 xmlText.setRequestHeader("Cache-Control", "no-cache");
977 xmlText.setRequestHeader("If-Match", "*");
978 xmlText.onload = function ()
979 {
980// if (xmlText.status==412)
981// {
982// timeoutText = setTimeout(refresh_text, 3000);
983// return;
984// }
985
986 if (counter>1 && xmlText.status!=200 && xmlText.status!=412)
987 {
988 alert("ERROR[2] - HTTP request '"+fname+".data': "+xmlText.statusText+" ["+xmlText.status+"]");
989 timeoutText = setTimeout(refresh_text, 10000);
990 return;
991 }
992
993 if (!isSliding())
994 {
995 cycleCol($("ldot"+z));
996 update_text(fname, counter>1 ? xmlText.responseText : undefined);
997 doresize(z);
998 }
999 timeoutText = setTimeout(refresh_text, 3000);
1000 };
1001 xmlText.send(null);
1002}
1003
1004var date0 = null;
1005
1006var test = 0;
1007function update_text(fname, result)
1008{
1009 var z=$("body").visiblePage;//getAttribute("data-visible");
1010 var table = $("table"+z);
1011
1012 if (table.pageName/*getAttribute("data-file")*/ != fname)
1013 return;
1014
1015 // ----------------------------------------------------
1016 var now = new Date();
1017
1018 var ltime = $("localtime"+z);
1019 setUTC(ltime, now);
1020
1021 if (!result)
1022 return;
1023
1024 var rtime = $("reporttime"+z);
1025 var tokens = result.split('\n');
1026 var header = tokens[0].split('\t');
1027
1028 // File corrupted / should we remove the date?)
1029 if ((header.length>5 || header.length==2 || header.length==0) && header[0].length!=13)
1030 {
1031 // we ignore corrupted files for one minute
1032 if (date0==null || date0.getTime()+60000<now.getTime())
1033 rtime.style.color = "darkred";
1034
1035 return;
1036 }
1037
1038 // File OK
1039 date0 = now;
1040
1041 var stamp = new Date();
1042 stamp.setTime(header[0]);
1043
1044 // File older than 1min
1045 if (stamp.getTime()+60000<now.getTime())
1046 rtime.style.color = "darkred";
1047 else
1048 rtime.style.color = "";
1049
1050 setUTC(rtime, stamp);
1051
1052 $("warn"+z).style.display = header.length>=4 && header[3]=='1' ? "" : "none";
1053
1054 if (header.length>=5)
1055 $("cmd"+z).style.backgroundColor = header[4]=='1' ? "darkgreen" : "darkred";
1056
1057 // ----------------------------------------------------
1058
1059 if (header.length>=3 && $("body").sound)
1060 {
1061 $("speaker"+z).style.display = "none";
1062
1063 var audio = $("audio");
1064
1065 var audio_date = new Date();
1066 audio_date.setTime(header[1]);
1067
1068 // Time stamp of audio file must be newer than page load
1069 // or last audio play respecitvely
1070 if (audio_date>audio.date && header[2].length>0)
1071 {
1072 var name = "audio/"+header[2];
1073
1074 var mp3 = $new("SOURCE");
1075 var ogg = $new("SOURCE");
1076 mp3.src = name+".mp3";
1077 ogg.src = name+".ogg";
1078 mp3.type = "audio/mp3";
1079 ogg.type = "audio/ogg";
1080
1081 audio.replaceChild(mp3, audio.firstChild);
1082 audio.replaceChild(ogg, audio.lastChild);
1083
1084 audio.load();
1085 audio.play();
1086
1087 audio.date = audio_date;
1088 }
1089 }
1090
1091 // ----------------------------------------------------
1092
1093 //var p = table.tBodies.length==3 ? 1 : 0;
1094 //var tbody = table.tBodies[p];
1095
1096 for (var line=1; line<tokens.length; line++)
1097 {
1098 if (tokens[line].length==0)
1099 continue;
1100
1101 var e = $("data"+z+"-"+line);
1102 if (!e)
1103 continue;
1104
1105 var form = e.dataFormat;//getAttribute("data-form");
1106 if (!form)
1107 continue;
1108
1109 var cols = tokens[line].split('\t');
1110 for (var col=1; col<cols.length; col++)
1111 form = form.replace("\$"+(col-1), cols[col].length==0 ? "&mdash;" : cols[col]);
1112
1113 if (cols.length<=1)
1114 form = "&mdash;";
1115
1116 form = form.replace(/<B#(.*?)>/g, "<b style='background:#$1'>");
1117 form = form.replace(/<#(.*?)>/g, "<font color='$1'>");
1118 form = form.replace(/<([\+-])>/g, "<font size='$11'>");
1119 form = form.replace(/<\/([#\+-])>/g, "</font>");
1120 form = form.replace(/([0-9][0-9]):([0-9][0-9]):([0-9][0-9])/g,
1121 "<pre>$1</pre>:<pre>$2</pre>:<pre>$3</pre>");
1122 form = form.replace(/--:--:--/g, "<pre> </pre> <pre> </pre> <pre> </pre>");
1123
1124 var newe = $new("div");
1125 newe.innerHTML = form;
1126 e.replaceChild(newe, e.lastChild);
1127
1128 e.parentNode.parentNode.parentNode.parentNode.style.background=cols[0];
1129 }
1130}
1131
1132// http://billmill.org/static/canvastutorial/index.html
1133// http://www.netmagazine.com/tutorials/learning-basics-html5-canvas
1134// http://www.alistapart.com/articles/responsive-web-design/
1135
1136function refresh_graphics()
1137{
1138 var z = $("body").visiblePage;//getAttribute("data-visible");
1139
1140 var canvas = $("canvas"+z);
1141
1142 // Is sliding or no data file defined?
1143 var fname = canvas==null ? "" : canvas.fileName;//getAttribute("data-file");
1144 if (isSliding() || !valid(fname))
1145 {
1146 // invalidate?
1147 timeoutGraphics = setTimeout(refresh_graphics, 3000);
1148 return;
1149 }
1150
1151 var xmlGfx = new XMLHttpRequest();
1152 xmlGfx.open('GET', "data/"+fname, true);
1153 xmlGfx.setRequestHeader("Cache-Control", "no-cache");
1154 xmlGfx.setRequestHeader("If-Match", "*");
1155 xmlGfx.onload = function ()
1156 {
1157// if (xmlGfx.status==412)
1158// {
1159// timeoutGraphics = setTimeout(refresh_graphics, 5000);
1160// return;
1161// }
1162
1163 if (xmlGfx.status!=200 && xmlGfx.status!=412)
1164 {
1165 alert("ERROR[3] - Request '"+fname+"': "+xmlGfx.statusText+" ["+xmlGfx.status+"]");
1166 timeoutGraphics = setTimeout(refresh_graphics, 10000);
1167 //****** invalidate ******
1168 return;
1169 }
1170
1171 if (!isSliding())
1172 {
1173 cycleCol($("rdot"+z));
1174 process_eventdata(xmlGfx.responseText);
1175 }
1176 timeoutGraphics = setTimeout(refresh_graphics, 5000)
1177 };
1178 xmlGfx.send(null);
1179}
1180
1181
1182function hueToRGB(hue)
1183{
1184 hue /= 3;
1185 hue %= 6;
1186
1187 if (hue<1) return parseInt(255*hue, 10);
1188 if (hue<3) return parseInt(255, 10);
1189 if (hue<4) return parseInt(255*(4-hue), 10);
1190
1191 return 0.
1192}
1193
1194function hueToHex(flt)
1195{
1196 var s = hueToRGB(flt).toString(16);
1197 return s.length==2 ? s : "0"+s;
1198}
1199
1200function HLStoRGB(hue)
1201{
1202 hue *= 14;
1203
1204 var sr = hueToHex(20-hue);
1205 var sg = hueToHex(14-hue);
1206 var sb = hueToHex(26-hue);
1207
1208 return sr+sg+sb;
1209}
1210
1211function color(col)
1212{
1213 if (col==65533)
1214 return HLStoRGB(0);
1215
1216 var hue = col/126;
1217 return HLStoRGB(hue);
1218}
1219
1220function toHex(str, idx)
1221{
1222 var ch = str[idx].toString(16);
1223 return ch.length==2 ? ch : "0"+ch;
1224}
1225
1226function drawHex(ctx, x, y, col)
1227{
1228 ctx.fillStyle = "#"+color(col);
1229
1230 ctx.save();
1231
1232 ctx.translate(x, y);
1233 ctx.scale(1/2, 1/3);
1234
1235 ctx.beginPath();
1236 ctx.moveTo( 1, 1);
1237 ctx.lineTo( 0, 2);
1238 ctx.lineTo(-1, 1);
1239 ctx.lineTo(-1, -1);
1240 ctx.lineTo( 0, -2);
1241 ctx.lineTo( 1, -1);
1242 ctx.fill();
1243
1244 ctx.restore();
1245}
1246
1247function drawDisc(ctx, x, y, r, col)
1248{
1249 ctx.fillStyle = "#"+color(col);
1250
1251 ctx.save();
1252
1253 ctx.translate(x, y);
1254
1255 ctx.beginPath();
1256 ctx.arc(0, 0, r, 0, Math.PI*2, true);
1257 ctx.fill();
1258
1259 ctx.restore();
1260}
1261
1262function beginDrawCam(scale)
1263{
1264 var z = $("body").visiblePage;//getAttribute("data-visible");
1265 var canv = $("canvas"+z);
1266
1267 var w = Math.min(canv.width/scale, canv.height/scale);
1268
1269 var ctx = canv.getContext("2d");
1270
1271 ctx.save();
1272 ctx.translate(canv.width/2, canv.height/2);
1273 ctx.scale(w*2, w*2);
1274
1275 return ctx;
1276}
1277
1278/**
1279 * @constructor
1280 */
1281function Position(s, ring, i)
1282{
1283 switch (s)
1284 {
1285 case 1: this.x = ring - i*0.5; this.y = + i; break;
1286 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
1287 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
1288 case 4: this.x = -ring + i*0.5; this.y = - i; break;
1289 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
1290 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
1291 }
1292 this.d = (function () { return this.x*this.x + this.y*this.y*3/4; });
1293}
1294
1295function drawFullCam(data)
1296{
1297 if (data.length!=40 && data.length!=160 && data.length!=320 && data.length!=1440)
1298 {
1299 alert("Camera - Received data has invalid size ("+data.length+"b)");
1300 return;
1301 }
1302
1303 var div = map.length/data.length;
1304 var off = data.length==320 ? 0.2 : 0;
1305
1306 var ctx = beginDrawCam(83);
1307 // ctx.rotate(Math.PI/3);
1308
1309 ctx.scale(1, Math.sqrt(3)/2);
1310 ctx.translate(-0.5, 0);
1311
1312 drawHex(ctx, 0, 0, data.charCodeAt(parseInt(map[0]/div+off, 10)));
1313
1314 var cnt = 1;
1315 for (var ring=1; ring<24; ring++)
1316 {
1317 for (var s=0; s<6; s++)
1318 {
1319 for (var i=1; i<=ring; i++)
1320 {
1321 var pos = new Position(s, ring, i);
1322 if (pos.d() - pos.x > 395.75)
1323 continue;
1324
1325 var p = parseInt(map[cnt]/div+off, 10);
1326
1327 drawHex(ctx, pos.x, pos.y, data.charCodeAt(p));
1328 cnt++;
1329 }
1330 }
1331 }
1332
1333 drawHex(ctx, 7, -22, data.charCodeAt(parseInt(map[1438]/div+off, 10)));
1334 drawHex(ctx, 7, 22, data.charCodeAt(parseInt(map[1439]/div+off, 10)));
1335
1336 ctx.restore();
1337}
1338
1339function drawCam(data)
1340{
1341 var ctx = beginDrawCam(27);
1342 ctx.rotate(Math.PI/6);
1343 ctx.scale(1, Math.sqrt(3)/2);
1344
1345 drawHex(ctx, 0, 0, data.charCodeAt(0));
1346
1347 var cnt = 1;
1348 for (var ring=1; ring<=7; ring++)
1349 {
1350 for (var s=0; s<6; s++)
1351 {
1352 for (var i=1; i<=ring; i++)
1353 {
1354 var pos = new Position(s, ring, i);
1355 if (pos.d() > 44)
1356 continue;
1357
1358 if (ring==7)
1359 {
1360 if (i==6 && (s==0 || s==3))
1361 continue;
1362 if (i==1 && (s==1 || s==4))
1363 continue;
1364 }
1365
1366 drawHex(ctx, pos.x, pos.y, data.charCodeAt(cnt++));
1367 }
1368 }
1369 }
1370
1371 ctx.restore();
1372}
1373
1374function drawCamLegend(canv, data)
1375{
1376 var unit = canv.dataUnit;//htmlDecode(canv.getAttribute("data-data"));
1377
1378 var umin = data[1];
1379 var umax = data[2];
1380
1381 var min = data[3]+unit
1382 var med = data[4]+unit;
1383 var max = data[5]+unit;
1384
1385 var v0 = parseFloat(umin);
1386 var v1 = parseFloat(umax);
1387
1388 var diff = v1-v0;
1389
1390 var cw = canv.width;
1391 //var ch = canv.height;
1392
1393 var ctx = canv.getContext("2d");
1394
1395 ctx.font = "8pt Arial";
1396 ctx.textAlign = "right";
1397 ctx.textBaseline = "top";
1398
1399 for (var i=0; i<11; i++)
1400 {
1401 ctx.strokeStyle = "#"+color(126*i/10);
1402 ctx.strokeText((v0+diff*i/10).toPrecision(3)+unit, cw-5, 125-i*12);
1403 }
1404
1405 var mw = Math.max(ctx.measureText(min).width,
1406 ctx.measureText(med).width,
1407 ctx.measureText(max).width);
1408
1409 ctx.textBaseline = "top";
1410 ctx.strokeStyle = "#000";
1411
1412 ctx.strokeText(min, 5+mw, 5+24);
1413 ctx.strokeText(med, 5+mw, 5+12);
1414 ctx.strokeText(max, 5+mw, 5);
1415}
1416
1417function drawGraph(canv, vals, data)
1418{
1419 var unit = canv.dataUnit;//htmlDecode(canv.getAttribute("data-data"));//.split("/");
1420
1421 var umin = vals[1]+unit;
1422 var umax = vals[2]+unit;
1423
1424 var stat = vals.length==4 ? vals[3] :
1425 vals[3]+unit+" / "+vals[4]+unit+" / "+vals[5]+unit;
1426
1427 var cw = canv.width;
1428 var ch = canv.height;
1429
1430 var ctx = canv.getContext("2d");
1431
1432 var dw = 3; // tick width
1433 var fs = 8; // font size
1434
1435 ctx.font = fs+"pt Arial";
1436 ctx.textAlign = "right";
1437
1438 var dim0 = ctx.measureText(umin);
1439 var dim1 = ctx.measureText(umax);
1440
1441 var tw = Math.max(dim0.width, dim1.width)+dw+2;
1442
1443 var ml = 5+tw; // margin left
1444 var mr = 10; // margin right
1445
1446 var mt = 5+2*fs+4; // margin top
1447 var mb = fs/2+4; // margin bottom
1448
1449 var nx = 20;
1450 var ny = 10;
1451
1452 var w = cw-ml-mr;
1453 var h = ch-mt-mb;
1454
1455 ctx.strokeStyle = "#666";
1456 ctx.fillStyle = "#"+color(100);
1457
1458 // --- data ---
1459 var cnt = 0;
1460 for (var j=1; j<data.length; j++)
1461 {
1462 if (data[j].length<5)
1463 continue;
1464
1465 ctx.strokeStyle = "#"+data[j].substr(0, 3);
1466 data[j] = data[j].substr(3);
1467
1468 ctx.beginPath();
1469 ctx.moveTo(ml, ch-mb-data[j].charCodeAt(0)/126*h);
1470 for (var i=1; i<data[j].length; i++)
1471 ctx.lineTo(ml+w/(data[j].length-1)*i, ch-mb-data[j].charCodeAt(i)/126*h);
1472
1473 // --- finalize data ---
1474 ctx.lineTo(cw-mr, ch-mb);
1475 ctx.lineTo(ml, ch-mb);
1476 ctx.stroke();
1477
1478 cnt++;
1479 }
1480 if (cnt==1)
1481 ctx.fill();
1482
1483 ctx.beginPath();
1484
1485 // --- grid ---
1486
1487 ctx.strokeStyle = "#eee";
1488
1489 for (var i=1; i<=nx; i++)
1490 {
1491 ctx.moveTo(ml+w*i/nx, ch-mb);
1492 ctx.lineTo(ml+w*i/nx, mt);
1493 }
1494 for (var i=0; i<ny; i++)
1495 {
1496 ctx.moveTo(ml, mt+h*i/ny);
1497 ctx.lineTo(ml+w, mt+h*i/ny);
1498 }
1499 ctx.stroke();
1500 ctx.closePath();
1501 ctx.beginPath();
1502
1503 ctx.strokeStyle = "#000";
1504
1505 // --- axes ---
1506 ctx.moveTo(ml, mt);
1507 ctx.lineTo(ml, ch-mb);
1508 ctx.lineTo(cw-mr, ch-mb);
1509
1510 for (var i=1; i<=nx; i++)
1511 {
1512 ctx.moveTo(ml+w*i/nx, ch-mb-dw);
1513 ctx.lineTo(ml+w*i/nx, ch-mb+dw);
1514 }
1515 for (var i=0; i<ny; i++)
1516 {
1517 ctx.moveTo(ml-dw, mt+h*i/ny);
1518 ctx.lineTo(ml+dw, mt+h*i/ny);
1519 }
1520 ctx.stroke();
1521 ctx.closePath();
1522
1523 ctx.textBaseline = "bottom";
1524 ctx.strokeText(umin, ml-dw-2, ch-1);
1525
1526 ctx.textBaseline = mt>fs/2 ? "middle" : "top";
1527 ctx.strokeText(umax, ml-dw-2, mt);
1528
1529 ctx.textBaseline = "top";
1530 ctx.textAlign = "center";
1531 ctx.strokeText(stat, ml+w/2, 5);
1532}
1533
1534function invalidateCanvas(canv)
1535{
1536 var ctx = canv.getContext("2d");
1537
1538 ctx.fillStyle = "rgba(255, 255, 255, 0.5)";
1539 ctx.fillRect(0, 0, canv.width, canv.height);
1540}
1541
1542function processGraphicsData(canv, result)
1543{
1544 if (result.length==0)
1545 return false;
1546
1547 var ctx = canv.getContext("2d");
1548 ctx.clearRect(0, 0, canv.width, canv.height);
1549
1550 var data = result.split('\x7f');
1551 if (data.length<2)
1552 return false;
1553
1554 var header = data[0].split('\n');
1555 if (header.length<4)
1556 return false;
1557
1558 switch (canv.dataType)
1559 {
1560 //case "camera": drawCam(result); break;
1561 case "hist":
1562 drawGraph(canv, header, data);
1563 break;
1564 case "camera":
1565 drawFullCam(data[1]);
1566 drawCamLegend(canv, header);
1567 break;
1568 }
1569
1570 var now = new Date();
1571 var tm = new Date();
1572 tm.setTime(header[0]);
1573
1574 if (tm.getTime()+60000<now.getTime())
1575 return false;
1576
1577 //$("image"+z).src = canv.toDataURL("image/png");
1578
1579 return true;
1580}
1581
1582function process_eventdata(result)
1583{
1584 var z = $("body").visiblePage;//getAttribute("data-visible");
1585 var canv = $("canvas"+z);
1586 if (!canv)
1587 return;
1588
1589 if (!processGraphicsData(canv, result))
1590 invalidateCanvas(canv);
1591}
1592
1593function save()
1594{
1595 var z = $("body").visiblePage;//getAttribute("data-visible");
1596
1597 var canvas = $("canvas"+z);
1598 var img = canvas.toDataURL("image/png");
1599
1600 img = img.replace("image/png", "image/octet-stream");
1601
1602 document.location.href = img;
1603}
1604
1605window['onload'] = onload;
Note: See TracBrowser for help on using the repository browser.