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

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