Displays one or more GraphLine. The GraphLines are drawn in the simulation coordinates of the containing SimView.

The screen rectangle that the DisplayGraph should occupy within the SimView must be set with setScreenRect before drawing can be done.

Additional GraphLines can be shown in the DisplayGraph, see addGraphLine.

The GraphLine can be drawn into an offscreen image, see setUseBuffer. The default is to use an offscreen image; this saves time by not needing to redraw the entire graph every frame.

Discontinuity

A change to a variable is either continuous or discontinuous. DisplayGraph doesn't draw a line at a point of discontinuity, but draws a dot instead. A discontinuity is indicated by incrementing the sequence number, see VarsList.

Implements

Constructors

Properties

graphLines_: GraphLine[]

The GraphLines to draw.

lastMap_: null | CoordMap = null

to detect when redraw needed; when the coordmap changes, we need to redraw.

memDraw_: number[]

Index of last point drawn within GraphPoints list of each GraphLine

needRedraw_: boolean = false

set when the entire graph needs to be redrawn.

offScreen_: null | HTMLCanvasElement = null

The offscreen buffer to draw the graph into

useBuffer_: boolean = true

Whether to draw into the offscreen buffer.

Methods

  • Whether the DisplayObject contains the given world coordinates point.

    Parameters

    • _p_world: Vector

      the point in world coordinates

    Returns boolean

    true if this DisplayObject contains the given point

  • Draws this DisplayObject using the given CoordMap.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw this object into

    • map: CoordMap

      the mapping to use for translating between simulation and screen coordinates

    Returns void

  • Draws a highly visible mark at the most recent point of the graph. Draws a small 5 pixel wide rectangle with the color set by GraphLine.setHotSpotColor. If the hot spot color is the empty string, then the hot spot is not drawn.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • coordMap: CoordMap

      the CoordMap specifying sim to screen conversion

    • graphLine: GraphLine

    Returns void

  • Draws the points starting from the specified point to the most recent point; returns the index of last point drawn.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • coordMap: CoordMap

      the CoordMap specifying sim to screen conversion

    • from: number

      the index of the the point to start from, within the datapoints

    • graphLine: GraphLine

    Returns number

    the index of the last point drawn, within the data points

  • Draws the entire graph into the given Graphics context.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • coordMap: CoordMap

      the CoordMap specifying sim to screen conversion

    Returns void

  • Whether this DisplayGraph is drawing into an offscreen buffer.

    Returns boolean

    Whether this DisplayGraph is drawing into an offscreen buffer

  • Sets the z-index which specifies front-to-back ordering of objects; objects with a higher zIndex are drawn over (in front of) objects with a lower zIndex.

    Returns number

    the zIndex of this DisplayObject

  • Draws only the recent points into the given Graphics context. Keeps track of what was the last point drawn.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • coordMap: CoordMap

      the CoordMap specifying sim to screen conversion

    Returns void

  • Remove a GraphLine from set of those to display.

    Parameters

    • graphLine: GraphLine

      the GraphLine to not display

    Returns void

  • Sets whether this DisplayObject is currently dragable; has no effect on objects that are not dragable.

    Parameters

    • _dragable: boolean

      whether this DisplayObject should be dragable

    Returns void

  • Sets this DisplayObject's position in simulation coordinates of the containing SimView. Each type of DisplayObject has a different policy regarding whether this will have an effect. Generally the policies are:

    • If the DisplayObject does not represent a SimObject, then the position can be set. Examples are DisplayClock, EnergyBarGraph.

    • If the SimObject's position is dependent on other objects, then the position cannot be set. Examples are DisplayConnector, DisplayRope, DisplaySpring.

    • If the SimObject can be moved independently and isDragable is true, then the position of the SimObject is modified. Example: DisplayShape.

    Parameters

    • _position: GenericVector

      this DisplayObject's position, in simulation coordinates.

    Returns void

  • Sets the screen rectangle that this DisplayGraph should occupy within the SimView, in screen coordinates.

    Parameters

    • screenRect: ScreenRect

      the screen coordinates of the area this DisplayGraph should occupy.

    Returns void

  • Whether to draw into an offscreen buffer. A time graph must redraw every frame, so it saves time to not use an offscreen buffer in that case.

    Parameters

    • value: boolean

      Whether to draw into an offscreen buffer

    Returns void

  • Sets the z-index which specifies front-to-back ordering of objects; objects with a higher zIndex are drawn over objects with a lower zIndex. Default is zero.

    Parameters

    • zIndex: number

      the zIndex of this DisplayObject

    Returns void

Generated using TypeDoc