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

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