Private
dataHolds the most recent data points drawn, to enable redrawing when needed.
Private
drawThe color to draw the graph with, a CSS3 color string.
Private
drawwhether to draw the graph with lines or dots
Private
hotThe color to draw the hot spot (most recent point) with, a CSS3 color string.
Private
lineThickness to use when drawing the line, in screen coordinates, so a unit is a screen pixel.
Private
styles_GraphStyle's for display, ordered by index in dataPoints list. There can be multiple GraphStyle entries for the same index, the latest one in the list takes precedence. We ensure there is always at least one GraphStyle in the list.
Private
varsThe VarsList whose data this graph is displaying
Function that gives the transformed the X value.
Function that gives the transformed the X value.
Private
xParameter that represents which variable is shown on X-axis, and the available choices of variables.
Private
xindex of horizontal variable in simulation's variables, or -1 to not collect any X variable data
Function that gives the transformed the Y value.
Function that gives the transformed the Y value.
Private
yParameter that represents which variable is shown on Y-axis, and the available choices of variables.
Private
yindex of vertical variable in simulation's variables, or -1 to not collect any X variable data
Static
RESETEvent broadcast when reset is called.
Private
addAdds the given Observer to this Subject's list of Observers, so that the Observer
will be notified of changes in this Subject. An Observer may call Subject.addObserver
during its observe
method.
the Observer to add
Adds the Parameter to the list of this Subject's available Parameters.
the Parameter to add
if a Parameter with the same name already exists.
Notifies all Observers that this Subject has changed by calling observe on each Observer.
An Observer may call addObserver or removeObserver during its observe
method.
a SubjectEvent with information relating to the change
Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.
the language-independent or English name of the Parameter that has changed
if there is no Parameter with the given name
Private
buildProtected
getReturns whether broadcasting is enabled for this Subject. See setBroadcast.
whether broadcasting is enabled for this Subject
Returns the DrawingMode of the graph: dots or lines.
the DrawingMode to draw this graph with
Returns the HistoryList of GraphPoints.
Returns the GraphStyle corresponding to the position in the list of GraphPoints.
the index number in list of GraphPoints
the GraphStyle for that position
Returns the ParameterBoolean with the given name.
the language-independent or English name of the ParameterBoolean
the ParameterBoolean with the given name
if there is no ParameterBoolean with the given name
Returns the ParameterNumber with the given name.
the language-independent or English name of the ParameterNumber
the ParameterNumber with the given name
if there is no ParameterNumber with the given name
Returns the ParameterString with the given name.
the language-independent or English name of the ParameterString
the ParameterString with the given name
if there is no ParameterString with the given name
Notifies this Observer that a change has occurred in the Subject.
contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter
Removes the Observer from this Subject's list of Observers. An Observer may
call removeObserver
during its observe
method.
the Observer to detach from list of Observers
Removes the Parameter from the list of this Subject's available Parameters.
the Parameter to remove
Forgets any memorized data and styles, starts from scratch. However, it also calls memorize to memorize the current data point, if any.
Forgets any memorized styles, records the current color, draw mode, and line width as the single starting style. Note that you may need to call DisplayGraph.reset to see this change take effect.
Protected
setSets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.
whether this Subject should broadcast events
the previous value
Sets whether to draw the graph with dots or lines. Applies only to portions of graph memorized after this time.
the DrawingMode (dots or lines) to draw this graph with.
if the value does not represent a valid DrawingMode
Sets the variable from which to collect data for the X value of the graph. Starts
over with a new HistoryList. Broadcasts the ParameterNumber named
GraphLine.i18n.X_VARIABLE
.
the name or index of X variable in the VarsList, or -1 to not collect any X variable data and have an empty HistoryList. The name can be the English or language independent version of the name
if the index is out of range, or the variable name doesn't exist
Sets the variable from which to collect data for the Y value of the graph. Starts
over with a new HistoryList. Broadcasts the ParameterNumber named
GraphLine.i18n.Y_VARIABLE
.
the name or index of Y variable in the VarsList, or -1 to not collect any Y variable data and have an empty HistoryList. The name can be the English or language independent version of the name
if the index is out of range, or the variable name doesn't exist
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort
on that other object.
For example, calling toStringShort()
on a DisplayShape might return something like
this:
DisplayShape{polygon:Polygon{'chain3'}}
a minimal string representation of this object.
Generated using TypeDoc
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. A GraphLine is typically shown by a DisplayGraph.
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 SimView by calling SimView.addMemo, for example: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:
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
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:
Note that the transform functions do not affect how the graph axes are shown.
Parameters Created
ParameterNumber named
X_VARIABLE
, see setXVariable. Has an extraNONE
choice, which causes the GraphLine to have an empty HistoryList.ParameterNumber named
Y_VARIABLE
, see setYVariable. Has an extraNONE
choice, which causes the GraphLine to have an empty HistoryList.ParameterNumber named
LINE_WIDTH
, see setLineWidth.ParameterString named
DRAWING_MODE
, see setDrawingMode.ParameterString named
GRAPH_COLOR
, see setColor.Events Broadcast
All the Parameters are broadcast when their values change. In addition:
RESET
, see reset.