Development of a Real-Time Dynamic Graphing Web Page

Implementation of the Theory as Code: Adding divgraph.js

We have a working first draft. Time to add the graphing. We have to initialize the plot, then add points. Here are our new functions:

Notice that no changes were made to react(). That's good, because it indicates that we have properly isolated the calculation from the implementation of the interface. In plotpoint() we've changed the status line to a call to GRaddpoint(), one of the functions of divgraph.js:

 GRaddpoint(x,y,"",color,GRUSER)

The third parameter is blank, because that is reserved for a label, and we don't need that, at least not yet. GRUSER here tells GRaddpoint() to use our coordinate system, not the document's.

The big change is in initialize(). Here we are

It may seem strange to close the document, but the way that the divgraph.js package works, points aren't really "added" later. The setting of Info.maxaddpoints = tmax * 2 actually writes all those points, but makes them invisible by creating a "place-holder" div from them and setting it well off the page. The GRaddpoint() function simply installs the image in the div and moves it to the desired location.

Run initialize();react()

View the code

After you click on the "Run initialize();react()" link, above, what do you think?

When you are ready, let's implement the user interface.

back to the list of examples


copyright 2001 Robert M. Hanson. All rights reserved. divgraph.js is freely distributable for noncomercial purposes, provided reference is made as "divgraph.js was developed at St. Olaf College by Robert M. Hanson (http://www.stolaf.edu/people/hansonr/divgraph)." Commercial licensing is available for specific purposes.