<!--
//本卷是 jsgraph1.js ，
//不是 jsgraph3.js 
//100,01,10,12,01 在 jsgraph1.js 
//增加 var showXYcoord1orNot0
//增加 var xatL, yatL
//
//如果您只需要 XYGraph.js : v2.3
//您可以由 
//http://freeman2.com/jsgraph1.js 
//改為
//http://freeman2.com/jsgraph3.js
//劉鑫漢 100,01,10,12,16
//
var doc01=''; //9506222120 全域變數
//9506241341 把粗體 'bold' 改為普通 'regular'
//9506241347 把粗體 'bold' 改為普通 'regular'
//9506241355 把字體 'Arial' 改為 'Dotum' 筆劃較細

var bgntxt= // 9506250728 use bgntxt
"http://freeman2.com/graph001.js<br>"
;


//9912172230
//本卷使用的 XYGraph v2.3 是更改版本，增加了
var showXYcoord1orNot0=1; //9912140641
//若令值為一，程式畫 XY 坐標軸，零則不畫。

//9912281633
//'L' 代表 x-軸與 y-軸的交點。
//xatL=0; 表示在XY 坐標軸交點處 X 坐標為零。
//同理， yatL=0; 表示交點處 Y 坐標為零。
var xatL=0;
var yatL=0; 
//定義為全域變數，容許其他函數修改變數值。
//應用實例請參考下述網頁
// http://freeman2.com/xygraph1.htm
//的函數 function xyatL(arg1) 
//9912281639



/*================================================================================

 XYGraph.js : v2.3

 by J. Gebelein, Last Updated 2006.01.11

 Contact: info@Structura.info

 All rights reserved.
 Copyright 2006 Structura.info


 This script generates an XY Graph
 using Vector Markup Language (VML)
 and returns
 an html string for display via
 Javascript.  Labels for points on
 a line, individual
 labels and arrows may be drawn with
 fully customizable features. 
 Multiple lines 
 with unlimited points and customizable
 formats can be drawn on the same plot
 with 
 intelligent data axes that provide a
 best fit to the data for simple, dynamic 
 programming.  

 The VML used by this script is fully
 supported by Internet Explorer 5 or
 later, 
 and will run on any website or intranet,
 online or offline.  Data for the graph
 may be generated from static or dynamic
 Javascript and user form interfaces, or
 even from complex active server database
 programs.

 Use of this code is free for all
 non-commercial websites.  If you find
 this code
 to be useful, I will gladly accept
 PayPal donations to info@Structura.info.
 I 
 provide free email support and will try
 to accomodate your various needs into
 improving this program.

 For commercial use I ask for a one time
 licensing fee of $39.95 per domain, or 
 $99.95 for an unlimited license. Both
 will cover all future version upgrades
 and 
 allow for customization of the source
 code. An unlimited license will allow
 unrestricted use by a single organization
 including redistribution or resale as 
 supporting code for a software product.

 Please leave this header intact if you
 intend on sharing this code.

=========================================
=========================================

"XYGraph" object documentation

Initialize: 
	var MyGraph = new XYGraph();
	MyGraph.xmax = 10;
 // set properties as desired
		
Properties: 
	See constructor script with
 inline comments below.
	
Methods:
	MyGraph.Plot(XYLine [, XYLine_1, ...])
 // returns html code for display

Notes:

 Input x,y coordinate pairs using the
 "XYLine" object found in this script.

 The only required input is the x and
 y data, all formatting and other
 parameters either have default values
 defined in this script, or are
 automatically calculated as required
 to best display the data.

 Multiple XYLine objects may be passed
 to the Plot function for graphing.

 Extreme values +/-999E+99 and "NaN"
 are clipped from the data set.

 Unlike standard XY graphs, lines are
 drawn point to point in any direction
 without limitation.  This allows step
 functions, circles, shapes, etc.

 This script does not optimize data for
 better resolution, it is up to the
 programmer to input the data spacing as
 desired.

 Generating smooth output requires
 increasing the number of data points
 at the
 expense of computation time. 
 Generally, 1000 points or less is
 adequate.
 
 Formatting for text may be modified
 using CSS.

 Formatting for the axes and lines may
 be modified using VML styles, for more 
 information on VML see the W3C
 definition page:
 http://www.w3.org/TR/NOTE-VML

=========================================
=========================================

"XYLine" object documentation

Initialize: 
	var MyLine = new XYLine();
	MyLine.x = [1, 2, 3, 4];
 // set x and y data points
	MyLine.label = "plot 1";
 // set properties as desired
		
Properties: 
	See constructor script with
 inline comments below.

========================================
========================================*/


function XYLine() {

	// Arrays for holding x, y coordinate values and point labels

	this.x = new Array();
	this.y = new Array();
	this.labels = new Array();
	
	// Assign VML compliant properties for the line.
	// Note that non-primary colors must be in #hex or rbg(r,g,b) format.

// 9506162040 此
// color='red' 或者
// color='blue' 決定曲線顏色
//	this.VMLstroke = "weight='1pt'; color='red'; dashstyle='solid';";
// 9506201957 只有此行指令改變顏色
//	this.VMLstroke = "weight='3pt'; color='red'; dashstyle='solid';";
	this.VMLstroke = "weight='1pt'; color='blue'; dashstyle='solid';";


	this.drawline=true;	// set to true or false

	// Assign a label for the line

	this.label = "line";	// displayed when mouse is over line
	this.labelfont = "'Arial'";
	this.labelsize = "8"; // font size in "pt"
	this.labelcolor = "black";

	// Assign a VML shapetype for plotting data points, see definitions at bottom of script.
	// Using the 'none' shapetype plots invisible points and allows coordinates to be
	// shown when the mouse is over the point.  Set 'drawpoints' to false to turn off
	// the points completely and speed up graphing for extensive data sets.  The graph script
	// automatically turns off points if the data set has more than 1000 points.

	this.VMLpointshapetype="diamond";	// [ diamond, square, triangle, circle, x, none ]
	this.drawpoints=true;	 	// set to true or false
	this.drawlabels=false;		// set to true or false
	this.mouseoverlabels=false;	// true will show the "labels" on mouseover, false will show x,y coord

	// Assign VML properties for the points

	this.pointsize="5";	 	// shape display size in "pt"
	this.pointfillcolor="blue";	// point fill color
	this.pointstrokecolor="black";	// point line color
}


function Arrow() {

	// x and y coordinate values of arrow origin

	this.x = 0;
	this.y = 0;
	this.rotation = 45;
	this.length = 25;
	
	// Assign a label for the arrow

	this.label = "Test";

	// Assign VML properties for the arrow

	this.size="10";	 	// shape display size in "pt"
	this.color="red";	// arrow color
	this.labelcolor="red";	// label color
	this.labelsize="12";	// label size in "pt"
	this.lineweight="2";  // line weight in "pt"
	this.dashstyle="solid"; // line style

	// Arrow head shape definition

	this.arrowhead='<v:shapetype id="arrowhead" coordsize="500,500" path=" m 0 0 l 250 500 500 0 250 100 x e" />';

} // end function



function Label() {

	// x and y coordinate values of the label origin

	this.x = 0;
	this.y = 0;
	this.rotation = 45;
	this.length = 0;
	
	// Assign a label text

	this.label = "";

	// Assign VML properties for the label

	this.labelcolor="red";	// label color
	this.labelsize="12";	// label size in "pt"

//	this.VMLpointshapetype="circle";	// [ diamond, square, triangle, circle, x, none ]
//9506172103 改為下面一行
//	this.VMLpointshapetype="none";	// [ diamond, square, triangle, circle, x, none ]
//結果所有小圈消失
//9506172105 返回原有設定
	this.VMLpointshapetype="circle";	// [ diamond, square, triangle, circle, x, none ]

	this.pointsize="6";	 	// shape display size in "pt"
	this.pointfillcolor="red";	// point fill color
	this.pointstrokecolor="black";	// point line color

} // end function



function XYGraph() {

  // Data Properties

	// The max and min values define the upper and lower axis values to display.
	// If not specified they will automatically fit to the data limits.

	this.xmax=null;
	this.xmin=null;
	this.ymax=null; 
	this.ymin=null;

	// Graph titles

	this.title=null;
	this.xaxis=null;
	this.yaxis=null;

	// Tic scale spacing, if not specified it will be fit to the data.

	this.xscale=null;
	this.yscale=null;

	// Value where the axes cross.  Default is at 0,0
	// Set to "Number.NEGATIVE_INFINITY" to align with the minimum axis value.
	// Set to "Number.POSITIVE_INFINITY" to align with the maximum axis value.

//	this.xint=0;
//	this.yint=0;
//9912281640 更改如下
	this.xint=xatL;
	this.yint=yatL;

	// The last plot string generated is maintained in memory

	this.lastplot="";

	// Tracks the changes made from additional plots for use with DeleteLast()

	this.lastplotadded= new Array();
	this.numplots=0;

  // Style Properties

	this.gheight=200;	// Plotting height in "pt"
	this.gwidth=300;	// Plotting width in "pt"
	this.pad_top=10;	// Internal padding margins in "pt"
	this.pad_bottom=10;
	this.pad_left=10;
	this.pad_right=10;

	this.ticsize=5; 	// Tic size in "pt", set to "0" to turn off
	this.ticspaceavg=30;	// Average auto tic spacing in "pt"
	this.xticloc="auto";	// x-axis labels "top", "bottom", "auto" or "none"
	this.yticloc="auto";	// y-axis labels "right", "left", "auto" or "none"
	this.userxticlabels=null;	// allows the user to override x axis tic labels
	this.useryticlabels=null;	// allows the user to override y axis tic labels

	this.VMLminorxaxisstroke = "weight='0.5pt'; color='#D3D3D3'; dashstyle='dash';";
	this.VMLminoryaxisstroke = "weight='0.5pt'; color='#D3D3D3'; dashstyle='dash';";
	this.VMLmajoraxisstroke = "weight='1pt'; color='black';";
	this.VMLbackgroundfill = "color='white'";
	this.VMLframestroke = "color='white'";

	this.CSSticfont = "font: 8pt 'Arial';";

//	this.CSStitlefont = "font: 10pt 'Arial'; font-weight: bold;";  // font sizes must be set in "pt"
//9506181816 刪除「粗體」 [ font-weight: bold;]
	this.CSStitlefont = "font: 10pt 'Arial';";  // font sizes must be set in "pt"

	this.CSSxaxisfont = "font: 8pt 'Arial'; font-weight: bold;";
	this.CSSyaxisfont = "font: 8pt 'Arial'; font-weight: bold;";
	this.VMLyaxisfontcolor = "black";  // must specify y-axis title font color since it is VML object

}

XYGraph.prototype.toString = function() {return this.lastplot;} // The object will evaluate to the last plot



XYGraph.prototype.Plot = function (XYLine) {

// Parse input to determine x,y data limits and clip extreme values
	lines = arguments; 
	xmax = Number.NEGATIVE_INFINITY; xmin = Number.POSITIVE_INFINITY;
	ymax = Number.NEGATIVE_INFINITY; ymin = Number.POSITIVE_INFINITY;
	clipxmax = (this.xmax ? Number(this.xmax) : 999E+99); 
	clipxmin = (this.xmin ? Number(this.xmin) : -999E+99);
	clipymax = (this.ymax ? Number(this.ymax) : 999E+99);
	clipymin = (this.ymin ? Number(this.ymin) : -999E+99);
	clipped=false;

// fix input
	this.yint = Number(this.yint); this.xint = Number(this.xint);
	this.ymin = Number(this.ymin); this.xmin = Number(this.xmin);
	this.ymax = Number(this.ymax); this.xmax = Number(this.xmax);

	if (this.xmax < this.xmin && this.xmax) {temp=this.xmax; this.xmax=this.xmin; this.xmin=temp;} 
	if (this.ymax < this.ymin && this.ymax) {temp=this.ymax; this.ymax=this.ymin; this.ymin=temp;}

	xmax=this.xmax; xmin=this.xmin; ymax=this.ymax; ymin=this.ymin;

  for (var n=0; n<lines.length; n++) {
	var j=0; tempx = new Array(); tempy = new Array(); templabels = new Array();
	linelen = (lines[n].y.length > lines[n].x.length ? lines[n].x.length : lines[n].y.length);
	for (var i=0; i<linelen; i++) {
		if ((lines[n].x[i] <= clipxmax)&&(lines[n].x[i] >= clipxmin)&&(lines[n].y[i] <= clipymax)&&(lines[n].y[i] >= clipymin)&&(i<=1000)) {
			if (xmax < lines[n].x[i]) {xmax = lines[n].x[i]};
			if (xmin > lines[n].x[i]) {xmin = lines[n].x[i]};
			if (ymax < lines[n].y[i]) {ymax = lines[n].y[i]};
			if (ymin > lines[n].y[i]) {ymin = lines[n].y[i]};
			tempx[j]=lines[n].x[i]; 
			tempy[j]=lines[n].y[i];
			if(lines[n].drawlabels || lines[n].mouseoverlabels) {templabels[j]= lines[n].labels[j];}
			j++;
		}
		else if (isNaN(lines[n].x[i]) || isNaN(lines[n].y[i])) {clipped=true;}
		else if (((lines[n].x[i+1] <= clipxmax)&&(lines[n].x[i+1] >= clipxmin)&&(lines[n].y[i+1] <= clipymax)&&(lines[n].y[i+1] >= clipymin)&&(i<=1000))) {
			lastxy = this.Findedge(lines[n].x[i+1],lines[n].x[i],lines[n].y[i+1],lines[n].y[i],clipxmax,clipxmin,clipymax,clipymin);
			if (Math.abs(lastxy[0]) < 999E+99 && Math.abs(lastxy[1]) < 999E+99) {
				tempx[j]=lastxy[0]; tempy[j]=lastxy[1]; 
				if(lines[n].drawlabels || lines[n].mouseoverlabels) {templabels[j]="";}
				j++;
			}
			clipped=true; 
		}
		else if (((lines[n].x[i-1] <= clipxmax)&&(lines[n].x[i-1] >= clipxmin)&&(lines[n].y[i-1] <= clipymax)&&(lines[n].y[i-1] >= clipymin))&&(i<=1000)) {
			lastxy = this.Findedge(lines[n].x[i-1],lines[n].x[i],lines[n].y[i-1],lines[n].y[i],clipxmax,clipxmin,clipymax,clipymin);
			if (Math.abs(lastxy[0]) < 999E+99 && Math.abs(lastxy[1]) < 999E+99) {
				tempx[j]=lastxy[0]; tempy[j]=lastxy[1]; 
				if(lines[n].drawlabels || lines[n].mouseoverlabels) {templabels[j]="";}
				j++;
			}
			if (i+1 != linelen) {
			lines.length += 1;
			lines[(lines.length-1)] = new Array();
			lines[(lines.length-1)].VMLstroke = lines[n].VMLstroke;
			lines[(lines.length-1)].drawline = lines[n].drawline;
			lines[(lines.length-1)].label = lines[n].label;
			lines[(lines.length-1)].VMLpointshapetype = lines[n].VMLpointshapetype;
			lines[(lines.length-1)].pointsize = lines[n].pointsize;
			lines[(lines.length-1)].pointfillcolor = lines[n].pointfillcolor;
			lines[(lines.length-1)].pointstrokecolor = lines[n].pointstrokecolor;
			lines[(lines.length-1)].drawpoints = lines[n].drawpoints;
			lines[(lines.length-1)].labelsize = lines[n].labelsize;
			lines[(lines.length-1)].labelfont = lines[n].labelfont;
			lines[(lines.length-1)].labelcolor = lines[n].labelcolor;
			lines[(lines.length-1)].drawlabels = lines[n].drawlabels;
			lines[(lines.length-1)].mouseoverlabels = lines[n].mouseoverlabels;
			lines[(lines.length-1)].x=lines[n].x.slice(i);
			lines[(lines.length-1)].y=lines[n].y.slice(i); 
			lines[n].x=tempx; lines[n].y=tempy; 
			if(lines[n].drawlabels || lines[n].mouseoverlabels) {
				lines[(lines.length-1)].labels=lines[n].labels.slice(i);
				lines[n].labels=templabels;
			}
			clipped=true;

			break; 
			}
		}
		else if (i > 1000) {
			lines[n].drawpoints = false;
			lines[n].drawlabels = false;
			lines.length += 1;
			lines[(lines.length-1)] = new Array();
			lines[(lines.length-1)].VMLstroke = lines[n].VMLstroke;
			lines[(lines.length-1)].drawline = lines[n].drawline;
			lines[(lines.length-1)].label = lines[n].label;
			lines[(lines.length-1)].drawpoints = false;
			lines[(lines.length-1)].drawlabels = false;
			lines[(lines.length-1)].x=lines[n].x.slice(i-1);
			lines[(lines.length-1)].y=lines[n].y.slice(i-1); 
			lines[n].x=tempx; lines[n].y=tempy;

			break; 
		}
		else {clipped=true;}
	}
	lines[n].x=tempx; lines[n].y=tempy; lines[n].labels=templabels;
  }

	if (this.xint == Number.NEGATIVE_INFINITY) {this.xint = xmin;}
	if (this.xint == Number.POSITIVE_INFINITY) {this.xint = xmax;}
	if (this.yint == Number.NEGATIVE_INFINITY) {this.yint = ymin;}
	if (this.yint == Number.POSITIVE_INFINITY) {this.yint = ymax;}



// Intialize data

if (this.lastplot == "") { // don't redraw graph background if called multiple times

	xscale=Number(this.xscale); yscale=Number(this.yscale);
	xint=Number(this.xint); yint=Number(this.yint);

	gheight=Number(this.gheight); gwidth=Number(this.gwidth);
	ticsize=Number(this.ticsize);

	xticloc=this.xticloc; yticloc=this.yticloc;

// Initialize parameters

	gxpt=100;
	pad_t=gxpt*this.pad_top; pad_b=gxpt*this.pad_bottom; // padding
	pad_l=gxpt*this.pad_left; pad_r=gxpt*this.pad_right; 
	gwt=Math.abs(Math.round(gwidth*gxpt)); // total graph width;
	ght=Math.abs(Math.round(gheight*gxpt)); // total graph height;

	gstyle='position:absolute; width='+gwt+'; height='+ght; // repetitive string constant
	GXstyle=this.CSSticfont+'position:absolute;';
	GYstyle=this.CSSticfont+'position:absolute;';
	GYLstyle=this.CSSticfont+'position:absolute; text-align:right; width:'; // finished later

// fix auto scale x axis
	if (xint < xmin) {xmin=xint;}
	if (xint > xmax) {xmax=xint;}

// x auto tic scale
     if (xscale <= 0) {
	xticmax=(gwidth-(pad_r+pad_l)/gxpt)/this.ticspaceavg;
	ticdivision=[0.1,0.2,0.25,0.5];
	divpow=0;
	i=0;
	  while ((xmax-xmin)/(ticdivision[i]*Math.pow(10,divpow)) > xticmax) { 
	    i++; 
	    if (!(i % ticdivision.length)) {divpow++; i=0;}
	    if (divpow>1) {xticmax=(gwidth-(pad_r+pad_l)/gxpt)/(Number(this.ticspaceavg)+5);}
	  }
	if (i==0 && divpow==0) {
	  i=ticdivision.length-1; divpow=-1; xticmax=(gwidth-(pad_r+pad_l)/gxpt)/(Number(this.ticspaceavg)+10);
	  while ((xmax-xmin)/(ticdivision[i]*Math.pow(10,divpow)) < xticmax) { 
	    i--; 
	    if (i==-1) {divpow--; i=ticdivision.length-1; xticmax=(gwidth-(pad_r+pad_l)/gxpt)/(Number(this.ticspaceavg)+30);}
	  }
	}
	xscale=ticdivision[i]*Math.pow(10,divpow);
     }


// fix auto scale y axis
	if (yint < ymin) {ymin = yint;}
	if (yint > ymax) {ymax = yint;}

// y auto tic scale
     if (yscale <= 0) {
	yticmax=(gheight-(pad_t+pad_b)/gxpt)/this.ticspaceavg;
	ticdivision=[0.1,0.2,0.25,0.5];
	divpow=0;
	i=0;
	  while ((ymax-ymin)/(ticdivision[i]*Math.pow(10,divpow)) > yticmax) { 
	    i++; 
	    if (!(i % ticdivision.length)) {divpow++; i=0;}
	    if (divpow>1) {yticmax=(gwidth-(pad_t+pad_b)/gxpt)/(Number(this.ticspaceavg)+5);}
	  }
	if (i==0 && divpow==0) {
	  i=ticdivision.length-1; divpow=-1; yticmax=(gheight-(pad_t+pad_b)/gxpt)/(this.ticspaceavg+10);
	  while ((ymax-ymin)/(ticdivision[i]*Math.pow(10,divpow)) < yticmax) { 
	    i--; 
	    if (i==-1) {divpow--; i=ticdivision.length-1; yticmax=(gheight-(pad_t+pad_b)/gxpt)/(this.ticspaceavg+30);}
	  }
	}
	yscale=ticdivision[i]*Math.pow(10,divpow);
     }

// fix auto scale y axis
	if (!clipped) {
		ymin = (ymin%yscale ? ymin-ymin%yscale-yscale : ymin);
		ymax = (ymax%yscale ? ymax-ymax%yscale+yscale : ymax);
	}


// Determine x tic labels

	xticlabels = new Array(); xticcharnum=1;
	numxticleft = Math.floor((xint-xmin)/xscale); 
	numxtic = numxticleft+Math.floor((xmax-xint)/xscale)+1;
	for (var i=0; i<numxtic; i++) {
		xticlabel=(i-numxticleft)*xscale+xint;  
		negstr=""; expstr=0;
		if (xticlabel < 0) {xticlabel*=-1; negstr="-";}
		switch (true) {	
		case (xticlabel > 99999) : 
			while (xticlabel>=1000) {xticlabel/=1000; expstr++;}
			xticlabel=String(xticlabel).slice(0,4);
			xticlabels[i]=negstr+xticlabel+"E+"+(expstr*3);
			break;
		case (xticlabel < 0.001 && xticlabel!=0) : 
			while (xticlabel<=0.001) {xticlabel*=1000; expstr++;}
			xticlabel=(Math.round(xticlabel*Math.pow(10,4)))/Math.pow(10,4);
			xticlabels[i]=negstr+xticlabel+"E-"+(expstr*3);
			break;
		default:
			xticlabel=(Math.round(xticlabel*Math.pow(10,3)))/Math.pow(10,3);
			xticlabels[i]=negstr+String(xticlabel).slice(0,6);
			break;
		} 
		xticcharnum=Math.max(xticcharnum,String(xticlabels[i]).length);
	}
	xticcharnumlast=String(xticlabels[i-1]).length;

	if (this.userxticlabels!=null) {
	len=Math.min(this.userxticlabels.length,xticlabels.length);
	for (var i=0; i<len; i++) {
		xticlabels[i]=this.userxticlabels[i];
	}}


// Determine y tic labels

	yticlabels = new Array(); yticcharnum=0;
	numyticbot = Math.floor((yint-ymin)/yscale);
	numytic = numyticbot+Math.floor((ymax-yint)/yscale)+1;
	for (var i=0; i<numytic; i++) {
		yticlabel=(i-numyticbot)*yscale+yint;
		negstr=""; expstr=0;
		if (yticlabel < 0) {yticlabel*=-1; negstr="-";}
		switch (true) { 
		case (yticlabel > 99999) : 
			while (yticlabel>=1000) {yticlabel/=1000; expstr++;}
			yticlabel=String(yticlabel).slice(0,4);
			yticlabels[i]=negstr+yticlabel+"E+"+(expstr*3);
			break;
		case (yticlabel < 0.001 && yticlabel!=0) : 
			while (yticlabel<=0.001) {yticlabel*=1000; expstr++;}
			yticlabel=(Math.round(yticlabel*Math.pow(10,4)))/Math.pow(10,4);
			yticlabels[i]=negstr+yticlabel+"E-"+(expstr*3);
			break;
		default:
			yticlabel=(Math.round(yticlabel*Math.pow(10,3)))/Math.pow(10,3);
			yticlabels[i]=negstr+String(yticlabel).slice(0,6);
			break;
		} 
		yticcharnum=Math.max(yticcharnum,String(yticlabels[i]).length);
	}

	if (this.useryticlabels!=null) {
	len=Math.min(this.useryticlabels.length,yticlabels.length);
	for (var i=0; i<len; i++) {
		yticlabels[i]=this.useryticlabels[i];
	}}

// Determine required extra padding and auto axis location
	tic_pt=Number((this.CSSticfont.slice(0,this.CSSticfont.indexOf("pt"))).slice(-2));
	GYLstyle+=tic_pt*(yticcharnum+1)*0.5+"pt;";
	if (yticloc!="none") {
	  if (!numxticleft) {
		if (yticloc=="auto") {yticloc="left";}
		if (yticloc!="right") {
			pad_l+=0.75*yticcharnum*tic_pt*gxpt;
			if (this.yaxis) {pad_l+=0.5*this.pad_left*gxpt;}
		}
	  }
	  if (numxticleft == numxtic-1) {
		if (yticloc=="auto") {yticloc="right";}
		if (yticloc!="left") {pad_r+=0.75*yticcharnum*tic_pt*gxpt;}
	  }
	}

	if (xticloc!="none") {
	  if (!numyticbot) {
		if (xticloc=="auto") {xticloc="bottom";}
		if (xticloc!="top") {pad_b+=0.75*tic_pt*gxpt;}
	  }
	  if (numyticbot == numytic-1) {
		if (xticloc=="auto") {xticloc="top";}
		if (xticloc!="bottom") {pad_t+=0.75*tic_pt*gxpt;}
	  }
	if (!((numxticleft == numxtic-1) && (yticloc=="right"))) {pad_r+=0.25*xticcharnumlast*tic_pt*gxpt;}
	}
	if (this.title) {
		title_pt=Number((this.CSStitlefont.slice(0,this.CSStitlefont.indexOf("pt"))).slice(-2));
		pad_t+=1.25*title_pt*gxpt;
		if (xticloc=="top") pad_t+=0.75*tic_pt*gxpt;}
	if (this.xaxis) {
		xaxis_pt=Number((this.CSSxaxisfont.slice(0,this.CSSxaxisfont.indexOf("pt"))).slice(-2));
		pad_b-=0.25*pad_b;
		pad_b+=xaxis_pt*gxpt;
		if (xticloc=="bottom") pad_b+=0.75*tic_pt*gxpt;}
	if (this.yaxis) {
		yaxis_pt=Number((this.CSSyaxisfont.slice(0,this.CSSyaxisfont.indexOf("pt"))).slice(-2));
		pad_l-=0.25*pad_l;
		pad_l+=yaxis_pt*gxpt;}


	gw=gwt-pad_l-pad_r;
	gh=ght-pad_t-pad_b;

	xscl=gw/(xmax-xmin);
	yscl=gh/(ymax-ymin);

	this.xmin=xmin; 
	this.xmax=xmax; 
	this.ymin=ymin; 
	this.ymax=ymax;

	gxmin=pad_l;
	gxmax=gw+pad_l;
	gxint=(xint-xmin)*xscl+pad_l;
	gymin=gh+pad_t;
	gymax=pad_t;
	gyint=(ymax-yint)*yscl+pad_t;
	gytic=yscale*yscl;
	gxtic=xscale*xscl;
	gticsize=Math.abs(Math.round(ticsize*gxpt));

	gstr='<v:group style="antialias:true; width='+gwidth+'pt; height='+gheight+'pt" coordsize="'+gwt+','+ght+'" coordorigin="0,0">';
	gstr+='<v:rect style="'+gstyle+'" ><v:stroke '+this.VMLframestroke+' /><v:fill '+this.VMLbackgroundfill+' /></v:rect>';

if(showXYcoord1orNot0==1) //9912140642
{ // showXYcoord1orNot0==0 刪除二維坐標軸

//9712291539 下面畫二維坐標軸等值網

// draw x-axis
	if(xscl!=Number.POSITIVE_INFINITY) {
		gstr+='<v:line from="'+gxmin+','+Math.round(gyint)+'" to="'+gxmax+','+Math.round(gyint)+'" ><v:stroke '+this.VMLmajoraxisstroke+' /></v:line>';
		}
// draw y-axis
	if(yscl!=Number.POSITIVE_INFINITY) {
		gstr+='<v:line from="'+Math.round(gxint)+','+gymin+'" to="'+Math.round(gxint)+','+gymax+'" ><v:stroke '+this.VMLmajoraxisstroke+' /></v:line>';
		}
// draw minor x-axis
	yticmin=gyint+numyticbot*gytic;
	for (var i=0; i<numytic; i++) {
	  curint=Math.round(yticmin-gytic*i);
	  if (curint!=Math.round(gyint)) {gstr+='<v:line from="'+gxmin+','+curint+'" to="'+gxmax+','+curint+'" ><v:stroke '+this.VMLminorxaxisstroke+' /></v:line>';}
	}

// draw minor y-axis
	xticmin=gxint-numxticleft*gxtic;
	for (var i=0; i<numxtic; i++) {
	  curint=Math.round(gxtic*i+xticmin);
	  if (curint!=Math.round(gxint)) {gstr+='<v:line from="'+curint+','+gymin+'" to="'+curint+','+gymax+'" ><v:stroke '+this.VMLminoryaxisstroke+' /></v:line>';}
	}

// draw x-axis tics
	gstr+='<v:shape style="'+gstyle+'"><v:path v="';
	for (var i=0; i<numxtic; i++) { gstr+='m '+Math.round(xticmin+i*gxtic)+','+Math.round(gyint)+' r 0,'+((xticloc=="top" ? -1 : 1)*gticsize)+' x ';}
	gstr+='e" /><v:stroke '+this.VMLmajoraxisstroke+' /><v:fill on="false" /></v:shape>';

// draw y-axis tics
	gstr+='<v:shape style="'+gstyle+'"><v:path v="';
	for (var i=0; i<numytic; i++) { gstr+='m '+Math.round(gxint)+','+Math.round(yticmin-i*gytic)+' r '+((yticloc=="right" ? 1 : -1)*gticsize)+',0 x ';}
	gstr+='e" /><v:stroke '+this.VMLmajoraxisstroke+' /><v:fill on="false" /></v:shape>';
//9712291539 above draw 2D axis equal level lines
/*9712291529 del */
}

// draw titles
	if (this.title) {
	nonchar=0; 
	for (var i=0; i<this.title.length; i++) {if (this.title.charAt(i)==";") {nonchar++;}}
	gstr+='<span style="'+this.CSStitlefont+' position:absolute; text-align:center; top: '+0.5*this.pad_top;
	gstr+='pt; left: '+(0.5*gwt/gxpt-(this.title.length-5.5*nonchar)*title_pt*0.25)+'pt;">'+this.title+'</span>';
	}
	if (this.xaxis) {
	nonchar=0; 
	for (var i=0; i<this.xaxis.length; i++) {if (this.xaxis.charAt(i)==";") {nonchar++;}}
	gstr+='<span style="'+this.CSSxaxisfont+' position:absolute; text-align:center; top: '+((gymin+0.5*(pad_b-xaxis_pt*gxpt))/gxpt+(xticloc=="bottom" ? 0.75*tic_pt:0));
	gstr+='pt; left: '+(0.5*gwt/gxpt-(this.xaxis.length-5.5*nonchar)*xaxis_pt*0.25)+'pt;">'+this.xaxis+'</span>';
	}
	if (this.yaxis) { 
	gstr+='<v:shape style="'+gstyle;
	gstr+='" path="M '+((0.25*this.pad_left+0.5*yaxis_pt)*gxpt)+','+gymin+' L '+((0.25*this.pad_left+0.5*yaxis_pt)*gxpt)+','+gymax+'" fillcolor="'+this.VMLyaxisfontcolor+'">';
	gstr+='<v:stroke on="false" /><v:path textpathok="true" />';
	gstr+='<v:textpath on="true" style="'+this.CSSyaxisfont+'" string="'+this.yaxis+'" /></v:shape>';
	}

} // end of draw graph background


// hold on to previous plot
  if (this.lastplot != "") {
	gstr=this.lastplot.substring(0,this.lastplot.length-10);
	gstrtemp=gstr;
  }

// draw lines
  for (var n=0; n<lines.length; n++) {
  if (lines[n].drawline && lines[n].x.length>1) {
	gstr+='<v:polyline points="';
	for (i=0; i<lines[n].x.length; i++) {gstr+= Math.round(gxmin+(lines[n].x[i]-xmin)*xscl)+" "+Math.round(gymin-(lines[n].y[i]-ymin)*yscl)+" ";}
	gstr+='" title="'+lines[n].label+'" ><v:stroke '+lines[n].VMLstroke+' /><v:fill on="false" /></v:polyline>';
  }}


// draw points
  for (var n=0; n<lines.length; n++) {
  if (lines[n].drawpoints && lines[n].x.length>0) {
	gstr+=this.VMLpointshape(lines[n].VMLpointshapetype);
	for (i=0; i<lines[n].x.length; i++) {
		gstr+='<v:shape type="#'+(lines[n].VMLpointshapetype).toLowerCase()+'" style="width:'+lines[n].pointsize*gxpt+'; height:'+lines[n].pointsize*gxpt;
		gstr+='; top:'+Math.round(gymin-0.5*lines[n].pointsize*gxpt-(lines[n].y[i]-ymin)*yscl)+'; left:'+Math.round(gxmin-0.5*lines[n].pointsize*gxpt+(lines[n].x[i]-xmin)*xscl);
		ptitle = (lines[n].mouseoverlabels) ? lines[n].labels[i] : lines[n].x[i]+','+lines[n].y[i]; 
		gstr+='" title="'+ptitle+'" fillcolor="'+lines[n].pointfillcolor+'"';
		gstr+=' strokecolor="'+lines[n].pointstrokecolor+'" />';
	}
  }}

// draw labels
  for (var n=0; n<lines.length; n++) { 
  if (lines[n].drawlabels && lines[n].labels.length>0) { 
	for (i=0; i<lines[n].labels.length; i++) { 
		gstr+='<span style="font: '+lines[n].labelsize+'pt '+lines[n].labelfont+'; position:absolute;';
		gstr+=' top:'+Math.round((gymin-1.5*lines[n].labelsize*gxpt-(lines[n].y[i]-ymin)*yscl)/gxpt)+'pt; left:'+Math.round((gxmin+0.5*lines[n].labelsize*gxpt+(lines[n].x[i]-xmin)*xscl)/gxpt)+'pt; ';
		gstr+=' color:'+lines[n].labelcolor+'">'+lines[n].labels[i]+'</span>';
	}
  }}

if(showXYcoord1orNot0==1) //9912140643
{ //9712291548 delete 2D axis
//9712291540 below need variable defined in "9712291529 del" section

if (this.lastplot == "") { // don't redraw graph background if called multiple times
// draw x-axis labels
	if (xticloc!="none") {
	for (var i=0; i<numxtic; i++) { 
		  if (xticloc=="top") {
			gstr+='<span style="'+GXstyle+' top: '+((gyint-gticsize*1.25)/gxpt-8)+'pt; left: '+((xticmin+i*gxtic-0.5*gticsize)/gxpt)+'pt;">';
		  }
		  else {
			gstr+='<span style="'+GXstyle+' top: '+((gyint+gticsize*1.25)/gxpt)+'pt; left: '+((xticmin+i*gxtic-0.5*gticsize)/gxpt)+'pt;">';
		  }
		gstr+=xticlabels[i]+'</span>';
	}}

// draw y-axis labels
	if (yticloc!="none") {
	for (var i=0; i<numytic; i++) { 
		  if (yticloc=="right") {
		  	gstr+='<span style="'+GYstyle+' top: '+((yticmin-i*gytic-gticsize)/gxpt)+'pt; left: '+((gxint+gticsize*1.5)/gxpt)+'pt;">';
		  }
		  else {
		  	gstr+='<span style="'+GYLstyle+' top: '+((yticmin-i*gytic-gticsize)/gxpt)+'pt; left: '+((gxint-gticsize)/gxpt-0.5*(yticcharnum+1)*tic_pt)+'pt;">';
		  }
		  gstr+=yticlabels[i]+'</span>';
	}}
} // end of draw graph background
/**9712291534 del
9712291536 success delete 2D axis
 */
} //9712291548 delete 2D axis


// close and return output 
	gstr+='</v:group>';
  	if (this.numplots > 0) {this.lastplotadded[this.numplots]=gstr.length-gstrtemp.length;}
	else {this.lastplotadded[0]=gstr.length;}
	this.numplots++;
	this.lastplot=gstr;  // save this output in memory

	return gstr;

} // end function




// function to undo last added line, label or arrow from the plot

XYGraph.prototype.DeleteLast = function () {
	if (this.numplots > 1) {
		gstr=this.lastplot.substring(0,this.lastplot.length-this.lastplotadded[this.numplots-1]+1);
		gstr+='</v:group>';
		this.lastplot=gstr;
		this.numplots--;
	}
	return gstr;
} // end function



XYGraph.prototype.Findedge = function (x1,x2,y1,y2,xmax,xmin,ymax,ymin) {

	x=0; y=0;
    if (!isNaN(x2)) {
	if (!isFinite(x2)) {
		switch (x2) {
			case Number.POSITIVE_INFINITY: x2 = 999E+99; break;
			case Number.NEGATIVE_INFINITY: x2 = -999E+99; break;
		}
	}
	if (!isFinite(y2)) {
		switch (y2) {
			case Number.POSITIVE_INFINITY: y2 = 999E+99; break;
			case Number.NEGATIVE_INFINITY: y2 = -999E+99; break;
		}
	}

	angle = Math.atan2(y2-y1,x2-x1);
	angle += (angle > 0 ? 0 : 2*Math.PI);

	slope = (y2-y1)/(x2-x1);
	Mxx = Math.atan2(ymax-y1,xmax-x1); Mxx += (Mxx > 0 ? 0 : 2*Math.PI);
	Mnx = Math.atan2(ymax-y1,xmin-x1); Mnx += (Mnx > 0 ? 0 : 2*Math.PI);
	Mnn = Math.atan2(ymin-y1,xmin-x1); Mnn += (Mnn > 0 ? 0 : 2*Math.PI);
	Mxn = Math.atan2(ymin-y1,xmax-x1); Mxn += (Mxn > 0 ? 0 : 2*Math.PI);

	switch (true) {
		case (angle>=Mxx && angle<Mnx) : 
			y = ymax;
			x = (ymax-y1)/slope+x1;
			break;
		case (angle>=Mnx && angle<Mnn) :
			x = xmin;
			y = (xmin-x1)*slope+y1;
			break;
		case (angle>=Mnn && angle<Mxn) :
			y = ymin;
			x = (ymin-y1)/slope+x1;
			break;
		case (angle>=Mxn || angle<Mxx) :
			x = xmax;
			y = (xmax-x1)*slope+y1;
			break;
	}
     }

	return [x,y]; 
} // end function



// point shapetype definitions, these can be modified and expanded

XYGraph.prototype.VMLpointshape = function (shapename) {
	switch (shapename.toLowerCase()) {
	
	case "diamond" :
		return '<v:shapetype id="diamond" coordsize="500,500" path=" m 250 500 l 500 250 250 0 0 250 x e" />';
	case "square" :
		return '<v:shapetype id="square" coordsize="350,350" path=" m 0 0 l 0 350 350 350 350 0 x e" />';
	case "triangle" :
		return '<v:shapetype id="triangle" coordsize="400,400" path=" m 200 0 l 400 400 0 400 x e" />';
	case "circle" :
		return '<v:shapetype id="circle" coordsize="350,350" path=" m 0 175 l 23 262 88 327 175 350 262 327 327 262 350 175 327 88 262 23 175 0 88 23 23 88 x e" />';
	case "x" :
		return '<v:shapetype id="x" coordsize="350,350" path=" m 0 0 l 350 350 e m 0 350 l 350 0 e" />';
	case "none" :
		return '<v:shapetype id="none" coordsize="350,350" filled="false" stroked="false" path=" m 0 0 l 0 350 350 350 350 0 x e" />';
	}
} // end function



XYGraph.prototype.Drawarrow = function (arrowdef) {

	gstr=gstr.substring(0,gstr.length-10);
	gstrtemp=gstr;

	arrowdef.x = Number(arrowdef.x)
	arrowdef.y = Number(arrowdef.y)
	arrowdef.rotation = Number(arrowdef.rotation)
	arrowdef.length = Number(arrowdef.length)
	arrowdef.size = Number(arrowdef.size)

	xpoint=Math.round(gxmin+(arrowdef.x-xmin)*xscl+0.5*arrowdef.size*gxpt*Math.sin(arrowdef.rotation*Math.PI/180));
	ypoint=Math.round(gymin-(arrowdef.y-ymin)*yscl-0.5*arrowdef.size*gxpt*Math.cos(arrowdef.rotation*Math.PI/180));

	xpoint2=Math.round(xpoint+arrowdef.length*gxpt*Math.sin(arrowdef.rotation*Math.PI/180));
	ypoint2=Math.round(ypoint-arrowdef.length*gxpt*Math.cos(arrowdef.rotation*Math.PI/180));

	gstr+='<v:line from="'+xpoint+','+ypoint+'" to="'+xpoint2+','+ypoint2+'" ><v:stroke weight="'+arrowdef.lineweight+'pt"; color="'+arrowdef.color+'"; dashstyle="'+arrowdef.dashstyle+'"; /></v:line>';

	xpoint3=Math.round(xpoint2+1.25*arrowdef.labelsize*gxpt*Math.sin(arrowdef.rotation*Math.PI/180));
	ypoint3=Math.round(ypoint2-1.25*arrowdef.labelsize*gxpt);

	if(Math.cos(arrowdef.rotation*Math.PI/180)>0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint3/gxpt)+'pt; left: '+Math.round(xpoint3/gxpt-0.25*arrowdef.label.length*arrowdef.labelsize)+'pt; ';}
	if(Math.cos(arrowdef.rotation*Math.PI/180)<0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt)+'pt; left: '+Math.round(xpoint3/gxpt-0.25*arrowdef.label.length*arrowdef.labelsize)+'pt; ';}
	if(Math.sin(arrowdef.rotation*Math.PI/180)>0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt-arrowdef.labelsize*(0.5+Math.cos(arrowdef.rotation*Math.PI/180)))+'pt; left: '+Math.round(xpoint3/gxpt-0.25*arrowdef.label.length*arrowdef.labelsize)+'pt; ';}
	if(Math.sin(arrowdef.rotation*Math.PI/180)<0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt-arrowdef.labelsize*(0.5+Math.cos(arrowdef.rotation*Math.PI/180)))+'pt; left: '+Math.round(xpoint3/gxpt-0.25*arrowdef.label.length*arrowdef.labelsize)+'pt; ';}

//	gstr+='<span style="font: '+arrowdef.labelsize+'pt Arial; font-weight:bold; position:absolute;';
//9506241341 把粗體 'bold' 改為一般 'regular'
	gstr+='<span style="font: '+arrowdef.labelsize+'pt Arial; font-weight:regular; position:absolute;';
	gstr+=position+'color:'+arrowdef.labelcolor+'">'+arrowdef.label+'</span>';

	xpoint=Math.round(gxmin-0.5*arrowdef.size*gxpt+(arrowdef.x-xmin)*xscl+0.5*arrowdef.size*gxpt*Math.sin(arrowdef.rotation*Math.PI/180));
	ypoint=Math.round(gymin-0.5*arrowdef.size*gxpt-(arrowdef.y-ymin)*yscl-0.5*arrowdef.size*gxpt*Math.cos(arrowdef.rotation*Math.PI/180));

	gstr+=arrowdef.arrowhead;
	gstr+='<v:shape type="#arrowhead" style="width:'+arrowdef.size*gxpt+'; height:'+arrowdef.size*gxpt;
	gstr+='; top:'+ypoint+'; left:'+xpoint;
	gstr+='" title="'+arrowdef.label+'" fillcolor="'+arrowdef.color+'"';
	gstr+='"; style= "rotation:'+arrowdef.rotation+'deg"';
	gstr+=' strokecolor="'+arrowdef.color+'" />';
	
	gstr+='</v:group>';
	this.lastplot=gstr;
	this.lastplotadded[this.numplots]=gstr.length-gstrtemp.length;
	this.numplots++;
	return gstr;

} // end function



XYGraph.prototype.Drawlabel = function (labeldef) {

	gstr=gstr.substring(0,gstr.length-10);
	gstrtemp=gstr;

	labeldef.x = Number(labeldef.x)
	labeldef.y = Number(labeldef.y)
	labeldef.rotation = Number(labeldef.rotation)
	labeldef.length = Number(labeldef.length)

	xpoint=Math.round(gxmin+(labeldef.x-xmin)*xscl+0.5*labeldef.labelsize*gxpt*Math.sin(labeldef.rotation*Math.PI/180));
	ypoint=Math.round(gymin-(labeldef.y-ymin)*yscl-0.5*labeldef.labelsize*gxpt*Math.cos(labeldef.rotation*Math.PI/180));

	xpoint2=Math.round(xpoint+labeldef.length*gxpt*Math.sin(labeldef.rotation*Math.PI/180));
	ypoint2=Math.round(ypoint-labeldef.length*gxpt*Math.cos(labeldef.rotation*Math.PI/180));

	xpoint3=Math.round(xpoint2+1.25*labeldef.labelsize*gxpt*Math.sin(labeldef.rotation*Math.PI/180));
	ypoint3=Math.round(ypoint2-1.25*labeldef.labelsize*gxpt);

	if(Math.cos(labeldef.rotation*Math.PI/180)>0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint3/gxpt)+'pt; left: '+Math.round(xpoint3/gxpt-0.25*labeldef.label.length*labeldef.labelsize)+'pt; ';}
	if(Math.cos(labeldef.rotation*Math.PI/180)<0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt)+'pt; left: '+Math.round(xpoint3/gxpt-0.25*labeldef.label.length*labeldef.labelsize)+'pt; ';}
	if(Math.sin(labeldef.rotation*Math.PI/180)>0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt-labeldef.labelsize*(0.5+Math.cos(labeldef.rotation*Math.PI/180)))+'pt; left: '+Math.round(xpoint3/gxpt-0.25*labeldef.label.length*labeldef.labelsize)+'pt; ';}
	if(Math.sin(labeldef.rotation*Math.PI/180)<0.707) 
		{position=' text-align:center; top:'+Math.round(ypoint2/gxpt-labeldef.labelsize*(0.5+Math.cos(labeldef.rotation*Math.PI/180)))+'pt; left: '+Math.round(xpoint3/gxpt-0.25*labeldef.label.length*labeldef.labelsize)+'pt; ';}

//	gstr+='<span style="font: '+labeldef.labelsize+'pt Arial; font-weight:bold; position:absolute;';
//9506241347 把粗體 'bold' 改為一般 'regular'
//	gstr+='<span style="font: '+labeldef.labelsize+'pt Arial; font-weight:regular; position:absolute;';
//9506241352 把字體 'Arial' 改為 'Courier New' 改為 'Courier' 仍然太粗
//9506241355 把字體 'Arial' 改為 'Dotum' 得到比較細的字體
	gstr+='<span style="font: '+labeldef.labelsize+'pt Dotum; font-weight:regular; position:absolute;';
	gstr+=position+'color:'+labeldef.labelcolor+'">'+labeldef.label+'</span>';

	gstr+=this.VMLpointshape(labeldef.VMLpointshapetype);

	gstr+='<v:shape type="#'+(labeldef.VMLpointshapetype).toLowerCase()+'" style="width:'+labeldef.pointsize*gxpt+'; height:'+labeldef.pointsize*gxpt;
	gstr+='; top:'+Math.round(gymin-0.5*labeldef.pointsize*gxpt-(labeldef.y-ymin)*yscl,2)+'; left:'+Math.round(gxmin-0.5*labeldef.pointsize*gxpt+(labeldef.x-xmin)*xscl);
	gstr+='" fillcolor="'+labeldef.pointfillcolor+'"';
	gstr+=' strokecolor="'+labeldef.pointstrokecolor+'" />';

	gstr+='</v:group>';
	this.lastplot=gstr;
	this.lastplotadded[this.numplots]=gstr.length-gstrtemp.length;
	this.numplots++;
	return gstr;

} // end function




// 9507121343
function stepf(t0,bgn0)
{
  if(t0<bgn0) return 0.;
  return 1.;

} // end function // 9507121346
// 9507121356
// stepf(t,3) get t<3  value 0
// stepf(t,3) get t>=3 value 1
//
// (1-stepf(t,3)) get t<3  value 1
// (1-stepf(t,3)) get t>=3 value 0
//
// (stepf(t,2)-stepf(t,3))
//  get  2<=t<3  value 1
//  t<2 and t>=3 value 0
// 9507121400



/*
95,07,08,14,55,00
http://www.univie.ac.at/future.media/moe/JavaCalc/jcintro.html
c:\$fm\js\math9507\JavaCalc-jcintro.html

95,07,08,15,00
http://www.univie.ac.at/future.media/moe/JavaCalc/parser.js
c:\$fm\js\math9507\JavaCalc-jcintro-parser.js


Return to MathCollections

Ken Kikuchi
Comment me: kikuchi@mix.or.jp
Last updated: 2/29/2000

9507132210 include
function loggamma(x)
and
function gamma(x) 

/**/


// Ab hier (17. 3. 2000) von Ken's Script ernommen:

function factorial(n) {  /* factorial */
  with(Math) {
  if (n<0)  /* if negative */
  	return gamma(n+1);
  else if ((n == 0) || (n == 1))
    return 1;
  else if (abs(n)-floor(abs(n))==0 ) /* if positive integer */
    return n * factorial(n-1) ;
  else         /* if non-integer */
    return gamma(n+1);
} }


function loggamma(x)  { /* log gamma */
var u0; //9507142008

    with(Math) {
        var v=1;
        var w=0;
        var z=0;
        while ( x<8 ) { v*=x; x++ }
        w=1/(x*x);

u0= //9507142009
((((((((-3617/122400)*w + 7/1092)*w
         -691/360360)*w + 5/5940)*w
         -1/1680)*w + 1/1260)*w
         -1/360)*w + 1/12)/x 
+ 0.5 * log(2*PI)-log(v)-x+(x-0.5)*log(x) ;

//status='x=['+x+']; w=['+w+']; u0=['+u0+'] 9507142010';

        return u0;

} }



function gamma(x) {  /* gamma */

//9507141940
var i0;
var y0='';
var g0,g1,g2; //9507142019

for(i0=0;i0<(x+'').length;i0++)
{
  if(i0==0&&(x+'').charAt(i0)=='(')continue;
  if((x+'').charAt(i0)==')')break; //9507141944
  y0+=(x+'').charAt(i0);
}

x=parseFloat(y0);

    with(Math) {
        if ( x <= 0 )
        {
            if (abs(x)-floor(abs(x))==0 )
                return "ComplexInfinity" ;
            else
            {
g0=loggamma(1-x);
g1=PI/( sin(PI*x) * exp( g0 ) );
 return g1;
            }
        }
        else 
        {
g0=loggamma(x);
g1=exp( g0 ) ;
            return g1 ;
        }
} }



// 9506191230
function wipeCurve(d3)
{
/**
var MyGraph = new XYGraph();

// 下面刪除曲線圖 9510221147
  var j5='document.getElementById("graphdiv'+d3+'").innerHTML="";';
  eval(j5); 

// 下面刪除文字說明
  j5='document.getElementById("eqnDoc"+d3).innerHTML=""';
  eval(j5); 
9510241225 change to next
/**/
document.getElementById("graphdiv"+d3).innerHTML="";
document.getElementById("eqnDoc"+d3).innerHTML=""
}



// DrawGraph() 可以畫統計數據
// DrawGraf2() 刪除統計數據指令 9510182128
//
function DrawGraf2(argd2)
{
  var i0,i1,i2,i3,i4,i5;
  var sz1=2; 
  var sz2=5; 
  var sz3=5; 
  var MyGraph = new XYGraph();

  var ev0; 
  var ev1;
  var ev2='[';
  var ev3='[';

  var ouStr1="";
  var ouStr2="";
  var ouStr3="";

// 下面定義輸出方格一是否啟用。
  j4=0; 
  var box21=1;

  j5='if(document.aa'+argd2+'.radio1[0].checked==1)box21=0;';
  eval(j5); 
//9510241228 change to next
//if('document.aa'+argd2+'.radio1[0].checked'==1)box21=0;

// 下面定義輸出方格二是否啟用。
  var box22=1;
//j5='if(document.aa'+argd2+'.radio1[0].checked==1)box22=0;';
//9510241249 change radio1 to radio2
  j5='if(document.aa'+argd2+'.radio2[0].checked==1)box22=0;';
  eval(j5);
//9510241236 change to next
//if('document.aa'+argd2+'.radio2[0].checked'==1)box22=0;

// 下面定義輸出方格三是否啟用。
  var box23=1;
  j5='if(document.aa'+argd2+'.radio3[0].checked==1)box23=0;';
  eval(j5); 
//9510241237 change to next
//if('document.aa'+argd2+'.radio3[0].checked'==1)box23=0;
//9510241242 all 3 change are wrong
//
//9510241255 because above change evaluate
//if('document.aa601.radio3[0].checked'==1)box23=0;
// the string
// 'document.aa601.radio3[0].checked'
// is never  1  evaluation carry out
// and never true, box are always open
// must use eval(), can not drop eval()
//9510241257

// 程式內定輸出方格一至方格三都不啟用，以增加計算速度。
// 使用者可以點選 '1' 按鈕，啟用輸出方格。

// 避免上次殘留數據誤會為本次數據
// 下面騰空輸出方格一至方格三。
document.getElementById("box11"+argd2).value=
document.getElementById("box12"+argd2).value=
document.getElementById("box13"+argd2).value=
''; 

//定義五條曲線坐位（尚無曲線點集）
  ev0='var MyLines=';  
  ev3='[';
  for(i3=0;i3<sz3;i3++)
  {
    ev3+='""';
    if(i3<sz3-1)ev3+=',';
    else        ev3+=']';
  }
  ev0=ev0+ev3; 
  eval(ev0);
// window.clipboardData.setData("Text",ev0+"\n") 
// alert("ev0 定義五條曲線空座指令已經複製到剪貼簿 9510191735");
// ev0 字串如右﹕ var MyLines=["","","","",""]

// eval(ev0); 是執行空座定義

// 上面建立曲線坐位
// 下面指定曲線空座性質
// 曲線與公式不同，曲線是幾百個點組成的數據，
// 公式是數學列式，每走一步，變數都有指定值，
// 變數代以指定值後，公式產生一個點x,y坐標。
// 曲線（幾百個點）可以畫圖，公式不能直接畫圖。

// XYLine() 是 XYGraph() 專用之曲線宣告指令。
// 下面指定每個曲線空座性質為 new XYLine()
  for(i3=0;i3<sz3;i3++)  
  {
    MyLines[i3] = new XYLine();
  }

// 曲線內定使用大點字體，結果都是粗黑曲線。
// 下面指定每條曲線都不使用大點字體
  ev0='';
  ev1='MyLines[';
  ev2='].VMLpointshapetype="none";';
  for(i3=0;i3<sz3;i3++)
  {
    ev0=ev1+i3+ev2; //避免輸出粗黑曲線
    eval(ev0);      //9510201524 加入
  }
// 執行 MyLines[*].VMLpointshapetype="none";
// 之後的曲線端點都用微點，比較好看。[*]代表[0]至[4]

  var MyArrow = new Arrow();
  var MyLabel1 = new Label(); 
  var UpLimit=1000; //每條曲線最多一千點
  var LoLimit=2;    //每條曲線至少兩點

//下面決定畫圖板面積大小
  var jj= 
  document.getElementById("boardH"+argd2).value;
  jj=parseFloat(jj);
  if(!isNaN(jj)&&jj>0)
  MyGraph.gheight=jj; 
  else 
  MyGraph.gheight=300; 
  jj= 
  document.getElementById("boardW"+argd2).value;
  jj=parseFloat(jj);
  if(!isNaN(jj)&&jj>0)
  MyGraph.gwidth=jj; 
  else
  MyGraph.gwidth=300;
//上面決定畫圖板面積大小
//輸入表格有一行為
//〔 畫板寬度 300 畫板高度 300 單位是「點」。 〕
//此行讓使用者決定畫板面積

//定義五條公式坐位（尚無公式）
  ev0='var eq5xy=';
  ev1='[';
  ev2='[';
  ev3='[';
  for(i3=0;i3<sz3;i3++)
  {
    ev3+='""';
    if(i3<sz3-1)ev3+=',';
    else        ev3+=']';
  }
  for(i2=0;i2<sz2;i2++)
  {
    ev2+=ev3;
    if(i2<sz2-1)ev2+=',';
    else        ev2+=']';
  }
  for(i1=0;i1<sz1;i1++)
  {
    ev1+=ev2;
    if(i1<sz1-1)ev1+=',';
    else        ev1+=']';
  }
  ev0=ev0+ev1; 
  eval(ev0);

if(box23)
ouStr3+=
 "三個自由度變數 eq5xy[i1][i2][i3] 使用下行字串定義 [eval(ev0);] ev0=\n"
+ev0+"\n"
+"0<=i1<sz1=2;  x(t),y(t) 兩個函數組成一條曲線\n"
+"0<=i2<sz2=5;  常數a,b 計值，變數t 計值，共需五步\n"
+"0<=i3<sz3=5;  程式容許一次畫五條曲線 9510191434\n"
+"i2==0 是使用者輸入的原始公式。\n";
+"　　　　　自變數 x與 exp()混同，自變數 t 與tan()混同\n";
+"i2==1 是程式把 x改為tt及把 t改為tt之後的公式\n";
+"i2==2 是程式把變動常數 a代以實值之後的公式（暫時不用）\n";
+"i2==3 是程式把變動常數 b代以實值之後的公式（暫時不用）\n";
+"i2==4 是程式把變數 tt 代以實值之後的公式\n";
+"eq5xy[*][4][*] 是可以用來計算曲線點的公式\n";
+"\n";
// 上面建立公式坐位
// 下面讀入公式值
// 把使用者定義的公式抄入 eq5xy[i1][i2][i3]
// i1=0 f(x); i1=1 f(y);
// [i2]=[0] = 使用者定義的公式
// i3=0 第一公式 ... i3=4 第五公式
  for(i3=0;i3<sz3;i3++)
  {
/**del eval(
ev0='eq5xy[0][0][i3]=document.getElementById("func'+(i3+1)+'x"+argd2).value;';
eval(ev0);
ev0='eq5xy[1][0][i3]=document.getElementById("func'+(i3+1)+'y"+argd2).value;';
eval(ev0);
9510241220 change to next OK
/**/
eq5xy[0][0][i3]=document.getElementById("func"+(i3+1)+"x"+argd2).value;
eq5xy[1][0][i3]=document.getElementById("func"+(i3+1)+"y"+argd2).value;
  } // 9510241220

// 把使用者定義的公式抄入 eq5xy[*][0][*]
// 改為本程式所要求的格式 eq5xy[*][1][*]
// 本程式要求自變數x 改為 tt 避免與 exp() 混同
// 本程式要求自變數t 改為 tt 避免與 tan() 混同
// 使用者輸入的公式不要直接用 tt 。 9510202120
  for(i3=0;i3<sz3;i3++)
  {
/**del eval
ev0='eq5xy[0][1][i3]=toSyntax(eq5xy[0][0][i3]);';
eval(ev0);
ev0='eq5xy[1][1][i3]=toSyntax(eq5xy[1][0][i3]);';
eval(ev0);
/*9510241305 change to next*/
eq5xy[0][1][i3]=toSyntax(eq5xy[0][0][i3]);
eq5xy[1][1][i3]=toSyntax(eq5xy[1][0][i3]);
  }

//定義五條曲線變數之上下限的坐位
  ev0='var tMinMax=';
  ev1='[';
  ev3='[';
  for(i3=0;i3<sz3;i3++) // sz3=5 五條曲線
  {
    ev3+='""';
    if(i3<sz3-1)ev3+=',';
    else        ev3+=']';
  }
  for(i1=0;i1<sz1;i1++) // sz1=2 兩個端點
  {
    ev1+=ev3;
    if(i1<sz1-1)ev1+=',';
    else        ev1+=']';
  }
  ev0=ev0+ev1; 
  eval(ev0);
// 上面建立曲線上下限的坐位
// 下面讀入上下限值
  for(i3=0;i3<sz3;i3++)
  {
    ev0='tMinMax[0]['; // 9510191929
    ev1=']=document.getElementById("t'+(i3+1)+'Min"+argd2).value;';
    ev0+=i3+ev1;
    eval(ev0);   //9510191931

    ev0='tMinMax[1]['; // 9510191929
    ev1=']=document.getElementById("t'+(i3+1)+'Max"+argd2).value;';
    ev0+=i3+ev1;
    eval(ev0);   //9510191932
  } // 9510191933

// 字串 tMinMax[][] 的 1 加 2 得到 12
// 數字 tMinMax[][] 的 1 加 2 得到 3
// 下面把字串 tMinMax[][] 改為數字 tMinMax[][]
  for(i3=0;i3<sz3;i3++)
  {
tMinMax[0][i3]=parseFloat(tMinMax[0][i3]); // 9510192047
tMinMax[1][i3]=parseFloat(tMinMax[1][i3]);
  }  // 9510192048

// 下面是畫曲線圖的標題 9510221650 處不能印出標題
// 下面是畫曲線圖的標題 9510221651 此處可以印出標題
    MyGraph.title= 
document.getElementById("title0"+argd2).value;

  var flag0=0;
  for(i3=0;i3<sz3;i3++)
  {
    if(tMinMax[0][i3]>tMinMax[1][i3])
    {
      flag0=1;
    alert("起點 t"+(i3+1)+"="+tMinMax[0][i3]+">"+tMinMax[1][i3]+"=終點 t"+(i3+1)+"\n"
+"本卷只容許自變數 t 由小至大，也只接受正值步長。\n"
+"如果您需要由大 t 至小 t 及負值步長，請修改指令。\n"
+"9510191952"
);
    } //9510191952
  }
  if(flag0) return;

//定義五條曲線步長坐位（尚無步長值）
  ev0='var tStep=[';  
  for(i3=0;i3<sz3;i3++)
  {
    ev0+='""';
    if(i3<sz3-1)ev0+=',';
    else        ev0+=']';
  }
  eval(ev0); // 9510202129
// 上面建立步長坐位
// 下面讀入步長值
  for(i3=0;i3<sz3;i3++)
  {
tStep[i3]=document.getElementById("t"+(i3+1)+"Len"+argd2).value;
tStep[i3]=parseFloat(tStep[i3]);
// 9510241422 test ok

    if(tStep[i3]<0)
    {
    alert("曲線"+(i3+1)+" 步長 tStep="+tStep[i3]+"<0\n"
+"本卷只容許正值步長，現在為負值步長，\n請修改指令卷。"
+"9510192000");
    return;
    }

ev1=0.001; //9510241458

    if(tStep[i3]<ev1)
    {
if(box23)
    ouStr3+=
'\n曲線'+(i3+1)+' 原步長 '+tStep[i3]+' 改為 '+ev1
+' 若您需要微步長請\n打開源碼找'
+'「ev1=0.001;」 修改數值。 9510241451\n\n';

//  tStep[i3]=0.001;
ev0='document.getElementById("t'+(i3+1)
   +'Len"+argd2).value=tStep[i3]=ev1';
eval(ev0); //9510241443
    }

  } // 9510202134

//定義每條曲線總步數坐位（尚無步數值）
// 9510192153
  ev0='var t0Total=';  
  ev3='[';
  for(i3=0;i3<sz3;i3++)
  {
    ev3+='""';
    if(i3<sz3-1)ev3+=',';
    else        ev3+=']';
  }
  ev0=ev0+ev3; 
  eval(ev0);
// 上面建立步數坐位
// 下面計算步數值
  for(i3=0;i3<sz3;i3++)  
  {
    t0Total[i3]=(tMinMax[1][i3]-tMinMax[0][i3])/tStep[i3];

    if(t0Total[i3]>UpLimit)t0Total[i3]=UpLimit; // 1000
    if(t0Total[i3]<LoLimit)t0Total[i3]=LoLimit; // 2
    if(isNaN(t0Total[i3])) t0Total[i3]=0; //不畫曲線
  }

// 下面定義橫軸範圍及定義縱軸範圍
// XYGraph 堅持把 (0,0) 容納於圖面，所以
// 雖然使用者定義圖面不包括 (0,0) ，實際畫出
// 的曲線圖仍然有 (0,0) 點，有些情況，這種性質
// 使得圖面大半為空白。 9510211754
  MyGraph.xmax=
  document.getElementById("maxX"+argd2).value;
  MyGraph.xmin=
  document.getElementById("minX"+argd2).value;
  MyGraph.ymax=
  document.getElementById("maxY"+argd2).value;
  MyGraph.ymin=
  document.getElementById("minY"+argd2).value;

// 下面定義五條曲線之性質、寬度、顏色、實虛
// 及計算五條曲線每步落點之坐標。
  for(i3=0;i3<sz3;i3++)
  {
    k1='document.getElementById("width'
    +(i3+1)+argd2+'").value';
    k1=eval(k1);
    k2='document.getElementById("color'
    +(i3+1)+argd2+'").value';
    k2=eval(k2);
    k3='document.getElementById("style'
    +(i3+1)+argd2+'").value';
    k3=eval(k3);
    k4="\"weight='"+k1+"pt'; color='"
    +k2+"'; dashstyle='"+k3+"';\"";
    MyLines[i3].VMLstroke = eval(k4); 
if(box23)
    ouStr3+="\n曲線"+(i3+1)+"之寬窄、顏色、實虛定義如下\nk4=["+k4+"]\n\n";//9510201509

// 上面定義五條曲線之性質、寬度、顏色、實虛
// 下面計算五條曲線每步落點之坐標。t 是自變數
// 每走一步，t 都有一個新值，把t 值代入公式，
// 可以計算該步落點之 x,y坐標值

    for(j4=0;j4<t0Total[i3];j4++)
    { // 以下計算曲線點的數值
      t = tMinMax[0][i3]+j4*tStep[i3];

// 上面t 得到數值，例如，計算得到 0.32
// 下面把公式中的自變數 tt 改為上面算出的數值
// 例如 sin(tt) 改為 sin(0.32)
// 9510222211 增加 'with(Math){' 及 '}'
      eq5xy[0][4][i3]='with(Math){'+eq5xy[0][1][i3].replace(/tt/g, t)+'}'
      eq5xy[1][4][i3]='with(Math){'+eq5xy[1][1][i3].replace(/tt/g, t)+'}'

// 公式 sin(0.32) 可以用 eval(sin(0.32)) 計值
// 三角函數的輸入值必須是弧度，不能是角度，57.2957795 角度=1弧度
// 計值之後，公式 sin(tt) 變為 0.31456
// 這就是 x坐標值（或y坐標值），
// 點的坐標值存入曲線點串中
      MyLines[i3].x[j4]=eval(eq5xy[0][4][i3]);
      MyLines[i3].y[j4]=eval(eq5xy[1][4][i3]);
// 上面用來畫圖
// 下面可以閱讀每點的坐標值
if(box21)
 ouStr1+=MyLines[i3].x[j4]+', '+MyLines[i3].y[j4]+'\n';//9510201217

if(box22)
 ouStr2+=t+', '+MyLines[i3].x[j4]+', '+MyLines[i3].y[j4]+'\n';//9510201217
    } // 結束 for(j4=0;j4<t0Total[i3];j4++)
      // 以上計算曲線點的數值

    if(box21)
    {
    ouStr1+='以上是曲線'+(i3+1)+'，共有 '+t0Total[i3]+' 點。\n';//9510221039
    if(i3<sz3-1)
    ouStr1+='以下是曲線'+(i3+2)+'，共有 '+t0Total[i3+1]+' 點。\n';
    }

    if(box22)
    {
    ouStr2+='以上是曲線'+(i3+1)+'，共有 '+t0Total[i3]+' 點。\n';//9510221041
    if(i3<sz3-1)
    ouStr2+='以下是曲線'+(i3+2)+'，共有 '+t0Total[i3+1]+' 點。\n';
    }

    if(box23)
    {
 ouStr3+='曲線'+(i3+1)+' 最後一點的變數t計值後的公式如下\n';//9510221032
 ouStr3+='t='+t+'\nx='+eq5xy[0][4][i3]+'\ny='+eq5xy[1][4][i3]+'\n\n';//9510201217
    }

// 下面指令畫出一條曲線（假設總共五條曲線，這裏只畫一條曲線）
    MyGraph.Plot(MyLines[i3]); // 9510201141 加入畫曲線指令
  }  // 結束 for(i3=0;i3<sz3;i3++) 

  ev0="arrowform"+argd2; // 9510221402
  for (var i in MyArrow) {
    if (i != "arrowhead") {
    var n = document.forms[ev0][i]; 
    MyArrow[i] = ( n.value !="" ? n.value : null);
    }
  }

// 若箭頭坐標 x 或 y 值沒有定義
// 不畫箭頭。
  if( //9506211935
    !(
    document.forms[ev0][0].value==[]
    ||
    document.forms[ev0][1].value==[]
      )
    ) //9506211936 
    MyGraph.Drawarrow(MyArrow);

// 如果畫第 601 圖
// ev0 代表 labelform601 其中 601 （argd2） 動態改變
ev0="labelform"+argd2; // 9510221403
// 如果畫第 602 圖 argd2=602
// "labelform"+argd2 變為 labelform602
// 這種 argd2 值隨時改變，稱為「動態改變」
// 「動態改變」設計，一套輸入表格指令
// openTable(drawID,table01)
// 可以為無限多張圖片服務。9510231220
// 因為 drawID 有無限多個數字
// table01==0 畫圖，同時關閉輸入表格（不要修改）
// table01==1 畫圖，同時開啟輸入表格（希望修改）

//9506211753 
  for (var i in MyLabel1) { 
  var n = document.forms[ev0][i]; 
  if (n.type != "select-one") { 
  MyLabel1[i] = ( n.value !="" ? n.value : null);
  }
  else {
    MyLabel1[i] = n[n.selectedIndex].value;}
  }

// 若標簽坐標 x 或 y 值沒有定義
// 不畫標簽。
  if( //9506211938
    !(
    document.forms[ev0][0].value==[]
    ||
    document.forms[ev0][1].value==[]
     )
    )
  MyGraph.Drawlabel(MyLabel1);

if(box21)
 ouStr1+=
'\n每條曲線容許最多一千點，如果畫五條曲線，最好控制起點\n'
+'值、終點值、步長值，使每條曲線印一百點至兩百點，若一次\n'
+'印出五千點，爪哇簡稿的能力非常慢！　　9510221117\n'
;

if(box23)
 ouStr3+='\n只能看最後一點的公式，因為如果印出每點公式，資料太長，沒有必要。 9510221050\n';

// 下面在網頁實際畫出五曲線圖及標題及箭頭及註解
document.getElementById("graphdiv"+argd2).innerHTML=MyGraph;
//9510241215 上行可行

// 下面在曲線圖下面加註文字說明
  document.getElementById("eqnDoc"+argd2).innerHTML=document.getElementById("CurveDoc0"+argd2).value;
//9510241217 上行可行

// 下面把 x,y 存入輸出方格一
if(box21)
document.getElementById("box11"+argd2).value=ouStr1;//9510221025
// 這裏不是畫圖，是印出每一點坐標，便利閱讀。

// 下面把 t,x,y 存入輸出方格二
if(box22)
document.getElementById("box12"+argd2).value=ouStr2;//9510221026

// 下面把流程說明存入輸出方格三 
if(box23)
document.getElementById("box13"+argd2).value=ouStr3;//9510201215

} // 結束 function DrawGraf2(argd2)







// 9510230247
function closeStr(klozID)
{
document.getElementById("putTable"+klozID).innerHTML="";
}
// 9510230248 節省系統資源。當使用者關閉
// 輸入表格時，立即刪除建立表格的長串字串。
// 等於無物「=""」，就是刪除字串。








//9506191246
//toSyntax(inStr1) 更改公式如下
//把 't' 改為 '(tt)'
//把 'a' 改為 '(aa)'
//把 'b' 改為 '(bb)'
//避免困惑。
//'t' 是自變數
//'tan(t)' 改為 'tan((tt))'
//'a' 及 'b' 為變動常數
//'a*acos(t)' 改為 '(aa)*acos((tt))'
//'2+b' => '2+bb' 當 b=-1, 2+-1 ?! 錯！
//'2+b' => '2+(bb)' 當 b=-1 沒有麻煩。
//9506191250
//
function toSyntax(inStr1)
{
  var oustr0=""; //9506191548
  var oustr1=""; //9506191539
  var oustr2=""; //950619160 6
  var i0,i1,i2,i3,i4,i5;

//9506191404 't' 'a' 'b' 是待換字母
  var tab3="tab";
  var tab3len=tab3.length;
  var inStr2=new Array(tab3len+1); //9506191412

  for(i3=0;i3<=tab3len;i3++)
    inStr2[i3]=""; //9506191614

/**
由
 Math.tan(t*a/b)
*Math.cot(a/b+t*t)/(t/a-1.2*b)
+Math.abs(t+a-b)
改為
 Math.tan((tt)*(aa)/(bb))
*Math.cot((aa)/(bb)+(tt)*(tt))/((tt)/(aa)-1.2*(bb))
+Math.abs((tt)+(aa)-(bb))

i2 控制 't', 'a', 'b' 之取用序
inStr2[0] 存原有公式
inStr2[1] 存 't' 改為 '(tt)' 後之公式
inStr2[2] 存 'a' 改為 '(aa)' 後之公式
inStr2[3] 存 'b' 改為 '(bb)' 後之公式
/**/

  oustr1+=inStr1+'\n';
  inStr2[0]=inStr1;
  for(i2=0;i2<tab3len;i2++)
  {
   for(i1=0;i1<inStr2[i2].length;i1++)
   {
    if(inStr2[i2].charAt(i1)!=tab3.charAt(i2))
    inStr2[i2+1]+=inStr2[i2].charAt(i1); //9506191454
    else// 當 i2==0 測試 tab3.charAt(i2)=='t'
    {   // 當 i2==1 測試 tab3.charAt(i2)=='a'
        // 當 i2==2 測試 tab3.charAt(i2)=='b'
      if(inStr2[i2].charAt(i1-1)=='.' //Math.tan()  't' 左側有 '.'
       ||inStr2[i2].charAt(i1+1)=='(' //Math.sqrt() 't' 右側有 '('
        ) // tan 及 sqrt 兩個 't' 都不是自變數 't'
       inStr2[i2+1]+=inStr2[i2].charAt(i1); //9506191507. 照抄 't'

      else /*9506300225*/
      if( // 自變數 't' 不與其他字母相鄰
         ((inStr2[i2].charAt(i1+1)>='a' //Math.atan()
        &&inStr2[i2].charAt(i1+1)<='z'
         )
         ||
         (inStr2[i2].charAt(i1+1)>='A' //Math.atan()
        &&inStr2[i2].charAt(i1+1)<='Z'  //9506191641
         ))
         ||
         ((inStr2[i2].charAt(i1-1)>='a' //Math.atan()
        &&inStr2[i2].charAt(i1-1)<='z'
         )
         ||
         (inStr2[i2].charAt(i1-1)>='A' //Math.atan()
        &&inStr2[i2].charAt(i1-1)<='Z'  //9506191641
         ))
        ) // 't' 只是舉例，  'a' 及 'b' 相同。

       inStr2[i2+1]+=inStr2[i2].charAt(i1); //9506191507 照抄 't'
      else     // 下面 't' 是自變數 't'
               // 'a' 及 'b' 是變動常數，更改。
       inStr2[i2+1]+='('                    // 加入 '('
                    +inStr2[i2].charAt(i1)  // 先抄一個 't' 或 'a' 或 'b'
                    +inStr2[i2].charAt(i1)  // 再抄一個 't' 或 'a' 或 'b'
                    +')' //9506191512       // 加入 ')'
      // 至此 't' 改為 '(tt)'  ('a', 'b' 相同)
    } // 結束 if(inStr2[i2].charAt(i1)!=tab3.charAt(i2))
   }  // 結束 for(i1=0;i1<inStr1.length;i1++)

   oustr0 =inStr2[i2+1]; //9506191548 送返值

  }   // 結束 for(i2=0;i2<tab3len;i2++)

//9506200807 如果輸入沒有 't',
//輸入公式可能以 'x' 為自變數，而不用 't'
  if(oustr0.length==inStr2[i2-1].length)
  {       // 把 'x' 改為 '(tt)'
    oustr0=x2t(oustr0); //9506200816
  }

  return oustr0;
}



//9506151257 x2z (本卷為 x2t)
// 在計算公式之數值時如果把 'x' 直接改為 '-2'
// 則
// Math.exp(x*x)+Math.max(x,1/x)
// 變為
// Math.e-2p(-2*-2)+Math.ma-2(-2,1/-2)
// 破壞了公式原貌！
//
// 本函數 x2t() 把
// Math.exp(x*x)+Math.max(x,1/x)
// 改為
// Math.exp((tt)*(tt))+Math.Max((tt),1/(tt))
// 在執行評估指令時
// eval(this.fOfx.replace(/tt/g, i));
// 不會有問題，因為函數名稱不含 'tt'.
//9506151302 x2z (本卷為 x2t)
//9506200814 x2t
function x2t(in0)
{
  var u0;
  var out0="";
  for(u0=0;u0<in0.length;u0++)
  {
    if(in0.charAt(u0)!=='x')
      out0+=in0.charAt(u0);
    else
    {
      if(in0.charAt(u0-1)=='e'
       &&in0.charAt(u0+1)=='p'
        ) // 照抄 Math.exp()
      out0+=in0.charAt(u0);
      else
      if(in0.charAt(u0-1)=='a'
       &&in0.charAt(u0-2)=='m'
        ) // 照抄 Math.max()
      out0+=in0.charAt(u0);
      else// 更換 'x' 至 '(tt)'
      out0+="(tt)"; //9506151309
    } // 用 'tt' 不用 'z' 避免與將來可能
  }   // 使用的新函數名稱衝突。 9506151348
  return out0;
} //9506151311
  //9506200815 完成 x2t


// 9506211006
function deleteData(workID,probID)
{
  var s1='document.getElementById("'; //9506211423
  var w1, w2, w3, w4; //9506211427

  w3=probID; //9510181942

  var s2='"+'+w3+').value=';

//本函數 deleteData(workID)  使用幾種方法
//workID==0 用最直接的方法，使本卷尺寸快速增加。
  if(workID==0)
  {
document.getElementById("t1Len"+w3).value=
document.getElementById("t1Min"+w3).value=
document.getElementById("t1Max"+w3).value=
document.getElementById("t2Len"+w3).value=
document.getElementById("t2Min"+w3).value=
document.getElementById("t2Max"+w3).value=
document.getElementById("t3Len"+w3).value=
document.getElementById("t3Min"+w3).value=
document.getElementById("t3Max"+w3).value=
document.getElementById("t4Len"+w3).value=
document.getElementById("t4Min"+w3).value=
document.getElementById("t4Max"+w3).value=
document.getElementById("t5Len"+w3).value=
document.getElementById("t5Min"+w3).value=
document.getElementById("t5Max"+w3).value=
"";
  }
//workID==1 用環路指令將空白值 "" 填入輸入方格
  else
  if(workID==1) // 刪除箭頭資料
  {

//9506211959
for(w1=0;w1<11;w1++)
document.forms["arrowform"+w3][w1].value="";

  }
//workID==2 先建立數列 並且建立適當的字串，
//然後用環路指令將空白值 "" 填入輸入方格。
  else
  if(workID==2)
  {//刪除五條曲線（五縱列，二十五組數據）

//var lbarr= new Array(25);
//9510201953 由 25 改為 15
var lbarr= new Array(15);
lbarr=
[
//本卷擴展為定義五條任意公式 9510201952
"width1",
"width2",
"width3",
"width4",
"width5",
"color1",
"color2",
"color3",
"color4",
"color5",
"style1",
"style2",
"style3",
"style4",
"style5"
];
    for(w1=0;w1<lbarr.length;w1++)
    {
      w4=s1+lbarr[w1]+s2+'""';
      eval(w4);
    } //9506211440
  }
  else
  if(workID==3)
  {
//9506211951
for(w1=0;w1<10;w1++)
document.forms["labelform"+w3][w1].value="";

document.forms["labelform"+w3][10].value="none"; //9510221500
  }
  else
  if(workID==61) // 9510221930
  { // 刪除第一條公式
document.getElementById("func1x"+probID).value=
document.getElementById("func1y"+probID).value="";
  }
  else
  if(workID==62)
  { // 刪除第二條公式
document.getElementById("func2x"+probID).value=
document.getElementById("func2y"+probID).value="";
  }
  else
  if(workID==63)
  { // 刪除第三條公式
document.getElementById("func3x"+probID).value=
document.getElementById("func3y"+probID).value="";
  }
  else
  if(workID==64)
  { // 刪除第四條公式
document.getElementById("func4x"+probID).value=
document.getElementById("func4y"+probID).value="";
  }
  else
  if(workID==65)
  { // 刪除第五條公式
document.getElementById("func5x"+probID).value=
document.getElementById("func5y"+probID).value="";
  }
  else
  if(workID==6000)
  { // 刪除五條公式
document.getElementById("func1x"+probID).value=
document.getElementById("func1y"+probID).value=
document.getElementById("func2x"+probID).value=
document.getElementById("func2y"+probID).value=
document.getElementById("func3x"+probID).value=
document.getElementById("func3y"+probID).value=
document.getElementById("func4x"+probID).value=
document.getElementById("func4y"+probID).value=
document.getElementById("func5x"+probID).value=
document.getElementById("func5y"+probID).value="";
  }

  else
  if(workID==4)
  {
//將來使用
  }
}




//9507142127
function delAll(probID)
{
  document.getElementById("title0"+probID).value="";
  deleteData(0,probID);
  deleteData(1,probID);
  deleteData(2,probID);
  deleteData(3,probID);
  deleteData(6000,probID);
  document.getElementById("CurveDoc0"+probID).value="";
}
//9507142130


// 「動態改變」設計，一套輸入表格指令
// openTable(drawID,table01)
// 可以為無限多張圖片服務。9510231220
// drawID 為圖片號碼

function openTable(drawID,table01) // 9510221840
{
// 9510221944 增加 'table01'
// table01==0 關閉,  table01==1 開啟
var openClose="block";
if(table01==0) openClose="none"; //9510221946

var htmlStr= //9510221823
'<TABLE cellSpacing=1 cellPadding=0 width="100%" align=center border=0><TBODY><br><TR id="showlxr'+drawID+'" style="DISPLAY:'+openClose+'" bgColor=#ccfcfc><TD colSpan=7><TABLE width="100%" align=left border=0><TBODY><TR><TD align=right bgColor=#FFFF00 border=0 onclick=open0lxr('+drawID+')>'

+'請<br>點<br>擊<br>關<br>閉</TD><TD width="100%"><table>  <tr>  <td height="0%">'

+'<input onclick="javascript:DrawGraf2('+drawID+')" type="button" value="　畫圖　" />　<INPUT name=Del0Graph type="button" value="刪圖" onclick=javascript:wipeCurve('+drawID+');>　<INPUT name=DelAllBox type="button" value="刪除全部方格" onclick=javascript:delAll('+drawID+')>　<INPUT name=DelTitle type="button" value="刪除標題" onclick=javascript:document.getElementById("title0'+drawID+'").value="";>　<input onclick="javascript:SelectEqn('+drawID+')" type="button" value="取用原題" /><br>'

+'標題﹕ <input type="text" id="title0'+drawID+'" value="" size=55 /><br>函數一 x(t) <input type="text" id="func1x'+drawID+'" value="" size=55 /><br>函數一 y(t) <input type="text" id="func1y'+drawID+'" value="" size=55 /><br>函數二 x(t) <input type="text" id="func2x'+drawID+'" value="" size=55 /><br>函數二 y(t) <input type="text" id="func2y'+drawID+'" value="" size=55 /><br>函數三 x(t) <input type="text" id="func3x'+drawID+'" value="" size=55 /><br>函數三 y(t) <input type="text" id="func3y'+drawID
+'" value="" size=55 /><br>函數四 x(t) <input type="text" id="func4x'+drawID+'" value="" size=55 /><br>函數四 y(t) <input type="text" id="func4y'+drawID+'" value="" size=55 /><br>函數五 x(t) <input type="text" id="func5x'+drawID+'" value="" size=55 /><br>函數五 y(t) <input type="text" id="func5y'+drawID+'" value="" size=55 /><br>每條曲線至多一千點。刪除函數<INPUT name=DelEqn1 type="button" value="一" onclick=javascript:deleteData(61,'+drawID+');><INPUT name=DelEqn2 type="button" value="二" onclick=javascript:deleteData(62,'+drawID+');><INPUT name=DelEqn3 type="button" value="三" onclick=javascript:deleteData(63,'+drawID+');><INPUT name=DelEqn4 type="button" value="四" onclick=javascript:deleteData(64,'+drawID+');><INPUT name=DelEqn5 type="button" value="五" onclick=javascript:deleteData(65,'+drawID+');><INPUT name=DelEqnAll type="button" value="全刪" onclick=javascript:deleteData(6000,'+drawID
+');><br>下面五條曲線自變數步長及起值、終值。<INPUT name=Del0Graph type="button" value="刪除" onclick=javascript:deleteData(0,'+drawID+');> &nbsp;<input onclick="javascript:DrawGraf2('+drawID+')" type="button" value="畫圖" /><br>曲線一步長 <input type="text" id="t1Len'+drawID+'" value="" size="6" />起值 <input type="text" id="t1Min'+drawID+'" value="" size="6" />終值 <input type="text" id="t1Max'+drawID+'" value="" size="6" /><br>曲線二步長 <input type="text" id="t2Len'+drawID+'" value="" size="6" />起值 <input type="text" id="t2Min'+drawID+'" value="" size="6" />終值 <input type="text" id="t2Max'+drawID+'" value="" size="6" /><br>曲線三步長 <input type="text" id="t3Len'+drawID+'" value="" size="6" />起值 <input type="text" id="t3Min'+drawID+'" value="" size="6" />終值 <input type="text" id="t3Max'+drawID+'" value="" size="6" /><br>曲線四步長 <input type="text" id="t4Len'+drawID+'" value="" size="6" />起值 <input type="text" id="t4Min'+drawID
+'" value="" size="6" />終值 <input type="text" id="t4Max'+drawID+'" value="" size="6" /><br>曲線五步長 <input type="text" id="t5Len'+drawID+'" value="" size="6" />起值 <input type="text" id="t5Min'+drawID+'" value="" size="6" />終值 <input type="text" id="t5Max'+drawID+'" value="" size="6" /><br>下面每個縱列對應一條曲線<INPUT name=Del1Arrow type="button" value="刪除五縱列" onclick=javascript:deleteData(2,'+drawID+')><br>曲線寬度 &nbsp;  &nbsp;  <input type="text" id="width1'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="width2'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="width3'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="width4'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="width5'+drawID+'" value="" size="3" /><br>曲線顏色 &nbsp;  &nbsp;  <input type="text" id="color1'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="color2'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="color3'+drawID
+'" value="" size="3" /> &nbsp; <input type="text" id="color4'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="color5'+drawID+'" value="" size="3" /><br>'
+'實線虛線 &nbsp;  &nbsp; <input type="text" id="style1'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="style2'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="style3'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="style4'+drawID+'" value="" size="3" /> &nbsp; <input type="text" id="style5'+drawID+'" value="" size="3" /><br><form id="arrowform'+drawID+'" action=""><table>下面方格可以定義一個箭頭（多個箭頭需要直接編程）<tr><td> x 坐標</td><td><input type="text" size="4" id="x" value="" /> &nbsp; </td><td> y 坐標</td><td><input type="text" size="4" id="y" value="" /> &nbsp; </td><td>箭頭轉角</td><td><input type="text" size="4" id="rotation" value="" /> &nbsp; </td></tr><tr><td>箭頭長度</td>'
+'<td><input type="text" size="4" id="length" value="" /> &nbsp; </td><td>箭頭尺寸</td><td><input type="text" size="4" id="size" value="" /> &nbsp; </td><td>箭頭顏色</td><td><input type="text" size="4" id="color" value="" /></td></tr><tr><td>旁註文字</td><td><input type="text" size="4" id="label" value="" /> &nbsp; </td><td>文字顏色</td><td><input type="text" size="4" id="labelcolor" value="" /> &nbsp; </td><td>文字尺寸</td><td><input type="text" size="4" id="labelsize" value="" /></td></tr><tr><td>箭柄寬度</td><td><input type="text" size="4" id="lineweight" value="" /> &nbsp; </td><td>箭柄實虛</td><td><input type="text" size="4" id="dashstyle" value="" /></td><td><INPUT name=Del1Arrow type="button" value="刪除箭頭" onclick=javascript:deleteData(1,'+drawID+')></td></tr></table></form>'
+'<form id="labelform'+drawID+'" action=""><table>下面方格可以定義一個標簽（多個標簽需要直接編程）<tr><td><!--div id="graphdiv3"></div--></td><td>  <table><tr><td> x 坐標</td><td><input type="text" id="x" size="4" value="" /></td><td> y 坐標</td><td><input type="text" id="y" size="4" value="" /></td></tr><tr><td>標簽轉角</td><td><input type="text" id="rotation" size="4" value="" /></td><td>標簽長度</td><td><input type="text" id="length" size="4" value="" /></td></tr><tr><td>標簽顏色</td><td><input type="text" id="labelcolor" size="4" value="" /></td><td>標簽尺寸</td><td><input type="text" id="labelsize" size="4" value="" /></td></tr>'
+'<tr><td>標簽文字</td><td><input type="text" id="label" size="4" value="" /></td><td>標點尺寸</td><td><input type="text" id="pointsize" size="4" value="" /></td></tr><tr><td>標點填色</td><td><input type="text" id="pointfillcolor" size="4" value="" /></td><td>標點匡色</td><td><input type="text" id="pointstrokecolor" size="4" value="" /></td></tr><tr><td>標點式樣</td><td><select id="VMLpointshapetype" ><option value="diamond">鑽石形</option><option value="square">正方形</option><option value="triangle">三角形</option><option value="circle">圓形○</option><option value="x">叉號Ｘ</option><option value="none" selected="selected">都不要</option></select></td><td><INPUT name=Del1Arrow type="button" value="刪除標簽" onclick=javascript:deleteData(3,'+drawID+')></td><td>  <input onclick="javascript:DrawGraf2('+drawID+')" type="button" value="畫圖" /></td></tr></table></td></table></form>'
+'<form id="Docform'+drawID+'" name="Docform1">使用者建立曲線之說明&nbsp;<INPUT onclick=\'javascript:window.clipboardData.setData("Text",document.getElementById("CurveDoc0'+drawID+'").value)\' type=button value="複製0"> &nbsp; <INPUT onclick=\'document.getElementById("CurveDoc0'+drawID+'").value="";\' type=button value="刪除0"><br><TEXTAREA id=CurveDoc0'+drawID+' name=CurveBox0 rows=8  cols=60 ></TEXTAREA></form>'
+'下面定義畫板尺寸及 X,Y 軸範圍。<br>畫板寬度 <input type="text" id="boardW'+drawID+'" value="300" size="3" />&nbsp;畫板高度 <input type="text" id="boardH'+drawID+'" value="300" size="3" />&nbsp;單位是「點」。<br><font color=red>請調整畫板尺寸或 X,Y 軸範圍以達到 X:Y=1:1 的情況。</font><br>最小X  <input type="text" id="minX'+drawID+'" value="-10" size="3" />&nbsp;最大X  <input type="text" id="maxX'+drawID+'" value="+10" size="3" />&nbsp;最小Y  <input type="text" id="minY'+drawID+'" value="-10" size="3" />&nbsp;最大Y  <input type="text" id="maxY'+drawID
+'" value="+10" size="3" /><br><form name="aa'+drawID+'"><table><tr><td width=248>方格一<input type="radio" name="radio1" checked />0<input type="radio" name="radio1" />1<INPUT onclick=\'javascript:window.clipboardData.setData("Text",document.getElementById("box11'+drawID+'").value)\' type=button value="複製1"> &nbsp; <INPUT onclick=\'document.getElementById("box11'+drawID+'").value="";\' type=button value="刪除1"><TEXTAREA id=box11'+drawID+' name=aaBox11 rows=8  cols=28 >曲線每點 x,y 坐標存於方格一</TEXTAREA></td><td width=248>方格二<input type="radio" name="radio2" checked />0<input type="radio" name="radio2" />1<INPUT onclick=\'javascript:window.clipboardData.setData("Text",document.getElementById("box12'+drawID+'").value)\' type=button value="複製2"> &nbsp; <INPUT onclick=\'document.getElementById("box12'+drawID+'").value="";\' type=button value="刪除2"><TEXTAREA id=box12'+drawID+' name=aaBox12 rows=8  cols=28 >曲線每點 t,x,y 坐標存於方格二\nt 是參數（自變數）</TEXTAREA>'
+'</td>'

+'</tr><tr>'

//9511120720
+'本表格讓您修改作者原題，可以小幅修改一個係數值，<br>'
+'也可以大幅更改為全新公式，請同時定義自變數 t<br>'
+'之起始值、終止值及步長值，同時請定義畫板範圍<br>'
+'最小X  最大X  最小Y  最大Y<font color=red><br>'
+'然後點擊表格內的「畫圖」鈕，修改有效。<br>'
+'如果點擊表格外的「畫圖 '+drawID+'」鈕，修改無效。</font><br>'
+'如果對修改不滿意，請點擊「取用原題」鈕。9511120730<br>'

+'如果您要保留曲線圖片為圖畫卷，目前自由人唯一知道的<br>'
+'方法是<font color=red>按鍵盤的控制鈕，同時按「複製全屏」鈕</font>，打開圖畫<br>'
+'軟體，把全屏圖象貼入圖畫軟體，並且存卷。 9511122013<br>'

+'</tr><tr>方格三<input type="radio" name="radio3" checked />0 <input type="radio" name="radio3" />1 &nbsp;<input onclick="javascript:DrawGraf2('+drawID+')" type="button" value="畫圖" />&nbsp;<INPUT name=FuncButton type="button" value="說明" onclick=javascript:open0lxr(102)> &nbsp;<INPUT onclick=\'javascript:window.clipboardData.setData("Text",document.getElementById("box13'+drawID
+'").value)\' type=button value="複製3"> &nbsp; <INPUT onclick=\'document.getElementById("box13'+drawID+'").value="";\' type=button value="刪除3"><br><TEXTAREA id=box13'+drawID+' name=aaBox13 rows=8  cols=60 >其他資料存於方格三。內定方格一、二、三都不存資料，\n以增加計算速度，如果您要某項資料，請點擊其方格旁\n邊的 1 鈕。　　0 鈕代表不要輸出，1 鈕代表要輸出。\n如果方格一的 1 鈕經常開啟，請在源碼找關鍵字串\n「name="radio1"」，把\n<input type="radio" name="radio1"\n checked />0\n<input type="radio" name="radio1"\n />1\n修改為\n<input type="radio" name="radio1"\n />0\n<input type="radio" name="radio1"\n checked />1\n重點是移動「 checked」\n方格二找 "radio2"\n方格三找 "radio3"\n9510221011</TEXTAREA></tr></table></FORM></td></tr><tr><td></td></tr></table></TD></TR></TBODY></TABLE></TBODY></TABLE>'


document.getElementById("putTable"+drawID).innerHTML=htmlStr;
}



// 9506130914 add  open0lxr(xx)
function open0lxr(xx)
{
 var i0;
 var totalWin=1;
 if(xx==100)
 {
  for(i0=101;i0<totalWin+101;i0++)
  closelxr(i0);
 }
 else
 {
  ss=eval("showlxr"+xx);

  if(ss.style.display=="block")
  {ss.style.display="none"
  }
  else
  {ss.style.display="block"
  }
// for(i0=101;i0<totalWin+101;i0++)
// if(i0!=xx) closelxr(i0);
 }
}
function closelxr(yy)
{ss=eval("showlxr"+yy);
  if(ss.style.display=="block")
  {ss.style.display="none"
  }

//9510230255 增加下面一行，節省系統資源
 document.getElementById("putTable"+yy).innerHTML="";
//9510230331 仍然需要上行指令，因為點擊黃條關閉時
//也要節省系統資源。
}


/**
97,12,08,17,37 開啟 jsgraph1.js
看有哪些函數定義
function XYLine() {
function Arrow() {
function Label() {
function XYGraph() {
function stepf(t0,bgn0)
function loggamma(x)
function gamma(x) 
function factorial(n)
function wipeCurve(d3) // 9506191230
function DrawGraf2(argd2) // DrawGraf2() 刪除統計數據指令 9510182128
function closeStr(klozID) // 9510230247
function toSyntax(inStr1) //9506191250
function x2t(in0) //9506200814 x2t
function deleteData(workID,probID) // 9506211006
function delAll(probID) //9507142127
9712081744 增加下面函數
function openTable(drawID,table01) // 9510221840
function open0lxr(xx)
function closelxr(yy)


下面是取卷記錄
95,06,12,18,21,28
http://www.structura.info/XYGraph/XYGraph.zip
C:\$fm\js\xygraph\XYGraph.zip
=====
95,10,17,20,00,42
http://www.structura.info/XYGraph/XYGraph.js
95,10,17,20,14,17
http://www.structura.info/XYGraph/Examples.htm
/**/

//-->
