Changeset 13587
- Timestamp:
- 05/07/12 20:45:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/www/index.js
r13568 r13587 1 var debug = true; 2 1 3 function $(id) { return document.getElementById(id); } 2 4 function trim(str) { return str.replace("/^\s\s*/", '').replace("/\s\s*$/", ''); } … … 75 77 76 78 var lines = text.split('\n'); 79 80 if (lines.length==0) 81 { 82 alert("buildPage - received data empty."); 83 return; 84 } 77 85 78 86 var table = $("table"+z); … … 124 132 htd3.setAttribute("class", "tcell1"); 125 133 htd3.setAttribute("width", "1px"); 134 hhtr.appendChild(htd3); 126 135 hhtr.appendChild(htd0); 127 136 hhtr.appendChild(htd1); 128 137 hhtr.appendChild(htd2); 129 hhtr.appendChild(htd3);130 138 131 139 var div0 = document.createElement("div"); … … 150 158 sp2.setAttribute("data-color", "3"); 151 159 sp0.appendChild(document.createTextNode(" \u2022 ")); 152 sp1.appendChild(document.createTextNode(lines .length>0?lines[0]:"n/a"));160 sp1.appendChild(document.createTextNode(lines[0])); 153 161 sp2.appendChild(document.createTextNode(" \u2022 ")); 154 162 … … 163 171 htd0.appendChild(div0); 164 172 htd1.appendChild(div1); 165 htd2.appendChild(div2); 166 htd3.appendChild(div3); 173 if (dz!=0/* && z+dz!=0*/) 174 htd2.appendChild(div2); // back 175 if (lines[0]!="FACT") 176 htd3.appendChild(div3); // home 167 177 168 178 // ----------------------------------------------------- … … 278 288 { 279 289 var sp = document.createElement("div"); 280 sp.setAttribute("class", "icon_ gray");290 sp.setAttribute("class", "icon_black"); 281 291 sp.setAttribute("style", "background-position: -144px 50%;"); 282 292 td0.appendChild(sp); … … 295 305 { 296 306 var sp = document.createElement("div"); 297 sp.setAttribute("class", "icon_ gray");307 sp.setAttribute("class", "icon_black"); 298 308 sp.setAttribute("style", "background-position: -108px 50%;"); 299 309 td2.appendChild(sp); … … 332 342 tr.setAttribute("class", "row"); 333 343 334 td = document.createElement("td"); 335 td.setAttribute("id", "debug"); 336 td.setAttribute("colspan", "3"); 337 tr.appendChild(td); 344 if (debug == true) 345 { 346 td = document.createElement("td"); 347 td.setAttribute("id", "debug"+z); 348 td.setAttribute("colspan", "3"); 349 tr.appendChild(td); 350 } 338 351 339 352 tbody.appendChild(tr); … … 347 360 function doresize(z) 348 361 { 362 // 393 / 482 488/482 / 200 200+482-488 349 363 var img = $("image"+z); 350 364 var canv = $("canvas"+z); … … 368 382 369 383 // ------ debug ----- 370 371 $('debug').innerHTML = ""; 372 $('debug').innerHTML += "|W="+W +"/"+H; 373 $('debug').innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight; 374 $('debug').innerHTML += "|I="+img.style.height+"+"+H+"-"+h; 384 if (debug == true) 385 { 386 $('debug'+z).innerHTML = ""; 387 $('debug'+z).innerHTML += "|W="+W +"/"+H; 388 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight; 389 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h; 390 } 375 391 } 376 392 … … 414 430 $("table"+newz).style.left=(-window.innerWidth-1)+"px"; 415 431 432 //window.clearTimeout(timeoutText); 433 //window.clearTimeout(timeoutGraphics); 434 416 435 $("body").setAttribute("data-visible", newz); 417 436 intervalSlide = setInterval(doShift, 75, oldz, newz); … … 420 439 function doShift(oldz, newz) 421 440 { 422 var W = window.innerWidth;423 424 441 var t0 = $("table"+oldz); 425 442 var t1 = $("table"+newz); 426 443 444 if (t0.style.display=="none") 445 { 446 clearInterval(intervalSlide); 447 $("body").removeChild(t0); 448 return; 449 } 450 427 451 var x0 = t0.offsetLeft; 428 452 var x1 = t1.offsetLeft; 429 453 454 var W = window.innerWidth; 455 430 456 if (newz<oldz) 431 457 { … … 442 468 if ((newz<oldz && x1>=0) || (newz>oldz && x1<=0)) 443 469 { 444 clearInterval(intervalSlide); 445 $("body").removeChild(t0); 446 t1.style.left = "0px"; 447 return; 470 t0.style.display="none"; 471 x1 = 0; 448 472 } 449 473 … … 552 576 */ 553 577 578 var timeoutText = null; 579 554 580 function refresh_text() 555 581 { … … 561 587 if (isSliding() || !valid(fname)) 562 588 { 563 setTimeout(refresh_text, 1000);589 timeoutText = setTimeout(refresh_text, 1000); 564 590 return; 565 591 } … … 572 598 { 573 599 alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlHttp.statusText+" ["+xmlHttp.status+"]"); 574 setTimeout(refresh_text, 10000);600 timeoutText = setTimeout(refresh_text, 10000); 575 601 return; 576 602 } … … 581 607 update_text(fname, xmlHttp.responseText); 582 608 } 583 setTimeout(refresh_text, 3000);609 timeoutText = setTimeout(refresh_text, 3000); 584 610 }; 585 611 xmlHttp.send(null); … … 705 731 if (isSliding() || !valid(fname)) 706 732 { 707 setTimeout(refresh_graphics, 1000);733 timeoutGraphics = setTimeout(refresh_graphics, 1000); 708 734 return; 709 735 } … … 716 742 { 717 743 alert("ERROR[2] - Request '"+fname+"': "+xmlHttp.statusText+" ["+xmlHttp.status+"]"); 718 setTimeout(refresh_text, 10000);744 timeoutGraphics = setTimeout(refresh_graphics, 10000); 719 745 //****** invalidate ****** 720 746 return; … … 726 752 process_eventdata(xmlHttp.responseText); 727 753 } 728 setTimeout(refresh_graphics, 5000)754 timeoutGraphics = setTimeout(refresh_graphics, 5000) 729 755 }; 730 756 xmlHttp.send(null); … … 937 963 { 938 964 ctx.strokeStyle = "#"+color(16*i); 939 ctx.strokeText((vals[ 1]-diff*i/8)+vals[2], cw-5, 135-i*15);965 ctx.strokeText((vals[0]-diff*(i-8)/8)+vals[2], cw-5, 135-i*15); 940 966 } 941 967 } … … 948 974 var ctx = canv.getContext("2d"); 949 975 950 var dx = 15; 951 var dy = 15; 952 953 var dw = 5; 976 var vals = canv.getAttribute("data-data").split("/"); 977 978 var dw = 3; // tick width 979 980 var fs = 8; // font size 981 982 ctx.font = fs+"pt Arial"; 983 ctx.textAlign = "right"; 984 985 var dim0 = ctx.measureText(vals[0]); 986 var dim1 = ctx.measureText(vals[1]); 987 988 var tw = vals.length>=2 ? Math.max(dim0.width, dim1.width)+dw+2 : 0; 989 990 var ml = vals.length>=2 ? 5+tw : 10; // margin left 991 var mr = 10; // margin right 992 993 var mt = vals.length>=2 ? fs/2+5 : 5; // margin top 994 var mb = vals.length>=2 ? fs/2+4 : 5; // margin bottom 954 995 955 996 var nx = 20; 956 997 var ny = 10; 957 998 958 var w = cw- 2*dx;959 var h = ch- 2*dy;999 var w = cw-ml-mr; 1000 var h = ch-mt-mb; 960 1001 961 1002 ctx.strokeStyle = "#808080"; 962 1003 1004 // --- data --- 963 1005 ctx.beginPath(); 964 ctx.moveTo( dx, ch-dy-data.charCodeAt(0)/128*h);1006 ctx.moveTo(ml, ch-mb-data.charCodeAt(0)/128*h); 965 1007 for (var i=1; i<data.length; i++) 966 ctx.lineTo(dx+w/data.length*i, ch-dy-data.charCodeAt(i)/128*h); 967 ctx.lineTo(dx+w, ch-dy); 968 ctx.lineTo(dx, ch-dy); 1008 ctx.lineTo(ml+w/(data.length-1)*i, ch-mb-data.charCodeAt(i)/128*h); 1009 1010 // --- finalize data --- 1011 ctx.lineTo(cw-mr, ch-mb); 1012 ctx.lineTo(ml, ch-mb); 969 1013 ctx.fillStyle = "#"+color(100); 1014 ctx.stroke(); 970 1015 ctx.fill(); 1016 1017 ctx.strokeStyle = "#000000"; 1018 1019 ctx.beginPath(); 1020 1021 // --- axes --- 1022 ctx.moveTo(ml, mt); 1023 ctx.lineTo(ml, ch-mb); 1024 ctx.lineTo(cw-mr, ch-mb); 1025 1026 for (var i=0; i<nx; i++) 1027 { 1028 ctx.moveTo(ml+w/nx*i, ch-mb-dw); 1029 ctx.lineTo(ml+w/nx*i, ch-mb+dw); 1030 } 1031 for (var i=0; i<ny; i++) 1032 { 1033 ctx.moveTo(ml-dw, mb+h/ny*i); 1034 ctx.lineTo(ml+dw, mb+h/ny*i); 1035 } 971 1036 ctx.stroke(); 972 1037 ctx.closePath(); 973 1038 974 ctx.strokeStyle = "#000000"; 975 976 ctx.beginPath(); 977 978 ctx.moveTo(dx, dy); 979 ctx.lineTo(dx, ch-dy); 980 ctx.lineTo(cw-dx, ch-dy); 981 982 for (var i=0; i<nx; i++) 983 { 984 ctx.moveTo(dx+w/nx*i, ch-dy-dw); 985 ctx.lineTo(dx+w/nx*i, ch-dy+dw); 986 } 987 for (var i=0; i<ny; i++) 988 { 989 ctx.moveTo(dx-dw, dy+h/ny*i); 990 ctx.lineTo(dx+dw, dy+h/ny*i); 991 } 992 ctx.stroke(); 993 ctx.closePath(); 1039 if (vals.length>=2) 1040 { 1041 ctx.textBaseline = "bottom"; 1042 ctx.strokeText(vals[0], ml-dw-2, ch-1); 1043 1044 ctx.textBaseline = "top"; 1045 ctx.strokeText(vals[1], ml-dw-2, 0); 1046 } 994 1047 } 995 1048 996 1049 function process_eventdata(result) 997 1050 { 998 if (result.length!=160)999 return;1000 1001 1051 var z = $("body").getAttribute("data-visible"); 1002 1052 var canv = $("canvas"+z);
Note:
See TracChangeset
for help on using the changeset viewer.