1 | /*
|
---|
2 | try { xmlHttp = new XMLHttpRequest(); }
|
---|
3 | catch(e)
|
---|
4 | {
|
---|
5 | try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
|
---|
6 | catch(e)
|
---|
7 | {
|
---|
8 | try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
|
---|
9 | catch(e)
|
---|
10 | {
|
---|
11 | alert("Your browser doesn't support dynamic reload.");
|
---|
12 | return;
|
---|
13 | }
|
---|
14 | }
|
---|
15 | }
|
---|
16 | */
|
---|
17 |
|
---|
18 | function $(id) { return document.getElementById(id); }
|
---|
19 | function trim(str) { return str.replace("/^\s\s*/", '').replace("/\s\s*$/", ''); }
|
---|
20 | function valid(str) { if (str==undefined) return false; if (str.length==0) return false; return true;}
|
---|
21 | function isSliding(){ return $("table0").offsetLeft!=0 && $("table1").offsetLeft!=0; }
|
---|
22 | function cycleCol(el)
|
---|
23 | {
|
---|
24 | var col = el.getAttribute("data-col");
|
---|
25 | col++;
|
---|
26 | col %= 31;
|
---|
27 | el.setAttribute("data-col", col);
|
---|
28 | if (col>16)
|
---|
29 | col = 31-col;
|
---|
30 | var hex = col.toString(16);
|
---|
31 | el.style.color = "#"+hex+"0"+hex+"0"+hex+"f";
|
---|
32 | }
|
---|
33 |
|
---|
34 | function onload()
|
---|
35 | {
|
---|
36 | /*
|
---|
37 | alert("0 -- "+navigator.appCodeName+"\n"+
|
---|
38 | "1 -- "+navigator.appName+"\n"+
|
---|
39 | "2 -- "+navigator.appVersion+"\n"+
|
---|
40 | "3 -- "+navigator.platform+"\n"+
|
---|
41 | "4 -- "+navigator.userAgent);
|
---|
42 | */
|
---|
43 | loadPage("fact", 0);
|
---|
44 | }
|
---|
45 |
|
---|
46 | function onresize()
|
---|
47 | {
|
---|
48 | var z = $("body").getAttribute("data-visible");
|
---|
49 | doresize(z);
|
---|
50 | }
|
---|
51 |
|
---|
52 | function loadPage(name, z)
|
---|
53 | {
|
---|
54 | var xmlHttp = null;
|
---|
55 |
|
---|
56 | try { xmlHttp = new XMLHttpRequest(); }
|
---|
57 | catch(e)
|
---|
58 | {
|
---|
59 | alert("Your browser doesn't support dynamic reload.");
|
---|
60 | return;
|
---|
61 | }
|
---|
62 |
|
---|
63 | xmlHttp.open('POST', name+'.table', true);
|
---|
64 |
|
---|
65 | xmlHttp.onreadystatechange =
|
---|
66 | function ()
|
---|
67 | {
|
---|
68 | if (xmlHttp.readyState == 4)
|
---|
69 | {
|
---|
70 | if (xmlHttp.status!=0 && xmlHttp.status!=200)
|
---|
71 | {
|
---|
72 | alert("ERROR[0] - HTTP request '"+name+".table': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
73 | //setTimeout("loadPage('+name+')", 5000);
|
---|
74 | /****** invalidate ******/
|
---|
75 | return;
|
---|
76 | }
|
---|
77 |
|
---|
78 | buildPage(name, xmlHttp.responseText, (z+1)%2);
|
---|
79 | changePage(z);
|
---|
80 |
|
---|
81 | //changePage(name, xmlHttp.resposeText);
|
---|
82 | //slideOut(name, xmlHttp.responseText);
|
---|
83 | //displayPage(name, xmlHttp.responseText);
|
---|
84 | //onresize(true);
|
---|
85 | }
|
---|
86 | };
|
---|
87 |
|
---|
88 | xmlHttp.send(null);
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | function buildPage(name, text, z)
|
---|
93 | {
|
---|
94 | var table = $("table"+z);
|
---|
95 | var p = table.tBodies.length==3 ? 1 : 0;
|
---|
96 |
|
---|
97 | var tbody = $("table"+z).tBodies[p];
|
---|
98 |
|
---|
99 | while (tbody.hasChildNodes())
|
---|
100 | tbody.removeChild(tbody.lastChild);
|
---|
101 |
|
---|
102 | var lines = text.split('\n');
|
---|
103 |
|
---|
104 | if (lines.length>0)
|
---|
105 | {
|
---|
106 | /*
|
---|
107 | var newe = document.createElement("span");
|
---|
108 | newe.innerHTML = lines[0];
|
---|
109 | var title = $("table"+z).tHead.rows[0].cells[0].childNodes[0].childNodes[1];
|
---|
110 | title.replaceChild(newe, title.lastChild);
|
---|
111 | */
|
---|
112 |
|
---|
113 | //var x = title.lastChild;
|
---|
114 | //title.removeChild(title.lastChild);
|
---|
115 | //title.appendChild(newe);
|
---|
116 |
|
---|
117 | var newe = document.createElement("span");
|
---|
118 | newe.innerHTML = lines[0];
|
---|
119 | var title = $("title"+z);//.innerHtml = lines[0];
|
---|
120 | title.replaceChild(newe, title.lastChild);
|
---|
121 | }
|
---|
122 |
|
---|
123 | var counter = 1;
|
---|
124 | for (var i=1; i<lines.length; i++)
|
---|
125 | {
|
---|
126 | lines[i] = trim(lines[i]);
|
---|
127 |
|
---|
128 | if (lines[i].length==0 || lines[i][0] == '#')
|
---|
129 | continue;
|
---|
130 |
|
---|
131 | var cols = lines[i].split(':');
|
---|
132 | if (cols.length != 3 && cols.length !=4)
|
---|
133 | {
|
---|
134 | alert("Size mismatch #"+i+": '"+lines[i]+"' N(cols)="+cols.length);
|
---|
135 | continue;
|
---|
136 | }
|
---|
137 |
|
---|
138 | if (cols[1].substring(0, 7)=="canvas=")
|
---|
139 | {
|
---|
140 | var tr = document.createElement("tr");
|
---|
141 | tr.setAttribute("class", "row");
|
---|
142 | tr.setAttribute("style", "margin:0;padding:0;");
|
---|
143 |
|
---|
144 | var td = document.createElement("td");
|
---|
145 | td.setAttribute("class", "container");
|
---|
146 | td.setAttribute("id", "container");
|
---|
147 | //td.setAttribute("onclick", "save();");
|
---|
148 | td.setAttribute("colspan", "3");
|
---|
149 | tr.appendChild(td);
|
---|
150 |
|
---|
151 | var canv = document.createElement("canvas");
|
---|
152 | canv.setAttribute("id", "canvas"+z);
|
---|
153 | canv.setAttribute("width", "1");
|
---|
154 | canv.setAttribute("height", "1");
|
---|
155 | canv.setAttribute("data-file", cols[1].substring(7));
|
---|
156 | canv.setAttribute("style", "display:none;");
|
---|
157 | td.appendChild(canv);
|
---|
158 |
|
---|
159 | var img = document.createElement("img");
|
---|
160 | img.setAttribute("id", "image"+z);
|
---|
161 | img.setAttribute("width", "1");
|
---|
162 | img.setAttribute("height", "1");
|
---|
163 | td.appendChild(img);
|
---|
164 |
|
---|
165 | tbody.appendChild(tr);
|
---|
166 | continue;
|
---|
167 | }
|
---|
168 |
|
---|
169 | var tr = document.createElement("tr");
|
---|
170 | tr.setAttribute("class", "row");
|
---|
171 | if (valid(cols[0]))
|
---|
172 | tr.setAttribute("onclick", "this.style.background='#ccb'; loadPage('"+cols[0]+"',"+z+");");
|
---|
173 | if (valid(cols[3]))
|
---|
174 | tr.setAttribute("onclick", "this.style.background='#ccb'; loadPage('"+cols[3]+"',"+z+");");
|
---|
175 | //tr.setAttribute("id", cols[0]+"_row");
|
---|
176 |
|
---|
177 | var td0 = document.createElement("td");
|
---|
178 | td0.setAttribute("class", "tcol0");
|
---|
179 | if (valid(cols[0]))
|
---|
180 | td0.appendChild(document.createTextNode("<"));
|
---|
181 | tr.appendChild(td0);
|
---|
182 |
|
---|
183 | var td1 = document.createElement("td");
|
---|
184 | td1.setAttribute("class", "tcol1");
|
---|
185 | td1.setAttribute("width", "100%");
|
---|
186 | tr.appendChild(td1);
|
---|
187 |
|
---|
188 | var td2 = document.createElement("td");
|
---|
189 | td2.setAttribute("class", "tcol2");
|
---|
190 | if (valid(cols[3]))
|
---|
191 | td2.appendChild(document.createTextNode(">"));
|
---|
192 | tr.appendChild(td2);
|
---|
193 |
|
---|
194 | var tab = document.createElement("table");
|
---|
195 | tab.setAttribute("width", "100%");
|
---|
196 | td1.appendChild(tab);
|
---|
197 |
|
---|
198 | var innertr = document.createElement("tr");
|
---|
199 | tab.appendChild(innertr);
|
---|
200 |
|
---|
201 | var cell1 = document.createElement("td");
|
---|
202 | cell1.setAttribute("class", "tcell1");
|
---|
203 | //cell1.setAttribute("id", cols[0]+"_title");
|
---|
204 | cell1.appendChild(document.createTextNode(cols[1]));
|
---|
205 |
|
---|
206 | var cell2 = document.createElement("td");
|
---|
207 | cell2.setAttribute("class", "tcell2");
|
---|
208 | cell2.setAttribute("id", "data"+counter);
|
---|
209 | cell2.setAttribute("data-form", cols[2]);
|
---|
210 | cell2.appendChild(document.createTextNode("---"));
|
---|
211 |
|
---|
212 | innertr.appendChild(cell1);
|
---|
213 | innertr.appendChild(cell2);
|
---|
214 |
|
---|
215 | tbody.appendChild(tr);
|
---|
216 |
|
---|
217 | counter++;
|
---|
218 | }
|
---|
219 |
|
---|
220 | // ---------------------------------------
|
---|
221 |
|
---|
222 | tr = document.createElement("tr");
|
---|
223 | tr.setAttribute("class", "row");
|
---|
224 |
|
---|
225 | td = document.createElement("td");
|
---|
226 | td.setAttribute("id", "debug");
|
---|
227 | td.setAttribute("colspan", "3");
|
---|
228 | tr.appendChild(td);
|
---|
229 |
|
---|
230 | tbody.appendChild(tr);
|
---|
231 |
|
---|
232 | // ---------------------------------------
|
---|
233 |
|
---|
234 | table.setAttribute("data-file", name);
|
---|
235 | doresize(z);
|
---|
236 | }
|
---|
237 |
|
---|
238 | function doresize(z)
|
---|
239 | {
|
---|
240 | var img = $("image"+z);
|
---|
241 | var canv = $("canvas"+z);
|
---|
242 | if (img == undefined || canv == undefined)
|
---|
243 | return;
|
---|
244 |
|
---|
245 | var h = $("table"+z).offsetHeight;
|
---|
246 | if (h == 0)
|
---|
247 | return;
|
---|
248 |
|
---|
249 | var W = window.innerWidth;
|
---|
250 | var H = window.innerHeight;
|
---|
251 |
|
---|
252 | var ih = img.height + H - h;
|
---|
253 |
|
---|
254 | img.style.width = W +"px";
|
---|
255 | img.style.height= ih+"px";
|
---|
256 |
|
---|
257 | canv.width = W;
|
---|
258 | canv.height = ih;
|
---|
259 |
|
---|
260 | // ------ debug -----
|
---|
261 | $('debug').innerHTML = "";
|
---|
262 | $('debug').innerHTML += "|W="+W +"/"+H;
|
---|
263 | $('debug').innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight;
|
---|
264 | $('debug').innerHTML += "|I="+ih;
|
---|
265 | }
|
---|
266 |
|
---|
267 | var intervalSlide = null;
|
---|
268 |
|
---|
269 | function changePage(z)
|
---|
270 | {
|
---|
271 | // No page displayed yet
|
---|
272 | if ($("table0").style.display=="none" && $("table1").style.display=="none")
|
---|
273 | {
|
---|
274 | $("table0").style.display="";
|
---|
275 | $("table1").style.display="";
|
---|
276 |
|
---|
277 | $("table0").style.left=window.innerWidth+"px";
|
---|
278 | $("table1").style.left="0px";
|
---|
279 |
|
---|
280 | $("body").setAttribute("data-visible", "1");
|
---|
281 |
|
---|
282 | doresize(1);
|
---|
283 |
|
---|
284 | refresh_text();
|
---|
285 | refresh_graphics();
|
---|
286 | return;
|
---|
287 | }
|
---|
288 |
|
---|
289 | //intervalSlide = setInterval("doSlideOut("+z+")", 25);
|
---|
290 |
|
---|
291 | //var k = (z+1)%2;
|
---|
292 | //$("table"+k).style.display="";
|
---|
293 | //$("table"+z).style.display="";
|
---|
294 | //$("table"+k).style.zIndex="0";
|
---|
295 | //$("table"+z).style.zIndex="1";
|
---|
296 | //$("table"+k).style.left=0;
|
---|
297 | //$("table"+z).style.left=0;
|
---|
298 | //$("table"+k).style.backgroundColor = "#ffffff";
|
---|
299 | //$("table"+z).style.backgroundColor = "#ffffff";
|
---|
300 | //doresize(k);
|
---|
301 | //intervalSlide = setInterval("doSlide("+z+",1)", 50);
|
---|
302 |
|
---|
303 | $("body").setAttribute("data-visible", (z+1)%2);
|
---|
304 | intervalSlide = setInterval("doShift("+z+")", 75);
|
---|
305 | }
|
---|
306 |
|
---|
307 | function doShift(z)
|
---|
308 | {
|
---|
309 | var W = window.innerWidth;
|
---|
310 |
|
---|
311 | var t0 = $("table0");
|
---|
312 | var t1 = $("table1");
|
---|
313 |
|
---|
314 | var x0 = t0.offsetLeft;
|
---|
315 | var x1 = t1.offsetLeft;
|
---|
316 |
|
---|
317 | if (/*x1<0 && x0>=0 &&*/ z==0)
|
---|
318 | {
|
---|
319 | x0 += W/5;
|
---|
320 | x1 += W/5;
|
---|
321 |
|
---|
322 | if (x1>=0)
|
---|
323 | {
|
---|
324 | x0 = W;
|
---|
325 | x1 = 0;
|
---|
326 |
|
---|
327 | clearInterval(intervalSlide);
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | if (/*x0>0 && x1<=0 &&*/ z==1)
|
---|
332 | {
|
---|
333 | x0 -= W/5;
|
---|
334 | x1 -= W/5;
|
---|
335 |
|
---|
336 | if (x0<=0)
|
---|
337 | {
|
---|
338 | x0 = 0;
|
---|
339 | x1 = -W-1;
|
---|
340 |
|
---|
341 | clearInterval(intervalSlide);
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | t0.style.left = parseInt(x0, 10)+"px";
|
---|
346 | t1.style.left = parseInt(x1, 10)+"px";
|
---|
347 | }
|
---|
348 |
|
---|
349 | /*
|
---|
350 | function doSlide(z, dir)
|
---|
351 | {
|
---|
352 | var k = (z+1)%2;
|
---|
353 |
|
---|
354 | var W = window.innerWidth;
|
---|
355 |
|
---|
356 | var tz = $("table"+z);
|
---|
357 | var tk = $("table"+k);
|
---|
358 |
|
---|
359 | var xz = tz.offsetLeft;
|
---|
360 | var xk = tk.offsetLeft;
|
---|
361 |
|
---|
362 | var ixz = parseInt(xz, 10);
|
---|
363 | var ikz = parseInt(xk, 10);
|
---|
364 |
|
---|
365 | ixz += dir*W/10;
|
---|
366 | ikz -= dir*W/10;
|
---|
367 |
|
---|
368 | tz.style.left = parseInt(ixz, 10)+"px";
|
---|
369 | tk.style.left = parseInt(ikz, 10)+"px";
|
---|
370 |
|
---|
371 | if (ixz>W/2)
|
---|
372 | {
|
---|
373 | clearInterval(intervalSlide);
|
---|
374 |
|
---|
375 | $("table"+k).style.zIndex="1";
|
---|
376 | $("table"+z).style.zIndex="0";
|
---|
377 |
|
---|
378 | $("body").setAttribute("data-visible", k);
|
---|
379 | doresize(k);
|
---|
380 |
|
---|
381 | intervalSlide = setInterval("doSlide("+z+",-1)", 50);
|
---|
382 | }
|
---|
383 | if (ikz>0)
|
---|
384 | {
|
---|
385 | clearInterval(intervalSlide);
|
---|
386 |
|
---|
387 | tz.style.left = 0;
|
---|
388 | tk.style.left = 0;
|
---|
389 |
|
---|
390 | tz.style.display="none";
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 |
|
---|
395 | function doSlideOut(z)
|
---|
396 | {
|
---|
397 | var table = $("table"+z);
|
---|
398 |
|
---|
399 | var W = window.innerWidth;
|
---|
400 | var x = table.offsetLeft;
|
---|
401 |
|
---|
402 | var ix = parseInt(x, 10);
|
---|
403 | if (ix>W)
|
---|
404 | {
|
---|
405 | clearInterval(intervalSlide);
|
---|
406 |
|
---|
407 | table.style.display="none";
|
---|
408 |
|
---|
409 | z = (z+1)%2;
|
---|
410 | table = $("table"+z);
|
---|
411 |
|
---|
412 | table.style.display="";
|
---|
413 | table.style.left = window.innerWidth+"px";
|
---|
414 |
|
---|
415 | $("body").setAttribute("data-visible", z);
|
---|
416 | doresize(z);
|
---|
417 |
|
---|
418 | intervalSlide = setInterval("doSlideIn("+z+")", 25);
|
---|
419 | return;
|
---|
420 | }
|
---|
421 |
|
---|
422 | ix += W/10;
|
---|
423 | table.style.left=ix+"px";
|
---|
424 | }
|
---|
425 |
|
---|
426 | function doSlideIn(z)
|
---|
427 | {
|
---|
428 | var table = $("table"+z);
|
---|
429 |
|
---|
430 | var W = window.innerWidth;
|
---|
431 | var x = table.offsetLeft;
|
---|
432 |
|
---|
433 | var ix = parseInt(x, 10);
|
---|
434 |
|
---|
435 | ix -= W/10;
|
---|
436 | if (ix<0)
|
---|
437 | ix = 0;
|
---|
438 |
|
---|
439 | table.style.left=ix+"px";
|
---|
440 |
|
---|
441 | if (ix<=0)
|
---|
442 | {
|
---|
443 | clearInterval(intervalSlide);
|
---|
444 | return;
|
---|
445 | }
|
---|
446 | }
|
---|
447 | */
|
---|
448 |
|
---|
449 | function refresh_text()
|
---|
450 | {
|
---|
451 | var z=$("body").getAttribute("data-visible");
|
---|
452 | var table = $("table"+z);
|
---|
453 |
|
---|
454 | // Is sliding or no file defined?
|
---|
455 | var fname = table.getAttribute("data-file");
|
---|
456 | if (isSliding() || !valid(fname))
|
---|
457 | {
|
---|
458 | setTimeout("refresh_text()", 1000);
|
---|
459 | return;
|
---|
460 | }
|
---|
461 |
|
---|
462 | var xmlHttp = null;
|
---|
463 |
|
---|
464 | try { xmlHttp = new XMLHttpRequest(); }
|
---|
465 | catch(e)
|
---|
466 | {
|
---|
467 | alert("Your browser doesn't support dynamic reload.");
|
---|
468 | return;
|
---|
469 | }
|
---|
470 |
|
---|
471 | xmlHttp.open('POST', fname+'.txt', true);
|
---|
472 |
|
---|
473 | xmlHttp.onreadystatechange =
|
---|
474 | function ()
|
---|
475 | {
|
---|
476 | if (xmlHttp.readyState == 4)
|
---|
477 | {
|
---|
478 | if (xmlHttp.status!=0 && xmlHttp.status!=200)
|
---|
479 | {
|
---|
480 | alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
481 | setTimeout("refresh_text()", 10000);
|
---|
482 | return;
|
---|
483 | }
|
---|
484 |
|
---|
485 | if (!isSliding())
|
---|
486 | {
|
---|
487 | cycleCol($("ldot"+z));
|
---|
488 | update_text(fname, xmlHttp.responseText);
|
---|
489 | }
|
---|
490 | setTimeout("refresh_text()", 3000);
|
---|
491 | }
|
---|
492 | };
|
---|
493 |
|
---|
494 | xmlHttp.send(null);
|
---|
495 | }
|
---|
496 |
|
---|
497 | function strike(e, status)
|
---|
498 | {
|
---|
499 | if (!e)
|
---|
500 | return;
|
---|
501 |
|
---|
502 | if (!status)
|
---|
503 | e.style.textDecoration="line-through";
|
---|
504 | else
|
---|
505 | e.style.textDecoration="";
|
---|
506 | }
|
---|
507 |
|
---|
508 | function gray(id, str)
|
---|
509 | {
|
---|
510 | var e = $(id);
|
---|
511 | if (!e)
|
---|
512 | return;
|
---|
513 |
|
---|
514 | if (valid(str))
|
---|
515 | {
|
---|
516 | e.style.color="#000";
|
---|
517 | e.style.textDecoration="";
|
---|
518 | }
|
---|
519 | else
|
---|
520 | {
|
---|
521 | e.style.color="#daa";
|
---|
522 | e.style.textDecoration="line-through";
|
---|
523 | }
|
---|
524 |
|
---|
525 | }
|
---|
526 |
|
---|
527 | var date0 = null;
|
---|
528 |
|
---|
529 | function update_text(fname, result)
|
---|
530 | {
|
---|
531 | var z=$("body").getAttribute("data-visible");
|
---|
532 | var table = $("table"+z);
|
---|
533 |
|
---|
534 | if (table.getAttribute("data-file") != fname)
|
---|
535 | return;
|
---|
536 |
|
---|
537 | var tokens = result.split('\n');
|
---|
538 |
|
---|
539 | // ----------------------------------------------------
|
---|
540 |
|
---|
541 | var time = $("reporttime"+z);
|
---|
542 | var ltime = $("localtime"+z);
|
---|
543 |
|
---|
544 | var date1 = new Date();
|
---|
545 |
|
---|
546 | if (tokens[0].length!=13)
|
---|
547 | {
|
---|
548 | if (date0 != null)
|
---|
549 | strike(time, date0.getTime()+60000>date1.getTime());
|
---|
550 | // FIXME: Reset display to "---" values -- no connection
|
---|
551 | return;
|
---|
552 | }
|
---|
553 |
|
---|
554 | var date2 = new Date();
|
---|
555 | date2.setTime(tokens[0]);
|
---|
556 |
|
---|
557 | strike(time, date2.getTime()+60000>date1.getTime());
|
---|
558 |
|
---|
559 | date0 = date2;
|
---|
560 |
|
---|
561 | time.innerHTML =
|
---|
562 | "• "+date0.toUTCString()+" •";//getUTCFullYear()+"/"+date0.getUTCMonth()+"/"+date0.getUTCDate()+" "+date0.getUTCHours()+":"+date0.getUTCMinutes()+":"+date0.getUTCSeconds()+"."+date0.getUTCMilliseconds();
|
---|
563 | ltime.innerHTML =
|
---|
564 | "• "+date1.toLocaleString()+" •";//ISOlocalDateStr();//ltoString();
|
---|
565 |
|
---|
566 | // ----------------------------------------------------
|
---|
567 |
|
---|
568 | var p = table.tBodies.length==3 ? 1 : 0;
|
---|
569 | var tbody = table.tBodies[p];
|
---|
570 |
|
---|
571 | for (var line=1; line<tokens.length; line++)
|
---|
572 | {
|
---|
573 | var c = tbody.rows[line-1].cells[1];
|
---|
574 | if (c == undefined)
|
---|
575 | continue;
|
---|
576 |
|
---|
577 | var e = c.childNodes[0].rows[0].cells[1];
|
---|
578 | if (e == undefined)
|
---|
579 | continue;
|
---|
580 |
|
---|
581 | var form = e.getAttribute("data-form");
|
---|
582 | if (form==undefined)
|
---|
583 | continue;
|
---|
584 |
|
---|
585 | var cols = tokens[line].split('\t');
|
---|
586 | for (var col=1; col<cols.length; col++)
|
---|
587 | form = form.replace("\$"+(col-1), cols[col].length==0 ? "--" : cols[col]);
|
---|
588 |
|
---|
589 | if (cols.length<=1)
|
---|
590 | form = "---";
|
---|
591 |
|
---|
592 | var newe = document.createElement("div");
|
---|
593 | newe.innerHTML = form;
|
---|
594 | e.replaceChild(newe, e.lastChild);
|
---|
595 |
|
---|
596 | e.parentNode.parentNode.parentNode.parentNode.style.background=cols[0];
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | // http://billmill.org/static/canvastutorial/index.html
|
---|
601 | // http://www.netmagazine.com/tutorials/learning-basics-html5-canvas
|
---|
602 | // http://www.alistapart.com/articles/responsive-web-design/
|
---|
603 |
|
---|
604 | function refresh_graphics()
|
---|
605 | {
|
---|
606 | var z = $("body").getAttribute("data-visible");
|
---|
607 |
|
---|
608 | var canvas = $("canvas"+z);
|
---|
609 |
|
---|
610 | // Is sliding or no data file defined?
|
---|
611 | var fname = canvas==null ? "" : canvas.getAttribute("data-file");
|
---|
612 | if (isSliding() || !valid(fname))
|
---|
613 | {
|
---|
614 | setTimeout("refresh_graphics()", 1000);
|
---|
615 | return;
|
---|
616 | }
|
---|
617 |
|
---|
618 | var xmlHttp = null;
|
---|
619 |
|
---|
620 | try { xmlHttp = new XMLHttpRequest(); }
|
---|
621 | catch(e)
|
---|
622 | {
|
---|
623 | alert("Your browser doesn't support dynamic reload.");
|
---|
624 | return;
|
---|
625 | }
|
---|
626 |
|
---|
627 | xmlHttp.open('POST', fname, true);
|
---|
628 | xmlHttp.onload =
|
---|
629 | function ()
|
---|
630 | {
|
---|
631 | if (xmlHttp.readyState == 4)
|
---|
632 | {
|
---|
633 | if (xmlHttp.status!=0 && xmlHttp.status!=200)
|
---|
634 | {
|
---|
635 | alert("ERROR[2] - Request '"+fname+"': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
636 | setTimeout("refresh_text()", 10000);
|
---|
637 | //****** invalidate ******
|
---|
638 | return;
|
---|
639 | }
|
---|
640 |
|
---|
641 | if (!isSliding())
|
---|
642 | {
|
---|
643 | cycleCol($("rdot"+z));
|
---|
644 | process_eventdata(xmlHttp.responseText);
|
---|
645 | }
|
---|
646 | setTimeout("refresh_graphics()", 5000)
|
---|
647 | }
|
---|
648 | };
|
---|
649 |
|
---|
650 | xmlHttp.send(null);
|
---|
651 | }
|
---|
652 |
|
---|
653 |
|
---|
654 | function hueToRGB(hue)
|
---|
655 | {
|
---|
656 | hue /= 3;
|
---|
657 | hue %= 6;
|
---|
658 |
|
---|
659 | if (hue<1) return parseInt(255*hue, 10);
|
---|
660 | if (hue<3) return parseInt(255, 10);
|
---|
661 | if (hue<4) return parseInt(255*(4-hue), 10);
|
---|
662 |
|
---|
663 | /*
|
---|
664 | if (hue<1*5/4) return parseInt(255*hue*4/5);
|
---|
665 | if (hue<2*5/4) return parseInt(255);
|
---|
666 | if (hue<3*5/4) return parseInt(255*(3*5/4-hue)*4/5);
|
---|
667 | */
|
---|
668 | /*
|
---|
669 | if (hue<1.5) return parseInt(255*hue/1.5);
|
---|
670 | if (hue<3.0) return parseInt(255);
|
---|
671 | if (hue<4.5) return parseInt(255*(4.5-hue)/1.5);
|
---|
672 | */
|
---|
673 | return 0.
|
---|
674 | }
|
---|
675 |
|
---|
676 | function hueToHex(flt)
|
---|
677 | {
|
---|
678 | var s = hueToRGB(flt).toString(16);
|
---|
679 | return s.length==2 ? s : "0"+s;
|
---|
680 | }
|
---|
681 |
|
---|
682 | function HLStoRGB(hue)
|
---|
683 | {
|
---|
684 | hue *= 14;
|
---|
685 |
|
---|
686 | var sr = hueToHex(20-hue);
|
---|
687 | var sg = hueToHex(14-hue);
|
---|
688 | var sb = hueToHex(26-hue);
|
---|
689 |
|
---|
690 | return sr+sg+sb;
|
---|
691 | }
|
---|
692 |
|
---|
693 |
|
---|
694 | function color(col)
|
---|
695 | {
|
---|
696 | if (col==65533)
|
---|
697 | col = 0;
|
---|
698 |
|
---|
699 | var hue = col/128;
|
---|
700 | return HLStoRGB(hue);
|
---|
701 | }
|
---|
702 |
|
---|
703 | function toHex(str, idx)
|
---|
704 | {
|
---|
705 | var ch = str[idx].toString(16);
|
---|
706 | return ch.length==2 ? ch : "0"+ch;
|
---|
707 | }
|
---|
708 |
|
---|
709 | function drawHex(ctx, x, y, col)
|
---|
710 | {
|
---|
711 | ctx.fillStyle = "#"+color(col);
|
---|
712 |
|
---|
713 | ctx.save();
|
---|
714 |
|
---|
715 | ctx.translate(x, y);
|
---|
716 | ctx.scale(1/2, 1/3);
|
---|
717 |
|
---|
718 | ctx.beginPath();
|
---|
719 | ctx.moveTo( 1, 1);
|
---|
720 | ctx.lineTo( 0, 2);
|
---|
721 | ctx.lineTo(-1, 1);
|
---|
722 | ctx.lineTo(-1, -1);
|
---|
723 | ctx.lineTo( 0, -2);
|
---|
724 | ctx.lineTo( 1, -1);
|
---|
725 | ctx.fill();
|
---|
726 |
|
---|
727 | ctx.restore();
|
---|
728 | }
|
---|
729 |
|
---|
730 | function drawDisc(ctx, x, y, r, col)
|
---|
731 | {
|
---|
732 | ctx.fillStyle = "#"+color(col);
|
---|
733 |
|
---|
734 | ctx.save();
|
---|
735 |
|
---|
736 | ctx.translate(x, y);
|
---|
737 |
|
---|
738 | ctx.beginPath();
|
---|
739 | ctx.arc(0, 0, r, 0, Math.PI*2, true);
|
---|
740 | ctx.fill();
|
---|
741 |
|
---|
742 | ctx.restore();
|
---|
743 | }
|
---|
744 |
|
---|
745 | function beginDrawCam(scale)
|
---|
746 | {
|
---|
747 | var z = $("body").getAttribute("data-visible");
|
---|
748 | var canv = $("canvas"+z);
|
---|
749 |
|
---|
750 | var w = Math.min(canv.width/scale, canv.height/scale);
|
---|
751 |
|
---|
752 | var ctx = canv.getContext("2d");
|
---|
753 |
|
---|
754 | ctx.save();
|
---|
755 | ctx.translate(canv.width/2, canv.height/2);
|
---|
756 | ctx.scale(w*2, w*2);
|
---|
757 |
|
---|
758 | return ctx;
|
---|
759 | }
|
---|
760 |
|
---|
761 | function drawFullCam(data)
|
---|
762 | {
|
---|
763 | var ctx = beginDrawCam(80);
|
---|
764 | ctx.rotate(Math.PI/2);
|
---|
765 | ctx.scale(1, Math.sqrt(3)/2);
|
---|
766 |
|
---|
767 | drawHex(ctx, -0.5, 0, data.charCodeAt(0));
|
---|
768 |
|
---|
769 | var cnt = 1;
|
---|
770 | for (var ring=1; ring<24; ring++)
|
---|
771 | {
|
---|
772 | for (var s=0; s<6; s++)
|
---|
773 | {
|
---|
774 | for (var i=1; i<=ring; i++)
|
---|
775 | {
|
---|
776 | var x=0.;
|
---|
777 | var y=0.;
|
---|
778 |
|
---|
779 | switch (s)
|
---|
780 | {
|
---|
781 | case 0: x = ring - i*0.5; y = + i; break;
|
---|
782 | case 1: x = ring*0.5 - i; y = ring ; break;
|
---|
783 | case 2: x = -ring*0.5 - i*0.5; y = ring - i; break;
|
---|
784 | case 3: x = -ring + i*0.5; y = - i; break;
|
---|
785 | case 4: x = -ring*0.5 + i; y = -ring ; break;
|
---|
786 | case 5: x = ring*0.5 + i*0.5; y = -ring + i; break;
|
---|
787 | }
|
---|
788 |
|
---|
789 | if (x*x + y*y*3/4 - x < 395.75)
|
---|
790 | drawHex(ctx, x-0.5, -y, data.charCodeAt(cnt++));
|
---|
791 | }
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | drawHex(ctx, -6.5, 22, data.charCodeAt(1438));
|
---|
796 | drawHex(ctx, -6.5, -22, data.charCodeAt(1439));
|
---|
797 |
|
---|
798 | ctx.restore();
|
---|
799 | }
|
---|
800 |
|
---|
801 | function drawCam(data)
|
---|
802 | {
|
---|
803 | var ctx = beginDrawCam(27);
|
---|
804 | ctx.rotate(Math.PI/6);
|
---|
805 | ctx.scale(1, Math.sqrt(3)/2);
|
---|
806 |
|
---|
807 | drawHex(ctx, 0, 0, data.charCodeAt(0));
|
---|
808 |
|
---|
809 | var cnt = 1;
|
---|
810 | for (var ring=1; ring<=7; ring++)
|
---|
811 | {
|
---|
812 | for (var s=0; s<6; s++)
|
---|
813 | {
|
---|
814 | for (var i=1; i<=ring; i++)
|
---|
815 | {
|
---|
816 | var x=0.;
|
---|
817 | var y=0.;
|
---|
818 |
|
---|
819 | switch (s)
|
---|
820 | {
|
---|
821 | case 0: x = ring - i*0.5; y = + i; break;
|
---|
822 | case 1: x = ring*0.5 - i; y = ring ; break;
|
---|
823 | case 2: x = -ring*0.5 - i*0.5; y = ring - i; break;
|
---|
824 | case 3: x = -ring + i*0.5; y = - i; break;
|
---|
825 | case 4: x = -ring*0.5 + i; y = -ring ; break;
|
---|
826 | case 5: x = ring*0.5 + i*0.5; y = -ring + i; break;
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (x*x + y*y*3/4 > 44)
|
---|
830 | continue;
|
---|
831 |
|
---|
832 | if (ring==7 && i==6 && s==0)
|
---|
833 | continue;
|
---|
834 | if (ring==7 && i==1 && s==1)
|
---|
835 | continue;
|
---|
836 | if (ring==7 && i==6 && s==3)
|
---|
837 | continue;
|
---|
838 | if (ring==7 && i==1 && s==4)
|
---|
839 | continue;
|
---|
840 |
|
---|
841 | drawHex(ctx, x, y, data.charCodeAt(cnt++));
|
---|
842 | }
|
---|
843 | }
|
---|
844 | }
|
---|
845 |
|
---|
846 | ctx.restore();
|
---|
847 | }
|
---|
848 |
|
---|
849 | function drawCamLegend(canv)
|
---|
850 | {
|
---|
851 | var cw = canv.width;
|
---|
852 | var ch = canv.height;
|
---|
853 |
|
---|
854 | var ctx = canv.getContext("2d");
|
---|
855 |
|
---|
856 | ctx.font = "8pt Arial";
|
---|
857 | ctx.textAlign = "right";
|
---|
858 | ctx.textBaseline = "top";
|
---|
859 |
|
---|
860 | ctx.strokeStyle = "#"+color(0);
|
---|
861 | ctx.strokeText("-2.0V", cw-5, 135);
|
---|
862 |
|
---|
863 | ctx.strokeStyle = "#"+color(16);
|
---|
864 | ctx.strokeText("-1.5V", cw-5, 120);
|
---|
865 |
|
---|
866 | ctx.strokeStyle = "#"+color(32);
|
---|
867 | ctx.strokeText("-1.0V", cw-5, 105);
|
---|
868 |
|
---|
869 | ctx.strokeStyle = "#"+color(48);
|
---|
870 | ctx.strokeText("-0.5V", cw-5, 90);
|
---|
871 |
|
---|
872 | ctx.strokeStyle = "#"+color(64);
|
---|
873 | ctx.strokeText("0V", cw-5, 70);
|
---|
874 |
|
---|
875 | ctx.strokeStyle = "#"+color(80);
|
---|
876 | ctx.strokeText("0.5V", cw-5, 50);
|
---|
877 |
|
---|
878 | ctx.strokeStyle = "#"+color(86);
|
---|
879 | ctx.strokeText("1.0V", cw-5, 35);
|
---|
880 |
|
---|
881 | ctx.strokeStyle = "#"+color(102);
|
---|
882 | ctx.strokeText("1.5V", cw-5, 20);
|
---|
883 |
|
---|
884 | ctx.strokeStyle = "#"+color(127);
|
---|
885 | ctx.strokeText("2.0V", cw-5, 5);
|
---|
886 | }
|
---|
887 |
|
---|
888 | function drawGraph(canv, data)
|
---|
889 | {
|
---|
890 | var cw = canv.width;
|
---|
891 | var ch = canv.height;
|
---|
892 |
|
---|
893 | var ctx = canv.getContext("2d");
|
---|
894 |
|
---|
895 | var dx = 15;
|
---|
896 | var dy = 15;
|
---|
897 |
|
---|
898 | var dw = 5;
|
---|
899 |
|
---|
900 | var nx = 20;
|
---|
901 | var ny = 10;
|
---|
902 |
|
---|
903 | var w = cw-2*dx;
|
---|
904 | var h = ch-2*dy;
|
---|
905 |
|
---|
906 | ctx.strokeStyle = "#808080";
|
---|
907 |
|
---|
908 | ctx.beginPath();
|
---|
909 | ctx.moveTo(dx, ch-dy-data.charCodeAt(0)/128*h);
|
---|
910 | for (var i=1; i<data.length; i++)
|
---|
911 | ctx.lineTo(dx+w/data.length*i, ch-dy-data.charCodeAt(i)/128*h);
|
---|
912 | ctx.lineTo(dx+w, ch-dy);
|
---|
913 | ctx.lineTo(dx, ch-dy);
|
---|
914 | ctx.fillStyle = "#"+color(100);
|
---|
915 | ctx.fill();
|
---|
916 | ctx.stroke();
|
---|
917 | ctx.closePath();
|
---|
918 |
|
---|
919 | ctx.strokeStyle = "#000000";
|
---|
920 |
|
---|
921 | ctx.beginPath();
|
---|
922 |
|
---|
923 | ctx.moveTo(dx, dy);
|
---|
924 | ctx.lineTo(dx, ch-dy);
|
---|
925 | ctx.lineTo(cw-dx, ch-dy);
|
---|
926 |
|
---|
927 | for (var i=0; i<nx; i++)
|
---|
928 | {
|
---|
929 | ctx.moveTo(dx+w/nx*i, ch-dy-dw);
|
---|
930 | ctx.lineTo(dx+w/nx*i, ch-dy+dw);
|
---|
931 | }
|
---|
932 | for (var i=0; i<ny; i++)
|
---|
933 | {
|
---|
934 | ctx.moveTo(dx-dw, dy+h/ny*i);
|
---|
935 | ctx.lineTo(dx+dw, dy+h/ny*i);
|
---|
936 | }
|
---|
937 | ctx.stroke();
|
---|
938 | ctx.closePath();
|
---|
939 | }
|
---|
940 |
|
---|
941 | function process_eventdata(result)
|
---|
942 | {
|
---|
943 | if (result.length!=160)
|
---|
944 | return;
|
---|
945 |
|
---|
946 | var z = $("body").getAttribute("data-visible");
|
---|
947 | var canv = $("canvas"+z);
|
---|
948 | if (canv == undefined)
|
---|
949 | return;
|
---|
950 |
|
---|
951 | var ctx = canv.getContext("2d");
|
---|
952 | ctx.clearRect(0, 0, canv.width, canv.height);
|
---|
953 |
|
---|
954 | // drawGraph(canv, result);
|
---|
955 |
|
---|
956 | // drawCam(result);
|
---|
957 | drawFullCam(result);
|
---|
958 | // drawFullCam(result);
|
---|
959 | // drawCamLegend(canv);
|
---|
960 |
|
---|
961 | $("image"+z).src = canv.toDataURL("image/png");
|
---|
962 | }
|
---|
963 |
|
---|
964 | /*
|
---|
965 | function save()
|
---|
966 | {
|
---|
967 | var z = $("body").getAttribute("data-visible");
|
---|
968 |
|
---|
969 | var canvas = $("canvas"+z);
|
---|
970 | var img = canvas.toDataURL("image/png");
|
---|
971 |
|
---|
972 | img = img.replace("image/png", "image/octet-stream");
|
---|
973 |
|
---|
974 | document.location.href = img;
|
---|
975 | }
|
---|
976 | */
|
---|
977 | window['onload'] = onload;
|
---|