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

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