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

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