search

Class myphysicslab.lab.graph.GraphLine

Provided By
Extends
All Implemented Interfaces

Collects data from a VarsList, storing it as a HistoryList composed of GraphPoints. The variables that this GraphLine is tracking are selected via the methods #setXVariable and #setYVariable.

It is during the #memorize method that the new data is stored into the HistoryList. For the memorize method to be called automatically, the GraphLine can be registered with it's LabView by calling addMemo on the LabView, for example:

simView.addMemo(graphLine);

Graph Styles

The color, line thickness, and drawing mode (dots or line) can be changed via methods #setColor, #setLineWidth, and #setDrawingMode.

The style used for drawing the graph can be changed at any time, without altering the style used for points previously memorized. Changes to style affect only how the next memorized points are displayed.

If you do want to change the style for the entire line, call #resetStyle which will forget about all styles except the current style and apply that to the entire line.

Note: line dash is not a supported feature because the graph is drawn incrementally as thousands of short line segments and the line dash starts over for each segment. It might be possible to use the HTML CanvasRenderingContext2D.lineDashOffset property to deal with this.

Axes Names

To update the names of the axes shown in a DisplayAxes, set up a GenericObserver to watch for changes to the variables tracked by the GraphLine, as in this example:

new GenericObserver(graphLine, function(evt) {
  axes.setHorizName(graphLine.getXVarName());
  axes.setVerticalName(graphLine.getYVarName());
});

Polar or Logarithmic Graph

It is possible to create a polar or logarithmic type of graph by specifying transform functions. For example, a polar graph could be created with

graphLine.xTransform = function(x,y) { return y*Math.cos(x); };
graphLine.yTransform = function(x,y) { return y*Math.sin(x); };

That transformation regards the X value as the angle and the Y value as the radius.

The transformation is done while memorizing points from the VarsList. The HistoryList contains transformed points something like this:

new GraphPoint(xTransform(x, y), yTransform(x, y));

Note that the transform functions do not affect how the graph axes are shown.

Parameters Created

  • ParameterNumber named GraphLine.en.X_VARIABLE, see #setXVariable. Has an extra NONE choice, which causes the GraphLine to have an empty HistoryList.

  • ParameterNumber named GraphLine.en.Y_VARIABLE, see #setYVariable. Has an extra NONE choice, which causes the GraphLine to have an empty HistoryList.

new GraphLine( name, varsList, opt_capacity )

Parameters
namestring
varsListmyphysicslab.lab.model.VarsList

the VarsList to collect data from

opt_capacity(number|undefined)

number of GraphPoints to store

Instance Methods

Static Functions

Static Properties

Type Definitions