divgraph.js Functions |
The divgraph.js functions fall into four basic categories:
Primary Interface Functions | |||
These ten functions comprise the main programming interface. For detailed examples of their use, see examples.htm. | |||
view function
adds x,y data to a previous graph initiated with | |||
parameter | default | description | |
---|---|---|---|
sdata | PROMPT | x,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
adds a function of x to a previous graph initiated with | |||
parameter | default | description | |
f_of_x | PROMPT | function 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
Allows the addition of a point at the specified x,y locations. | |||
parameter | default | description | |
x | PROMPT | x-coordinate | |
y | PROMPT | y-coordinate | |
label | PROMPT | text 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. | |
c | GR.colorlast | c.gif must be a valid GIF file. | |
xytype | GRUSER | GRUSER 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).
| |
ngraph | GR.thisgraph | the 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
Allows the addition of text at the specified x,y locations. | |||
parameter | default | description | |
x | PROMPT | x-coordinate | |
y | PROMPT | y-coordinate | |
stext | PROMPT | text to display | |
c | GR.colorlast | JavaScipt 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.
| |
xytype | GRUSER | GRUSER 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
| |
ngraph | GR.thisgraph | the 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
Closes the document at the end of graphing. This should be standard procedure. | |||
parameter | default | description | |
doc | GR.doc | the document to close | |
actions: | closes the specified document. | ||
return: | closed document | ||
view function
Closes one or more graph windows. (Graphs in the main document are not affected.) | |||
parameter | default | description | |
ngraph | 0 | the number of the graph for which the window is to be closed. Zero indicates all open graph windows. | |
delay | 20 | The delay for a setTimeout() in milliseconds.
| |
actions: | closes the specified graph window(s) | ||
return: | null | ||
view function
The primary interface for graphing after execution of | |||
parameter | default | description | |
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 | |
doc | GR.doc | graphing document | |
actions: |
Several default actions are available.
| ||
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
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
Open a new graph document in the specified frame | |||
parameter | default | description | |
frame | REQUIRED | frame 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
Opens a new window and its associated document for a new graph. | |||
parameter | default | description | |
w | 300 | window width | |
h | 300 | window height | |
t | 50 | window top | |
l | 50 | window 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
replotting of data for printing with Netscape Navigator or for redisplaying the data in a new window | |||
parameter | default | description | |
ngraph | GR.thisgraph | plot number (index into GR.List[ ] , returned by GRdrawgraph()
| |
xoff | 0 | x-offset from original | |
yoff | 0 | y-offset from original | |
doc2 | new | graph document | |
w | most recent | window width | |
h | most recent | window height | |
t | most recent | window top | |
l | most recent | window 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
Sets the window and its currently open document to be the current graphing window and document. Assumes an open document already. | |||
parameter | default | description | |
w | window | window 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
shows an alert in the graphing document | |||
parameter | default | description | |
any | REQUIRED | any 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
shows a message in a new window | |||
parameter | default | description | |
any | REQUIRED | any 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
| |||
parameter | default | description | |
i | REQUIRED | refering to div "G"+i | |
doc | REQUIRED | any 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
this function allows a determination of the contents of div "#G"+i in document doc | |||
parameter | default | description | |
i | REQUIRED | refering to div "G"+i | |
doc | REQUIRED | graphing 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
move the specided div "G"+i to the specified location | |||
parameter | default | description | |
i | REQUIRED | refering to div "G"+i | |
x | REQUIRED | x-coordinate | |
y | REQUIRED | y-coordinate | |
xytype | GRUSER | GRUSER 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
| |
ngraph | GR.thisgraph | the graph number associated with this point, starting with 1 | |
actions: | repositions the div; automatically shows it if hidden | ||
return: | null | ||
view function
shows or hides the specified div | |||
parameter | default | description | |
i | REQUIRED | refering to div "G"+i | |
TF | true | whether to show the div; true or false | |
ngraph | GR.thisgraph | the graph number associated with this point, starting with 1 | |
actions: | shows/hides the div; | ||
return: | null | ||
view function
writes HTML to a specified div of id "G"+i, moving it, if that too is specified | |||
parameter | default | description | |
i | REQUIRED | refering to div "G"+i | |
s | REQUIRED | HTML to write | |
x | OPTIONAL | x-coordinate | |
y | OPTIONAL | y-coordinate | |
xytype | GRNONE | GRUSER 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. | |
ngraph | GR.thisgraph | the 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
convert standard user form a^b to Math.pow(a,b) | |||
parameter | default | description | |
s | REQUIRED | the 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
calculates a least squares fit on x,y pairs in Data | |||
parameter | default | description | |
Data[ ] | REQUIRED | data in the form of x,y pairs | |
L[ ] | REQUIRED | return array | |
actions: | calculates least squares fit | ||
return: | L.m (slope), L.b (intercept), L.r2 (r2) | ||
view function
get the absolute x,y position of a page element. | |||
parameter | default | description | |
s | REQUIRED | the 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
find the graph associated with a specific absolute document x,y position. | |||
parameter | default | description | |
x,y | REQUIRED | document-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
responds to user clicks and moves of the mouse | |||
parameter | default | description | |
e | event | event structure from Netscape Navigator only | |
x,y | event x and y | x,y coordinates (only for testing) | |
scmd | null | the 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
| |||
parameter | default | description | |
s | REQUIRED | URL of page to open, or "" for blank window | |
opt | REQUIRED | option 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
| |||
actions: | checks for browser compatibility; sets GR.isnn4 and GR.isie4 | ||
return: | true if successful, false if unsuccessful | ||
view function
generates a user prompt in the graph window | |||
parameter | default | description | |
s | REQUIRED | prompt question string | |
a | REQUIRED | prompt 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
create a string representing a rectangle | |||
parameter | default | description | |
x1,y1 | REQUIRED | upper left coordinates | |
x2,y2 | REQUIRED | lower right coordinates | |
c | GR.colorlast | c.gif must be a valid GIF file. | |
xytype | GRUSER | GRUSER 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).
| |
ngraph | GR.thisgraph | the 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
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
rounds off a number to a specified number of digits | |||
parameter | default | description | |
x | REQUIRED | number to be rounded | |
ndec | depends | number 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
set current graph to be ngraph | |||
parameter | default | description | |
ngraph | REQUIRED | the number of the graph to make the default graph | |
tolist | false | true: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
displays all elements of an object | |||
parameter | default | description | |
obj | REQUIRED | object to be enumerated | |
objName | "obj" | name to supply for the object | |
signore | null | ignore all elements containing this text in their name | |
sonly | null | include 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
converts user x-coordinate to document coordinates | |||
parameter | default | description | |
x | REQUIRED | user x-coordinate | |
return: | Math.round(GR.left+(x-GR.xmin)*GR.xfactor) | ||
view function
converts user y-coordinate to document coordinates | |||
parameter | default | description | |
y | REQUIRED | user y-coordinate | |
return: | Math.round(GR.top+GR.height-(y-GR.ymin)*GR.yfactor) |