| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 3 |
<head> |
|---|
| 4 |
<title>JavaScript Diagram Builder - Dynamic example</title> |
|---|
| 5 |
<link rel=stylesheet type="text/css" href="diagram.css" /> |
|---|
| 6 |
<SCRIPT Language="JavaScript">if ((document.layers)&&(history.length==1)) location.href=location.href+"#";</SCRIPT> |
|---|
| 7 |
<SCRIPT Language="JavaScript" src="diagram.js"></script> |
|---|
| 8 |
<SCRIPT Language="JavaScript">if (document.getElementById) document.write("<SCRIPT Language=\"JavaScript\" SRC=\"evalsafe.js\"><\/SCRIPT>");</SCRIPT> |
|---|
| 9 |
</head> |
|---|
| 10 |
<body> |
|---|
| 11 |
<DIV STYLE="position:absolute; top:0px"></DIV> |
|---|
| 12 |
<TABLE NOBORDER CELLPADDING=2 CELLSPACING=2 WIDTH=720><TR><TD> |
|---|
| 13 |
<H3> </H3> |
|---|
| 14 |
</TD></TR></TABLE> |
|---|
| 15 |
<form name="inputform"> |
|---|
| 16 |
<TABLE NOBORDER CELLPADDING=2 CELLSPACING=2 WIDTH=720> |
|---|
| 17 |
<TR><TD width=40></TD> |
|---|
| 18 |
<TD width=50 align=right>x-min:</TD> |
|---|
| 19 |
<TD width=80 align=left><input name="xmin" value="0" size=8></TD> |
|---|
| 20 |
<TD width=50 align=right>x-max:</TD> |
|---|
| 21 |
<TD width=80 align=left><input name="xmax" value="14" size=8></TD> |
|---|
| 22 |
<TD width=50 align=right>y-min:</TD> |
|---|
| 23 |
<TD width=80 align=left><input name="ymin" value="0" size=8></TD> |
|---|
| 24 |
<TD width=50 align=right>y-max:</TD> |
|---|
| 25 |
<TD width=80 align=left><input name="ymax" value="15" size=8></TD> |
|---|
| 26 |
<TD></TD> |
|---|
| 27 |
</TR> |
|---|
| 28 |
<TR><TD align=right>y=</TD> |
|---|
| 29 |
<TD colspan=8 align=left><input name="fx" value="x" size=56></TD> |
|---|
| 30 |
<TD><input type=button value="Draw" onClick="javascript:Draw()"></TD> |
|---|
| 31 |
</TR> |
|---|
| 32 |
</TABLE> |
|---|
| 33 |
</form> |
|---|
| 34 |
<SCRIPT Language="JavaScript"> |
|---|
| 35 |
document.open(); |
|---|
| 36 |
var D=new Diagram(); |
|---|
| 37 |
D.SetFrame(60, 175, 635, 500); |
|---|
| 38 |
D.SetBorder(-1, 1, -1, 1); |
|---|
| 39 |
D.SetText("x","y", "y=f(x)"); |
|---|
| 40 |
D.SetGridColor("#808080", "#CCCCCC"); |
|---|
| 41 |
D.Draw("#DDDDDD", "#000000", true); |
|---|
| 42 |
var i, j, x, y; |
|---|
| 43 |
j= D.ScreenY(0); |
|---|
| 44 |
P=new Array(636); |
|---|
| 45 |
for (i=60; i<=635; i++) |
|---|
| 46 |
P[i]=new Pixel(i, j, "#FFFFFF"); |
|---|
| 47 |
document.close(); |
|---|
| 48 |
function Draw() |
|---|
| 49 |
{ if ((navigator.userAgent.search("Opera 5")>=0)||(navigator.userAgent.search("Opera 6")>=0)) |
|---|
| 50 |
{ alert("Sorry, this doesn't work with this version of Opera.\nUse Opera 7.x, IE 5.x or Netscape 6.x instead."); |
|---|
| 51 |
return; |
|---|
| 52 |
} |
|---|
| 53 |
if ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)<5)) |
|---|
| 54 |
{ if (!confirm("This is not a safe operation with Netscape 4.x."+ |
|---|
| 55 |
" It can cause a crash of the browser."+ |
|---|
| 56 |
" Do you want to continue anyway?")) |
|---|
| 57 |
return; |
|---|
| 58 |
} |
|---|
| 59 |
var xmin=parseFloat(document.inputform.xmin.value); |
|---|
| 60 |
var xmax=parseFloat(document.inputform.xmax.value); |
|---|
| 61 |
var ymin=parseFloat(document.inputform.ymin.value); |
|---|
| 62 |
var ymax=parseFloat(document.inputform.ymax.value); |
|---|
| 63 |
if (isNaN(xmin)) { alert("x-min is not a number"); return; } |
|---|
| 64 |
if (isNaN(xmax)) { alert("x-max is not a number"); return; } |
|---|
| 65 |
if (isNaN(ymin)) { alert("y-min is not a number"); return; } |
|---|
| 66 |
if (isNaN(ymax)) { alert("y-max is not a number"); return; } |
|---|
| 67 |
D.SetBorder(xmin, xmax, ymin, ymax); |
|---|
| 68 |
D.SetText("x", "y", "y="+document.inputform.fx.value); |
|---|
| 69 |
D.SetGridColor("#808080", "#CCCCCC"); |
|---|
| 70 |
D.Draw("#DDDDDD", "#000000", true, "y="+document.inputform.fx.value); |
|---|
| 71 |
var isEvalSafe=((window.EvalSafe)&&(EvalSafe("1+1")==2)); |
|---|
| 72 |
for (i=60; i<=635; i++) |
|---|
| 73 |
{ x = D.RealX(i); |
|---|
| 74 |
if (isEvalSafe) |
|---|
| 75 |
{ y=EvalSafe(document.inputform.fx.value); |
|---|
| 76 |
if ((y=="")&&(isNaN(parseInt(y)))) |
|---|
| 77 |
{ alert(document.inputform.fx.value+" can not be evaluated for x="+x); |
|---|
| 78 |
return; |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
else |
|---|
| 82 |
{ with (Math) y=eval(document.inputform.fx.value); |
|---|
| 83 |
} |
|---|
| 84 |
if ((ymin<=y)&&(y<=ymax)) P[i].MoveTo(i, D.ScreenY(y)); |
|---|
| 85 |
else P[i].SetVisibility(false); |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|
| 88 |
</SCRIPT> |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
</body> |
|---|
| 93 |
</html> |
|---|