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

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