Watches the VarsList of one or more GraphLine to calculate the range rectangle that encloses the points on the graphs, and sets accordingly the simRect of a SimView. The range rectangle is the smallest rectangle that contains all the points, but possibly expanded by the extraMargin factor.

Temporarily Deactivate

When the user pans or zooms the graph, we need to temporarily turn off the auto-scale behavior. When the user clicks the "reset" button in the middle of the pan-zoom control, this means "turn auto-scale back on".

To accomodate these behaviors, AutoScale observes the SimView and GraphLines and will react to their events as follows (assuming the AutoScale is enabled):

  • AutoScale becomes inactive when the SimView's simRect is changed by an entity other than this AutoScale. This happens when AutoScale observes a SimView event called SIM_RECT_CHANGED.

  • AutoScale becomes active when one of its GraphLines broadcasts a RESET event. This happens when a graph is cleared, or when the X or Y variable is changed.

You can also directly call setActive to make the AutoScale active or inactive (but it must also be enabled to actually do anything).

To entirely disable an AutoScale, use setEnabled.

Time Graph

For a time graph where one variable is time, the range rectangle in the time dimension has a fixed size specified by setTimeWindow. The default time window is 10 seconds.

Parameters Created

Events Broadcast

All the Parameters are broadcast when their values change. In addition:

  • GenericEvent named AUTO_SCALE is broadcast when the range rectangle changes. The new range rectangle is the value of the event.

Hierarchy (view full)

Implements

Constructors

Properties

extraMargin: number = 0.01

How much extra margin to allocate when expanding the graph range: a fraction typically between 0.0 and 1.0, adds this fraction times the current horizontal or vertical range.

This does not guarantee a margin of this amount, it merely reduces the frequency of range expansion. You could for example expand the range, and then have succeeding points come very close to the new range so that the graph goes very close to the edge but stays within the range.

graphLines_: GraphLine[]

The GraphLines to auto-scale.

lastIndex_: number[]

Index of last point seen within GraphPoints list of each GraphLine

minSize: number = 1E-14

Minimum size that range rectangle can be, for width and height.

ownEvent_: boolean = false

Indicates that the SIM_RECT_CHANGED event was generated by this AutoScale.

rangeSetX_: boolean = false

false indicates that the range has never been set based on graph data

rangeSetY_: boolean = false

false indicates that the range has never been set based on graph data

rangeXHi_: number = 0

the maximum horizontal value of the range, used for calculating the scale

rangeXLo_: number = 0

the minimum horizontal value of the range, used for calculating the scale

rangeYHi_: number = 0

the maximum vertical value of the range, used for calculating the scale

rangeYLo_: number = 0

the minimum vertical value of the range, used for calculating the scale

timeWindow_: number = 10

Length of time to include in the range rectangle for a 'time graph'.

AUTO_SCALE: "AUTO_SCALE" = 'AUTO_SCALE'

Name of event broadcast when a new enclosing simulation rectangle has been calculated.

BOTH_AXES: "BOTH_AXES" = 'BOTH_AXES'

Specifies both axes option for setAxis.

HORIZONTAL: "HORIZONTAL" = 'HORIZONTAL'

Specifies horizontal axis option for setAxis.

VERTICAL: "VERTICAL" = 'VERTICAL'

Specifies vertical axis option for setAxis.

Methods

  • Add a GraphLine which will be observed to calculate the range rectangle of points on the line.

    Parameters

    Returns void

  • Clears the range rectangle, continues calculating from latest entry in HistoryList.

    Returns void

  • Returns which axis should be auto scaled: one of VERTICAL, HORIZONTAL, or BOTH_AXES.

    Returns string

    which axis should be auto scaled

  • Returns the range rectangle that encloses points on the GraphLines, including any extra margin. Note that this rectangle might not correspond to the SimView's simulation rectangle, see setAxis.

    Returns DoubleRect

    the range rectangle that encloses points on the GraphLines

  • Returns length of time to include in the range rectangle for a time graph.

    Returns number

    length of time to include in the range rectangle

  • Memorize the current simulation data, or do some other function that should happen regularly after each simulation time step.

    Returns void

  • Notifies this Observer that a change has occurred in the Subject.

    Parameters

    • event: SubjectEvent

      contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter

    Returns void

  • When the range rectangle changes, this will broadcast a GenericEvent named AUTO_SCALE.

    Returns void

  • Remove a GraphLine, it will no longer be observed for calculating the range rectangle of points on the line.

    Parameters

    Returns void

  • Clears the range rectangle, and starts calculating from first entry in HistoryList. Note that you will need to call memorize to have the range recalculated.

    Returns void

  • Sets whether this AutoScale is active. When not active, the range rectangle is not updated and the SimView's simulation rectangle is not modified. When changed to be active, this will also call reset.

    The AutoScale must be enabled in order to become active, see setEnabled. If not enabled, then this method can only make the AutoScale inactive.

    Parameters

    • value: boolean

      whether this AutoScale should be active

    Returns void

  • Set which axis to auto scale: one of VERTICAL, HORIZONTAL, or BOTH_AXES.

    Parameters

    • value: string

      which axis should be auto scaled

    Returns void

  • Sets 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.

    Parameters

    • value: boolean

      whether this Subject should broadcast events

    Returns boolean

    the previous value

  • Marks the SimView's Parameters as to whether they are automatically computed depending on whether this AutoScale is active.

    Parameters

    • value: boolean

      whether this AutoScale is computing the Parameter values

    Returns void

  • Sets whether this AutoScale is enabled. The AutoScale must be enabled in order to be active. See setActive.

    Parameters

    • value: boolean

      whether this AutoScale should be enabled

    Returns void

  • Sets length of time to include in the range rectangle for a time graph, and sets the AutoScale to be active. See setActive.

    Parameters

    • value: number

      length of time to include in the range rectangle

    Returns void

  • 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'}}
    

    Returns string

    a minimal string representation of this object.

  • Updates the graph range to include the given point. For time variable, limit the range to the timeWindow. For non-time variable, expand the range an extra amount when the range is exceeded; this helps avoid too many visually distracting updates.

    Parameters

    Returns void

Generated using TypeDoc