divgraph.js Functions

This document describes the divgraph.js functions.
See info.htm for user parameter information.

The divgraph.js functions fall into four basic categories:


Primary Interface Functions (click to go to a description)
GRadddata(sdata,Data,Labels,Info)
GRaddfunction(f_of_x,Info)
GRaddpoint(x,y,label,c,xytype,ngraph)
GRaddtext(x,y,stext,c,xytype,ngraph)
GRclosegraphdocument(ngraph)
GRclosegraphwindow(ngraph,delay)
GRdrawgraph(f_of_x,Data,Labels,Info,doc)
GRinit()
GRopengraphframe(frame)
GRopengraphwindow(w,h,t,l)
GRreplot(ngraph,xoff,yoff,doc2,w,h,t,l)
GRsetgraphwindow(w)
Secondary Interface Functions (click to go to a description)
GRalert(a,b,c,d,...)
GRdebugwrite(a,b,c,d,...)
GRdiv(i,doc)
GRdivinfo(i,doc)
GRdivmove(i,x,y,xytype,ngraph)
GRdivshow(i,TF,ngraph)
GRdivwrite(i,s,x,y,xytype,ngraph)
GRfixpower(s,format)
GRgetleastsquares(Data,L)
GRgetoffset(s)
GRgraph(x,y)
GRgetnewwindow(s,opt)
GRinitdivs()
GRmouseevent(e,x,y,scmd)
GRprompt(q,a)
GRrect(x1,y1,y2,y2,c,xytype,ngraph)
GRresize()
GRroundoff(x,ndec)
GRsetgraph(ngraph,tolist)
GRshow(obj,objName,signore,sonly)
GRxof(x)
GRyof(y)
Internal divgraph.js Functions (click to view)

GRcleargraph(setdefaults)
GRcopy(Afrom,Ato,list...)
GRdatacolor(D)
GRdotics(tic0,tmin,tmax,minort,majort,stylex,styley,plotx,ploty,
        force,isy,doticnums,numx,numy,ndig,nignore)
GRfindparen(s,ipt0,idirect)
GRgetdata(sdata,Data,Labels)
GRgetinfo(A,skey,def)
GRgraphpoint(i,scolor,slabel)
GRinrange(x,a,b)
GRlabelof(i,s,c,a,w)
GRLSQ(L,x,y)
GRLSR(L,x,y)
GRndig(n)
GRnewdata(A,x,P)
GRnewdiv(P)
GRnewlabel(s,x,y,c)
GRnewpt(i,x,y,Data,Labels,width,height,c)
GRnewstyle(left,top,width,height,color,label)
GRptof(i,w,h,c,a)
GRsort(a,b)
GRspline(Data,i)
GR10(x)
User Math Functions (click for a discussion)
function cos(x){return Math.cos(x)}
function ln(x){return Math.log(x)}
function log(x){return Math.LOG10E*Math.log(x)}
function sin(x){return Math.sin(x)}
function sqr(x){return Math.pow(x,0.5)}
function sqrt(x){return Math.pow(x,0.5)}
function tan(x){return Math.sin(x)/Math.cos(x)}

Primary Interface Functions

These ten functions comprise the main programming interface. For detailed examples of their use, see examples.htm.


 view function

GRadddata(sdata,Data,Labels,Info)

adds x,y data to a previous graph initiated with GRdrawgraph()
NOTE: CANNOT BE RUN AFTER DOCUMENT IS CLOSED
parameterdefaultdescription
sdataPROMPTx,y data in pairs, one pair per line, or a continuous stream of x,y,x,y... data. If Data.length=0, then the user is prompted.
Data[ ]new Array()x,y data in the form [x,y,color,label], where color.gif is a valid GIF file name, and label is a label for the point. Color and label are optional. If no verical bar is present in the label, the label is an alt label, which is only seen when the user moves the mouse over the point. If a vertical bar ("|") is present in the label, then text to the left of this bar becomes the alt label, while text after the bar becomes the displayed label.
Labels[ ]new Array()labels for x,y data. If Labels.length>0, then any labels in Data[ ] are ignored.
Info[ ]new Array()information array -- see info.htm
actions:This function allows entry of a second set of data BEFORE the graphing document is closed. After that, GRaddpoint() must be used instead.
return:plot number, the index into GR.List[ ] for this plot. In addition, if sdata is used, then Data[ ] is filled with x,y pairs.

 view function

GRaddfunction(f_of_x,Info)

adds a function of x to a previous graph initiated with GRdrawgraph()
NOTE: CANNOT BE RUN AFTER DOCUMENT IS CLOSED
parameterdefaultdescription
f_of_xPROMPTfunction of x (a string)
Info[ ]new Array()information array -- see info.htm
actions:This function allows entry of a second function of x BEFORE the graphing document is closed.
return:plot number, the index into GR.List[ ] for this plot.

 view function

GRaddpoint(x,y,label,c,xytype,ngraph)

Allows the addition of a point at the specified x,y locations.
NN4: CANNOT BE RUN BEFORE DOCUMENT IS CLOSED
parameterdefaultdescription
xPROMPTx-coordinate
yPROMPTy-coordinate
labelPROMPTtext to associate with this point. If no verical bar is present in the label, the label is an alt label, which is only seen when the user moves the mouse over the point. If a vertical bar ("|") is present in the label, then text to the left of this bar becomes the alt label, while text after the bar becomes the displayed label.
cGR.colorlastc.gif must be a valid GIF file.
xytypeGRUSERGRUSER indicates coordinates are user-based
GRDOC indicates coordinates are document-based, with 0,0 at the top left corner of the plotting surface (as specified by Info.graphleft and Info.graphtop, not the window) with y running DOWN from the top.
GRANCHOR indicates coordinates based on a graph anchor element such as an image or "a" tag (indicated by setting Info.anchor to the name of the element).
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
return:
actions:only the total number of additional points, as specified by Info.maxaddpoints in a previous call to GRdrawgraph() are allowed. If this number is exceeded, then the request is ignored.
return:div number associated with this point, or 0 if the maximum number of points has been exceeded. This number can be used later in GRdivwrite() or GRdivmove().

 view function

GRaddtext(x,y,stext,c,xytype,ngraph)

Allows the addition of text at the specified x,y locations.
NN4: CANNOT BE RUN BEFORE DOCUMENT IS CLOSED
parameterdefaultdescription
xPROMPTx-coordinate
yPROMPTy-coordinate
stextPROMPTtext to display
cGR.colorlastJavaScipt color to use. This parameter may include additional information to be included in the font tag (when no alignment is specified) or in the td tag (when alignment is specified, for example, with red align=center. The color must come first, and the width of the tag, if aligned, must not exceed 200 pixels.
xytypeGRUSERGRUSER indicates coordinates are user-based
GRDOC indicates coordinates are document-based, with 0,0 at the top left corner of the plotting surface (as specified by Info.graphleft and Info.graphtop, not the window) with y running DOWN from the top.
GRANCHOR indicates coordinates based on a graph anchor element such as an image or "a" tag (indicated by setting Info.anchor to
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
actions:only the total number of additional points, as specified by Info.maxaddpoints in a previous call to GRdrawgraph() are allowed. If this number is exceeded, then the request is ignored.
return:div number associated with this point, or 0 if the maximum number of points has been exceeded. This number can be used later in GRdivwrite() or GRdivmove().

 view function

GRclosegraphdocument(doc)

Closes the document at the end of graphing. This should be standard procedure.
parameterdefaultdescription
docGR.docthe document to close
actions:closes the specified document.
return:closed document

 view function

GRclosegraphwindow(ngraph,delay)

Closes one or more graph windows. (Graphs in the main document are not affected.)
parameterdefaultdescription
ngraph0the number of the graph for which the window is to be closed. Zero indicates all open graph windows.
delay20The delay for a setTimeout() in milliseconds.
actions:closes the specified graph window(s)
return:null

 view function

GRdrawgraph(f_of_x,Data,Labels,Info,doc)

The primary interface for graphing after execution of GRopengraphwindow() , GRopengraphframe(), or GRsetgraphwindow()
parameterdefaultdescription
f_of_x""f(x) or x,y paired data, either "x,y,x,y,x,y..." or one x,y pair per line.
Data[ ]new Array()x,y data in the form [x,y,color,label], where color.gif is a valid GIF file name, and label is text to include with the point. If no verical bar is present in the label, the label is an alt label, which is only seen when the user moves the mouse over the point. If a vertical bar ("|") is present in the label, then text to the left of this bar becomes the alt label, while text after the bar becomes the displayed label. Color and label are optional.
Labels[ ]new Array()labels for x,y data. If Labels.length>0, then any labels in Data[ ] are ignored.
Info[ ]new Array()information array -- see info.htm
docGR.docgraphing document
actions: Several default actions are available.
  • If no parameters are given, the user is prompted both for the f(x) or x,y data and for the range of x when f(x) is given.
  • If only the first parameter is given, and it is found to be a function of x, then the user is prompted for the range of x.
  • If Data.length>0, then f_of_x is ignored.
  • If Labels.length>0, then Data labels are ignored.
return:plot number, the index into GR.List[ ] for this plot. In addition, if f_of_x is used, then Data[ ] is filled with x,y pairs.

 view function

GRinit()

initializes the divgraph.js package
actions:resets all arrays and variables to their default values. Reuses all variables and structures. Recommended to be called whenever previous graphs are not being saved or displayed.
return:null

 view function

GRopengraphframe(frame)

Open a new graph document in the specified frame
parameterdefaultdescription
frameREQUIREDframe for which the document is to be opened
actions:GR.win is set the new frame, and GR.doc is set to the frame document, which is opened. This initiates an overwriting of any document currently that frame.
return:frame.document

 view function

GRopengraphwindow(w,h,t,l)

Opens a new window and its associated document for a new graph.
parameterdefaultdescription
w300window width
h300window height
t50window top
l50window left
actions: Creates a new window with options based on the GR.winoptions template. Sets GR.win and GR.doc.
return:new graph window

 view function

GRreplot(ngraph,xoff,yoff,doc2,w,h,t,l)

replotting of data for printing with Netscape Navigator or for redisplaying the data in a new window
parameterdefaultdescription
ngraphGR.thisgraphplot number (index into GR.List[ ], returned by GRdrawgraph()
xoff0x-offset from original
yoff0y-offset from original
doc2newgraph document
wmost recentwindow width
hmost recentwindow height
tmost recentwindow top
lmost recentwindow left
actions:if doc2 is not specified, the new graph document is closed, and the old window is closed. GR.win and GR.doc point to the new graph.
return:new graph window if creation was necessary, or null if it was not.

 view function

GRsetgraphwindow(w)

Sets the window and its currently open document to be the current graphing window and document. Assumes an open document already.
parameterdefaultdescription
wwindowwindow or frame to be used (defaults to main window)
actions:GR.win is set the specified window, and GR.doc is set to the window's document. However, no document is opened. This allows writing into the main document or into a frame that has an already-opened document currently being written to. Use this function instead of GRopengraphwindow() or GRopengraphframe() to open a graph in a document that is currently being written.
return:w.document

 

Math Interface Functions

These seven functions allow the user to specify common-use math functions instead of JavaScript math. They are the only functions in the package that do not begin with "GR" and probably are only of use if the user is expected to specify the math function to be plotted. They are not called by any GR functions and may be overwritten, complemented, or discarded.


function sin(x){return Math.sin(x)}
function cos(x){return Math.cos(x)}
function tan(x){return Math.sin(x)/Math.cos(x)}
function log(x){return Math.LOG10E*Math.log(x)}
function ln(x){return Math.log(x)}
function sqrt(x){return Math.pow(x,0.5)}
function sqr(x){return Math.pow(x,0.5)}

Secondary Interface Functions

These 13 functions might be of general use, but are primarily used from within the divgraph.js package.


 view function

GRalert(a,b,c,d,...)

shows an alert in the graphing document
parameterdefaultdescription
anyREQUIREDany number of parameters may be displayed. Each separate parameter is displayed on a separate line of the message box.
actions:This also serves to bring a graph window to the foreground when necessary. Standard alerts will bring the calling page to the foreground, probably hiding the graph.
return:null

 view function

GRdebugwrite(a,b,c,d,...)

shows a message in a new window
parameterdefaultdescription
anyREQUIREDany number of parameters may be displayed. Each separate parameter is displayed on a separate line of the new window.
actions:opens a new window displaying the specified string.
return:null

 view function

GRdiv(i,doc)

parameterdefaultdescription
iREQUIREDrefering to div "G"+i
docREQUIREDany document with divs of this form
actions:this is a browser-blind call to get a div handle.
return:(GR.isnn4?doc.layers["G"+i]:eval("doc.all.G"+i))

 view function

GRdivinfo(i,doc)

this function allows a determination of the contents of div "#G"+i in document doc
parameterdefaultdescription
iREQUIREDrefering to div "G"+i
docREQUIREDgraphing document
actions:this is a browser-blind call to get a div HTML contents. Since NN4 does not proved the innerHTML property, this is provided by an array GR.innerHTML, which is set up as divs are written.
return:D, an array with elements D.innerHTML, D.offsetLeft, and D.offsetTop

 view function

GRdivmove(i,x,y,xytype,ngraph)

move the specided div "G"+i to the specified location
parameterdefaultdescription
iREQUIREDrefering to div "G"+i
xREQUIREDx-coordinate
yREQUIREDy-coordinate
xytypeGRUSERGRUSER indicates coordinates are user-based
GRDOC indicates coordinates are document-based, with 0,0 at the top left corner of the plotting surface (as specified by Info.graphleft and Info.graphtop, not the window) with y running DOWN from the top.
GRANCHOR indicates coordinates based on a graph anchor element such as an image or "a" tag (indicated by setting Info.anchor to
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
actions:repositions the div; automatically shows it if hidden
return:null

 view function

GRdivshow(i,TF,ngraph)

shows or hides the specified div
parameterdefaultdescription
iREQUIREDrefering to div "G"+i
TFtruewhether to show the div; true or false
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
actions:shows/hides the div;
return:null

 view function

GRdivwrite(i,s,x,y,xytype,ngraph)

writes HTML to a specified div of id "G"+i, moving it, if that too is specified
parameterdefaultdescription
iREQUIREDrefering to div "G"+i
sREQUIREDHTML to write
xOPTIONALx-coordinate
yOPTIONALy-coordinate
xytypeGRNONEGRUSER indicates coordinates are user-based
GRDOC indicates coordinates are document-based, with 0,0 at the top left corner of the plotting surface (as specified by Info.graphleft and Info.graphtop, not the window) with y running DOWN from the top.
GRANCHOR indicates coordinates based on a graph anchor element such as an image or "a" tag (indicated by setting Info.anchor to
GRNONE or no parameter present indicates write only, without a move.
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
actions:write to and optionally repositions the div; automatically shows the div if hidden
return:null

 view function

GRfixpower(s,format)

convert standard user form a^b to Math.pow(a,b)
parameterdefaultdescription
sREQUIREDthe string to search for a^b in
format"Math.pow(%1,%2)"the format
actions:All occurances of a^b are replaced in a format, where a is %1 and b is %2. Preceding and subsequent string information is recognized and left unchanged. Parentheses are recognized. For example, 3*(5+3)^7+1 becomes 3*Math.pow((5+3),7)+1.
return:format replaced as specified

 view function

GRgetleastsquares(Data,L)

calculates a least squares fit on x,y pairs in Data
parameterdefaultdescription
Data[ ]REQUIREDdata in the form of x,y pairs
L[ ]REQUIREDreturn array
actions:calculates least squares fit
return:L.m (slope), L.b (intercept), L.r2 (r2)

 view function

GRgetoffset(s)

get the absolute x,y position of a page element.
parameterdefaultdescription
sREQUIREDthe name of the element, as indicated in a "name=" parameter of an HTML tag.
actions:The x,y coordinates of the element are determined. This function is used for finding a specified anchor's page position initially and upon page resizing.
return:an array, where array.left=x and array.top=y

 view function

GRgraph(x,y)

find the graph associated with a specific absolute document x,y position.
parameterdefaultdescription
x,yREQUIREDdocument-based x and y coordinates.
actions:Generally, this function is used to associate a user's mouse clicks with a specific graph.
return:the graph number of the graph whose plotting surface contains these x,y coordinates.

 view function

GRmouseevent(e,x,y,scmd)

responds to user clicks and moves of the mouse
parameterdefaultdescription
eeventevent structure from Netscape Navigator only
x,yevent x and yx,y coordinates (only for testing)
scmdnullthe function name to which to pass structure information (only for testing)
actions:responds to mouse events
return:passes on the event structure (from the browser) along with a structure indicating the button that was pressed (in the case of mousedown and mouseup) as well as the graph number for the graph that was clicked on and the x,y coordinates in document, anchor, and user systems. See examplec.htm for more information.

 view function

GRgetnewwindow(s,opt)

parameterdefaultdescription
sREQUIREDURL of page to open, or "" for blank window
optREQUIREDoption string indicating size, menu, scrolling, and other options
actions:A new window with a unique name and its associated document are created
return:handle to new window

 view function

GRinitdivs()

actions:checks for browser compatibility; sets GR.isnn4 and GR.isie4
return:true if successful, false if unsuccessful

 view function

GRprompt(q,a)

generates a user prompt in the graph window
parameterdefaultdescription
sREQUIREDprompt question string
aREQUIREDprompt default answer string
actions:brings the graph window forward and produces a prompt in it. In contrast, a simple prompt() will generally hide a visible graph window behind the main page.
return:prompt result string or null (canceled)

 view function

GRrect(x1,y1,x2,y2,c,xytype,ngraph) ,y,label,c,xytype,ngraph)

create a string representing a rectangle
parameterdefaultdescription
x1,y1REQUIREDupper left coordinates
x2,y2REQUIREDlower right coordinates
cGR.colorlastc.gif must be a valid GIF file.
xytypeGRUSERGRUSER indicates coordinates are user-based
GRDOC indicates coordinates are document-based, with 0,0 at the top left corner of the plotting surface (as specified by Info.graphleft and Info.graphtop, not the window) with y running DOWN from the top.
GRANCHOR indicates coordinates based on a graph anchor element such as an image or "a" tag (indicated by setting Info.anchor to the name of the element).
ngraphGR.thisgraphthe graph number associated with this point, starting with 1
return:
actions: creates a string corresponding to a box with upper left corner x1,y1 and lower right corner x2,y2.
return:<img>HTML tag for use in GRdivwrite()

 view function

GRresize()

moves the graph to the correct anchored position if the web page is resized
actions:This function is called when the page is resized if an anchor is indicated for a graph. For proper function under Internet Explorer, the <body> tag must contain "onresize=GRresize()" or else a reference to a function that itself calls GRresize().
return:1

 view function

GRroundoff(x,ndec)

rounds off a number to a specified number of digits
parameterdefaultdescription
xREQUIREDnumber to be rounded
ndecdependsnumber of digits to round:
ndec<0 for floating (scientific notation)
ndec>0 for fixed notation
absent: do "reasonable" roundoff
actions:If ndec is omitted, then it is determined by:
 |x|>=9999 -2
 |x|<0.01  -2
 |x|>=10    0
 |x|>=1     1
 |x|>=0.1   2
 |x|>=0.01  3
return:rounded number as a string

 view function

GRsetgraph(ngraph,tolist)

set current graph to be ngraph
parameterdefaultdescription
ngraphREQUIREDthe number of the graph to make the default graph
tolistfalsetrue:transfers save current graph information to this graph number (not recommended);false:load this graph information (from GR.List[ngraph]) into the current information (in GR)
actions: this function needs to be called only if you have multiple graphs and are using GRxof() or GRyof() and no other calls have been made, such as to GRdivmove() or GRdivwrite(), to set the graph. Critical elements in GR.List are transferred to GR so that proper positioning can occur. After calling GRsetgraph(), the "ngraph" parameter may be left off in all other functions requiring it.
return:null

 view function

GRshow(obj,objName,signore,sonly)

displays all elements of an object
parameterdefaultdescription
objREQUIREDobject to be enumerated
objName"obj"name to supply for the object
signorenullignore all elements containing this text in their name
sonlynullinclude only elements containing this in their name
actions:enumerates the object for debugging purposes. Use with GRalert() or GRdebugwrite(). For example, GRalert(GRshow(document.anchors,"document.anchors")) or GRdebugwrite(GRshow(document.anchors,"document.anchors"))
return:string of all of the object's elements and their definitions

 view function

GRxof(x)

converts user x-coordinate to document coordinates
parameterdefaultdescription
xREQUIREDuser x-coordinate
return:Math.round(GR.left+(x-GR.xmin)*GR.xfactor)

 view function

GRyof(y)

converts user y-coordinate to document coordinates
parameterdefaultdescription
yREQUIREDuser y-coordinate
return:Math.round(GR.top+GR.height-(y-GR.ymin)*GR.yfactor)

Disclaimer