Changeset 13664 for trunk/FACT++/www/index.js
- Timestamp:
- 05/12/12 00:03:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/www/index.js
r13642 r13664 189 189 function onload() 190 190 { 191 var xmlHttp = null; 192 193 try { xmlHttp = new XMLHttpRequest(); } 191 try { new XMLHttpRequest(); } 194 192 catch(e) 195 193 { … … 218 216 function loadPage(name, z, dz) 219 217 { 220 var xml Http= new XMLHttpRequest();221 xml Http.open('POST', name+'.table', true);222 xml Http.onload = function ()223 { 224 if (xml Http.status!=200)218 var xmlPage = new XMLHttpRequest(); 219 xmlPage.open('POST', name+'.table', true); 220 xmlPage.onload = function () 221 { 222 if (xmlPage.status!=200) 225 223 { 226 alert("ERROR[0] - HTTP request '"+name+".table': "+xml Http.statusText+" ["+xmlHttp.status+"]");224 alert("ERROR[0] - HTTP request '"+name+".table': "+xmlPage.statusText+" ["+xmlPage.status+"]"); 227 225 //setTimeout("loadPage('+name+')", 5000); 228 226 /****** invalidate ******/ … … 230 228 } 231 229 232 buildPage(name, xml Http.responseText, z, dz);230 buildPage(name, xmlPage.responseText, z, dz); 233 231 changePage(z, z+dz); 234 232 … … 239 237 }; 240 238 241 xml Http.send(null);239 xmlPage.send(null); 242 240 243 241 location.hash = name; … … 264 262 265 263 table = document.createElement("table"); 266 table.setAttribute("class", 267 table. setAttribute("id", "table"+z);268 table. setAttribute("border", "0");269 table. setAttribute("cellspacing", "0");270 table. setAttribute("cellpadding", "6");271 table. setAttribute("width", "100%");264 table.setAttribute("class", "tborder"); 265 table.id = "table"+z; 266 table.border = 0; 267 table.cellspacing = 0; 268 table.cellpadding = "6px"; 269 table.width = "100%"; 272 270 table.setAttribute("style", "overflow:hidden;position:fixed;top:0px;left:"+window.innerWidth+"px;"); 273 271 … … 275 273 276 274 var th = document.createElement("thead"); 277 th. setAttribute("colspan", "3");278 th. setAttribute("width", "100%");275 th.colSpan = 3; 276 th.width = "100%"; 279 277 table.appendChild(th); 280 278 … … 283 281 284 282 var htd = document.createElement("td"); 285 htd.setAttribute("class", 286 htd. setAttribute("colspan", "3");287 htd. setAttribute("width", "100%");283 htd.setAttribute("class", "thead"); 284 htd.colSpan = 3; 285 htd.width = "100%"; 288 286 htr.appendChild(htd); 289 287 … … 291 289 292 290 var htab = document.createElement("table"); 293 htab. setAttribute("width", "100%");291 htab.width = "100%"; 294 292 htd.appendChild(htab); 295 293 … … 327 325 var sp1 = document.createElement("span"); 328 326 var sp2 = document.createElement("span"); 329 sp0. setAttribute("id", "ldot" +z);330 sp1. setAttribute("id", "title"+z);331 sp2. setAttribute("id", "rdot" +z);327 sp0.id = "ldot" +z; 328 sp1.id = "title"+z; 329 sp2.id = "rdot" +z; 332 330 sp0.setAttribute("data-color", "3"); 333 331 sp2.setAttribute("data-color", "3"); … … 341 339 342 340 div1.setAttribute("style", "font-size:small;"); 343 div1. setAttribute("id", "reporttime"+z);341 div1.id = "reporttime"+z; 344 342 div1.appendChild(document.createTextNode("---")); 345 343 … … 366 364 var ftd = document.createElement("td"); 367 365 ftd.setAttribute("class", "tfoot"); 368 ftd. setAttribute("width", "100%");369 ftd. setAttribute("colspan", "3");366 ftd.width = "100%"; 367 ftd.colSpan = 3; 370 368 ftr.appendChild(ftd); 371 369 372 370 var ftab = document.createElement("table"); 373 ftab. setAttribute("width", "100%");371 ftab.width = "100%"; 374 372 ftd.appendChild(ftab); 375 373 … … 388 386 fdiv0.setAttribute("style", "font-size:x-large;"); 389 387 fdiv1.setAttribute("style", "font-size:small;"); 390 fdiv1. setAttribute("id", "localtime"+z);388 fdiv1.id = "localtime"+z; 391 389 392 390 fdiv0.appendChild(document.createTextNode("logbook")); … … 409 407 if (cols.length != 3 && cols.length !=4) 410 408 { 411 alert(" Size mismatch #"+i+": '"+lines[i]+"' N(cols)="+cols.length);409 alert("Wrong number of columns in line #"+i+" in '"+name+"': '"+lines[i]+"' N(cols)="+cols.length); 412 410 continue; 413 411 } … … 424 422 425 423 var td = document.createElement("td"); 426 td.setAttribute("class", "container"); 427 td.setAttribute("id", "container"); 428 //td.setAttribute("onclick", "save();"); 429 td.setAttribute("colspan", "3"); 424 td.setAttribute("class", "container"); 425 td.id = "container"; 426 td.colSpan = 3; 430 427 tr.appendChild(td); 431 428 432 429 var canv = document.createElement("canvas"); 433 canv.setAttribute("id", "canvas"+z); 434 canv.setAttribute("width", "1"); 435 canv.setAttribute("height", "1"); 430 canv.id = "canvas"+z; 431 canv.width = "1"; 432 canv.height = "1"; 433 //canv.onclick = function() { save(); } 436 434 canv.setAttribute("data-type", check[0]); 437 435 canv.setAttribute("data-file", data[0]); 438 436 canv.setAttribute("data-data", cols[1].substring(check[0].length+data[0].length+2)); 439 canv.setAttribute("style", "display:none;");437 // canv.setAttribute("style", "display:none;"); 440 438 td.appendChild(canv); 441 439 442 440 var img = document.createElement("img"); 443 441 img.src = "dummy.png";//needed in firefox 444 img. setAttribute("id", "image"+z);445 img.setAttribute("style", "width:1px;height:1px; ");442 img.id = "image"+z; 443 img.setAttribute("style", "width:1px;height:1px;display:none;"); 446 444 td.appendChild(img); 447 445 … … 471 469 var td1 = document.createElement("td"); 472 470 td1.setAttribute("class", "tcol1"); 473 td1. setAttribute("width", "100%");471 td1.width = "100%"; 474 472 tr.appendChild(td1); 475 473 476 474 var td2 = document.createElement("td"); 477 475 td2.setAttribute("class", "tcol2"); 478 td2. setAttribute("width", "18px");476 td2.width = "18px"; 479 477 if (valid(cols[3])) 480 478 { … … 487 485 488 486 var tab = document.createElement("table"); 489 tab. setAttribute("width", "100%");487 tab.width = "100%"; 490 488 td1.appendChild(tab); 491 489 … … 499 497 500 498 var cell2 = document.createElement("td"); 499 cell2.id = "data"+counter; 501 500 cell2.setAttribute("class", "tcell2"); 502 cell2.setAttribute("id", "data"+counter);503 501 cell2.setAttribute("data-form", cols[2]); 504 502 cell2.appendChild(document.createTextNode("---")); … … 515 513 if (debug == true) 516 514 { 517 518 515 tr = document.createElement("tr"); 519 516 tr.setAttribute("class", "row"); 520 517 521 518 td = document.createElement("td"); 522 td. setAttribute("id", "debug"+z);523 td. setAttribute("colspan", "3");519 td.id = "debug"+z; 520 td.colSpan = 3; 524 521 tr.appendChild(td); 525 522 … … 559 556 560 557 if ($("table"+z).offsetHeight == H || cnt==2) 561 return; 558 { 559 // ------ debug ----- 560 if (debug == true) 561 { 562 $('debug'+z).innerHTML = ""; 563 $('debug'+z).innerHTML += "|W="+W +"/"+H; 564 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight; 565 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h; 566 } 567 return; 568 } 562 569 563 570 resizeimpl(z, ++cnt); … … 567 574 { 568 575 resizeimpl(z, 0); 569 570 // ------ debug -----571 if (debug == true)572 {573 $('debug'+z).innerHTML = "";574 $('debug'+z).innerHTML += "|W="+W +"/"+H;575 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;576 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;577 }578 576 } 579 577 … … 598 596 } 599 597 600 //intervalSlide = setInterval("doSlideOut("+z+")", 25); 601 602 //var k = (z+1)%2; 603 //$("table"+k).style.display=""; 604 //$("table"+z).style.display=""; 605 //$("table"+k).style.zIndex="0"; 606 //$("table"+z).style.zIndex="1"; 607 //$("table"+k).style.left=0; 608 //$("table"+z).style.left=0; 609 //$("table"+k).style.backgroundColor = "#ffffff"; 610 //$("table"+z).style.backgroundColor = "#ffffff"; 611 //doresize(k); 612 //intervalSlide = setInterval("doSlide("+z+",1)", 50); 598 var W = window.innerWidth; 599 if (W==0) 600 { 601 $("table"+newz).style.left="0px"; 602 $("body").setAttribute("data-visible", newz); 603 $("body").removeChild($("table"+oldz)); 604 return; 605 } 613 606 614 607 if (newz>oldz) 615 $("table"+newz).style.left =window.innerWidth+"px";608 $("table"+newz).style.left = W+"px"; 616 609 else 617 $("table"+newz).style.left =(-window.innerWidth-1)+"px";610 $("table"+newz).style.left = (-W-1)+"px"; 618 611 619 612 //window.clearTimeout(timeoutText); … … 662 655 t1.style.left = x1+"px"; 663 656 } 664 665 /*666 function doSlide(z, dir)667 {668 var k = (z+1)%2;669 670 var W = window.innerWidth;671 672 var tz = $("table"+z);673 var tk = $("table"+k);674 675 var xz = tz.offsetLeft;676 var xk = tk.offsetLeft;677 678 var ixz = parseInt(xz, 10);679 var ikz = parseInt(xk, 10);680 681 ixz += dir*W/10;682 ikz -= dir*W/10;683 684 tz.style.left = parseInt(ixz, 10)+"px";685 tk.style.left = parseInt(ikz, 10)+"px";686 687 if (ixz>W/2)688 {689 clearInterval(intervalSlide);690 691 $("table"+k).style.zIndex="1";692 $("table"+z).style.zIndex="0";693 694 $("body").setAttribute("data-visible", k);695 doresize(k);696 697 intervalSlide = setInterval("doSlide("+z+",-1)", 50);698 }699 if (ikz>0)700 {701 clearInterval(intervalSlide);702 703 tz.style.left = 0;704 tk.style.left = 0;705 706 tz.style.display="none";707 }708 }709 710 711 function doSlideOut(z)712 {713 var table = $("table"+z);714 715 var W = window.innerWidth;716 var x = table.offsetLeft;717 718 var ix = parseInt(x, 10);719 if (ix>W)720 {721 clearInterval(intervalSlide);722 723 table.style.display="none";724 725 z = (z+1)%2;726 table = $("table"+z);727 728 table.style.display="";729 table.style.left = window.innerWidth+"px";730 731 $("body").setAttribute("data-visible", z);732 doresize(z);733 734 intervalSlide = setInterval("doSlideIn("+z+")", 25);735 return;736 }737 738 ix += W/10;739 table.style.left=ix+"px";740 }741 742 function doSlideIn(z)743 {744 var table = $("table"+z);745 746 var W = window.innerWidth;747 var x = table.offsetLeft;748 749 var ix = parseInt(x, 10);750 751 ix -= W/10;752 if (ix<0)753 ix = 0;754 755 table.style.left=ix+"px";756 757 if (ix<=0)758 {759 clearInterval(intervalSlide);760 return;761 }762 }763 */764 657 765 658 var timeoutText = null; … … 775 668 if (isSliding() || !valid(fname)) 776 669 { 670 // invalidate? 777 671 timeoutText = setTimeout(refresh_text, 1000); 778 672 return; 779 673 } 780 674 781 var xml Http= new XMLHttpRequest();782 xml Http.open('POST', fname+'.txt', true);783 xml Http.onload = function ()784 { 785 if (xml Http.status!=200)675 var xmlText = new XMLHttpRequest(); 676 xmlText.open('POST', fname+'.txt', true); 677 xmlText.onload = function () 678 { 679 if (xmlText.status!=200) 786 680 { 787 alert("ERROR[1] - HTTP request '"+fname+".txt': "+xml Http.statusText+" ["+xmlHttp.status+"]");681 alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlText.statusText+" ["+xmlText.status+"]"); 788 682 timeoutText = setTimeout(refresh_text, 10000); 789 683 return; … … 793 687 { 794 688 cycleCol($("ldot"+z)); 795 update_text(fname, xml Http.responseText);689 update_text(fname, xmlText.responseText); 796 690 } 797 691 timeoutText = setTimeout(refresh_text, 3000); 798 692 }; 799 xml Http.send(null);693 xmlText.send(null); 800 694 } 801 695 … … 811 705 } 812 706 707 /* 813 708 function gray(id, str) 814 709 { … … 827 722 e.style.textDecoration="line-through"; 828 723 } 829 830 } 831 724 } 725 */ 832 726 var date0 = null; 833 727 … … 878 772 for (var line=1; line<tokens.length; line++) 879 773 { 774 if (tokens[line].length==0) 775 continue; 776 880 777 var c = tbody.rows[line-1].cells[1]; 881 778 if (c == undefined) … … 919 816 if (isSliding() || !valid(fname)) 920 817 { 818 // invalidate? 921 819 timeoutGraphics = setTimeout(refresh_graphics, 1000); 922 820 return; 923 821 } 924 822 925 var xml Http= new XMLHttpRequest();926 xml Http.open('POST', fname, true);927 xml Http.onload = function()928 { 929 if (xml Http.status!=200)823 var xmlGfx = new XMLHttpRequest(); 824 xmlGfx.open('POST', fname, true); 825 xmlGfx.onload = function() 826 { 827 if (xmlGfx.status!=200) 930 828 { 931 alert("ERROR[2] - Request '"+fname+"': "+xml Http.statusText+" ["+xmlHttp.status+"]");829 alert("ERROR[2] - Request '"+fname+"': "+xmlGfx.statusText+" ["+xmlGfx.status+"]"); 932 830 timeoutGraphics = setTimeout(refresh_graphics, 10000); 933 831 //****** invalidate ****** … … 938 836 { 939 837 cycleCol($("rdot"+z)); 940 process_eventdata(xml Http.responseText);838 process_eventdata(xmlGfx.responseText); 941 839 } 942 840 timeoutGraphics = setTimeout(refresh_graphics, 5000) 943 841 }; 944 xml Http.send(null);842 xmlGfx.send(null); 945 843 } 946 844 … … 1074 972 if (data.length!=40 && data.length!=160 && data.length!=320 && data.length!=1440) 1075 973 { 1076 alert(" Data length mismatch ("+data.length+")");974 alert("Camera - Received data has invalid size ("+data.length+"b)"); 1077 975 return; 1078 976 } … … 1149 1047 } 1150 1048 1151 function drawCamLegend(canv) 1152 { 1153 var vals = canv.getAttribute("data-data").split("/"); 1154 1155 var v0 = parseFloat(vals[0]); 1156 var v1 = parseFloat(vals[1]); 1049 function drawCamLegend(canv, min, max) 1050 { 1051 var unit = canv.getAttribute("data-data");//.split("/"); 1052 if (unit.length>0) 1053 unit = " "+unit; 1054 1055 var v0 = parseFloat(min); 1056 var v1 = parseFloat(max); 1157 1057 1158 1058 var diff = v1-v0; … … 1167 1067 ctx.textBaseline = "top"; 1168 1068 1169 for (var i=0; i< 9; i++)1069 for (var i=0; i<11; i++) 1170 1070 { 1171 1071 ctx.strokeStyle = "#"+color(16*i); 1172 ctx.strokeText((v0+diff*i/8)+vals[2], cw-5, 135-i*15); 1173 } 1174 } 1175 1176 function drawGraph(canv, data) 1177 { 1072 ctx.strokeText((v0+diff*i/10)+unit, cw-5, 120-i*12); 1073 } 1074 } 1075 1076 function drawGraph(canv, min, max, data) 1077 { 1078 var unit = canv.getAttribute("data-data");//.split("/"); 1079 if (unit.length>0) 1080 unit = " "+unit; 1081 1178 1082 var cw = canv.width; 1179 1083 var ch = canv.height; … … 1181 1085 var ctx = canv.getContext("2d"); 1182 1086 1183 var vals = canv.getAttribute("data-data").split("/");1184 1185 1087 var dw = 3; // tick width 1186 1088 … … 1190 1092 ctx.textAlign = "right"; 1191 1093 1192 var dim0 = ctx.measureText( vals[0]);1193 var dim1 = ctx.measureText( vals[1]);1194 1195 var tw = vals.length>=2 ? Math.max(dim0.width, dim1.width)+dw+2 : 0;1196 1197 var ml = vals.length>=2 ? 5+tw : 10; // margin left1198 var mr = 10; 1199 1200 var mt = vals.length>=2 ? fs/2+5 :5; // margin top1201 var mb = vals.length>=2 ? fs/2+4 : 5; // margin bottom1094 var dim0 = ctx.measureText(min+unit); 1095 var dim1 = ctx.measureText(max+unit); 1096 1097 var tw = Math.max(dim0.width, dim1.width)+dw+2; 1098 1099 var ml = 5+tw; // margin left 1100 var mr = 10; // margin right 1101 1102 var mt = fs/2+5; // margin top 1103 var mb = fs/2+4; // margin bottom 1202 1104 1203 1105 var nx = 20; … … 1262 1164 ctx.closePath(); 1263 1165 1264 if (vals.length>=2) 1265 { 1266 ctx.textBaseline = "bottom"; 1267 ctx.strokeText(vals[0], ml-dw-2, ch-1); 1268 1269 ctx.textBaseline = "top"; 1270 ctx.strokeText(vals[1], ml-dw-2, 0); 1271 } 1272 } 1166 ctx.textBaseline = "bottom"; 1167 ctx.strokeText(min+unit, ml-dw-2, ch-1); 1168 1169 ctx.textBaseline = "top"; 1170 ctx.strokeText(max+unit, ml-dw-2, 0); 1171 } 1172 1173 var gfxtime0 = null; 1273 1174 1274 1175 function process_eventdata(result) 1275 1176 { 1177 if (result.length==0) 1178 return; 1179 1276 1180 var z = $("body").getAttribute("data-visible"); 1277 1181 var canv = $("canvas"+z); … … 1284 1188 ctx.clearRect(0, 0, canv.width, canv.height); 1285 1189 1190 var data = result.split('\n'); 1191 if (result.length<3) 1192 return; 1193 1194 var l = data[0].length+1+data[1].length+1; 1195 1286 1196 switch (type) 1287 1197 { 1288 case "hist": drawGraph(canv, result); break; 1289 //case "camera": drawCam(result); break; 1290 case "camera": drawFullCam(result); drawCamLegend(canv); break; 1291 } 1292 1293 $("image"+z).src = canv.toDataURL("image/png"); 1294 } 1295 1296 /* 1198 //case "camera": drawCam(result); break; 1199 case "hist": 1200 drawGraph(canv, data[0], data[1], result.substr(l)); 1201 break; 1202 case "camera": 1203 drawFullCam(result.substr(l)); 1204 drawCamLegend(canv, data[0], data[1]); 1205 break; 1206 } 1207 1208 var date = new Date(); 1209 if (gfxtime0 != null && gfxdate0.getTime()+60000>date.getTime()) 1210 { 1211 ctx.fillStyle = "rgba(255, 255, 255, 0.75)"; 1212 ctx.fillRect(0, 0, canv.width, canv.height); 1213 } 1214 1215 //$("image"+z).src = canv.toDataURL("image/png"); 1216 } 1217 1297 1218 function save() 1298 1219 { … … 1306 1227 document.location.href = img; 1307 1228 } 1308 */ 1229 1309 1230 window['onload'] = onload;
Note:
See TracChangeset
for help on using the changeset viewer.