A visual representation of a Simulation which can be displayed in a LabCanvas; has a DisplayList which represents the SimObjects of the Simulation; defines how to translate simulation coordinates to LabCanvas screen coordinates.

A SimView is shown inside a LabCanvas, possibly overlaid with other SimViews.

Boundary Rectangles

A SimView keeps track of two boundary rectangles: the simulation and screen rectangles.

  • The simulation rectangle specifies what area of the simulation space to display in this SimView. See getSimRect.

  • The screen rectangle specifies where to show this SimView within the containing LabCanvas. See getScreenRect. The screen rectangle is initially set to a default size of 800 by 600.

A CoordMap maps the simulation rectangle onto the screen rectangle, in accordance with various alignment options; see setHorizAlign, setVerticalAlign, setAspectRatio. The CoordMap is available via getCoordMap. The CoordMap is passed to each DisplayObject during the paint method.

Pan-Zoom Controls

The methods such as panUp, panLeft, zoomIn, zoomOut are used to make a 'pan-zoom control' in CommonControls.makePanZoomControls. The amount of pan-zoom that is done by each invocation of those methods can be changed via the properties panX, panY, zoom.

Parameters Created

Events Broadcast

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

  • GenericEvent named SIM_RECT_CHANGED when the simulation rectangle changes.

  • GenericEvent named COORD_MAP_CHANGED when the CoordMap changes.

Hierarchy (view full)

Implements

Constructors

Properties

coordMap_: CoordMap

The CoordMap that defines the simulation coordinates for this SimView.

displayList_: DisplayList = ...

This list of DisplayObjects that this SimView displays

opaqueness: number = 1.0

The transparency used when painting the drawables; a number between 0.0 (fully transparent) and 1.0 (fully opaque).

panX: number = 0.05

when panning horizontally, this is percentage of width to move.

panY: number = 0.05

when panning vertically, this is percentage of height to move.

ratio_: number

ratio of height/width, used when scaleTogether_ is true.

screenRect_: ScreenRect = ...

The rectangle in screen coordinates where this SimView exists inside the LabCanvas.

simRect_: DoubleRect

The boundary rectangle in simulation coordinates.

zoom: number = 1.1

when zooming, this is percentage of size to zoom

COORD_MAP_CHANGED: string = 'COORD_MAP_CHANGED'

Name of event broadcast when the CoordMap changes, see setCoordMap.

SCREEN_RECT_CHANGED: string = 'SCREEN_RECT_CHANGED'

Name of event broadcast when the screen rectangle size changes, see setScreenRect.

SIM_RECT_CHANGED: string = 'SIM_RECT_CHANGED'

Name of event broadcast when the simulation rectangle size changes, see setSimRect.

Methods

  • Adds an object to the list of Memorizable objects. These object's memorize methods will be called from this object's memorize method.

    Parameters

    • memorizable: Memorizable

      object to add to the list of Memorizable objects

    Returns void

    Throws

    if called during the memorize method.

  • Called when this SimView becomes the focus view of the LabCanvas.

    Returns void

  • Returns the ratio of 'pixels per simulation unit along y axis' divided by 'pixels per simulation unit along x axis' used when displaying this SimView. See CoordMap.

    Returns number

    the aspect ratio used when displaying this SimView

  • Returns the horizontal coordinate of simulation rectangle's center.

    Returns number

    horizontal coordinate of simulation rectangle's center.

  • Returns the vertical coordinate of simulation rectangle's center.

    Returns number

    the vertical coordinate of simulation rectangle's center.

  • Returns true if this SimView has changed, and sets the state to "unchanged".

    Returns boolean

    whether this SimView has changed

  • Returns the CoordMap that defines the mapping between screen coordinates and simulation coordinates.

    Returns CoordMap

    the CoordMap being used by this SimView

  • Returns height of the simulation rectangle.

    Returns number

    height of the simulation rectangle

  • Returns the horizontal alignment to use when aligning the SimView's simulation rectangle within its screen rectangle. See CoordMap.

    Returns HorizAlign

    the horizontal alignment to use for aligning the simulation rectangle within the screen rectangle

  • Whether the width and height of the simulation rectangle scale together; if true then changing one causes the other to change proportionally.

    Returns boolean

    whether width and height scale together

  • Returns the screen rectangle that this SimView is occupying within the LabCanvas, in screen coordinates.

    Returns ScreenRect

    the screen rectangle of this SimView in screen coordinates

  • Returns the bounding rectangle for this SimView in simulation coordinates.

    Returns DoubleRect

    the bounding rectangle for this SimView in simulation coordinates

  • Returns the vertical alignment to use when aligning the SimView's simulation rectangle within its screen rectangle. See CoordMap.

    Returns VerticalAlign

    the vertical alignment to use for aligning the simulation rectangle within the screen rectangle

  • Returns the width of the simulation rectangle.

    Returns number

    width of the simulation rectangle

  • Called when this SimView is no longer the focus view of the LabCanvas.

    Returns void

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

    Returns void

  • Modifies the simulation rectangle of the target SimView according to our current settings for width, height, centerX, centerY.

    Returns void

  • Paints this SimView into the given CanvasRenderingContext2D.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    Returns void

  • Moves the center of the simulation rectangle (the 'camera') down by fraction panY, which causes the image to move up. Also broadcasts a SIM_RECT_CHANGED event.

    Returns void

  • Moves the center of the simulation rectangle (the 'camera') left by fraction panX, which causes the image to move right. Also broadcasts a SIM_RECT_CHANGED event.

    Returns void

  • Moves the center of the simulation rectangle (the 'camera') right by fraction panX, which causes the image to move left. Also broadcasts a SIM_RECT_CHANGED event.

    Returns void

  • Moves the center of the simulation rectangle (the 'camera') up by fraction panY, which causes the image to move down. Also broadcasts a SIM_RECT_CHANGED event.

    Returns void

  • Removes an object from the list of Memorizable objects.

    Parameters

    • memorizable: Memorizable

      object to remove from the list of Memorizable objects

    Returns void

    Throws

    if called during the memorize method.

  • Sets the ratio of 'pixels per simulation unit along y axis' divided by 'pixels per simulation unit along x axis' used when displaying this SimView. See CoordMap.

    Parameters

    • aspectRatio: number

      the aspect ratio used when displaying this SimView

    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

  • Sets the horizontal coordinate of simulation rectangle's center, and broadcasts a SIM_RECT_CHANGED event.

    Parameters

    • value: number

      the horizontal coordinate of simulation rectangle's center.

    Returns void

  • Sets the vertical coordinate of simulation rectangle's center, and broadcasts a SIM_RECT_CHANGED event.

    Parameters

    • value: number

      the vertical coordinate of simulation rectangle's center.

    Returns void

  • Sets the CoordMap used by this SimView.

    Parameters

    • map: CoordMap

      the CoordMap to use for this SimView

    Returns void

  • Sets height of the simulation rectangle, and broadcasts a SIM_RECT_CHANGED event

    Parameters

    • value: number

      height of the simulation rectangle

    Returns void

  • Sets the horizontal alignment to use when aligning the SimView's simulation rectangle within its screen rectangle. See CoordMap.

    Parameters

    • alignHoriz: HorizAlign

      the horizontal alignment to use for aligning the simulation rectangle within the screen rectangle

    Returns void

  • Sets whether the width and height of the simulation rectangle scale together; if true then changing one causes the other to change proportionally.

    Parameters

    • value: boolean

      whether width and height scale together

    Returns void

  • Sets the area that this SimView will occupy within the LabCanvas, in screen coordinates.

    Parameters

    • screenRect: ScreenRect

      the screen coordinates of the area this SimView should occupy

    Returns void

  • Sets the bounding rectangle for this SimView, ensures this rectangle is visible, and turns off auto-scaling. The result is to generate a new CoordMap for this SimView so that the simulation rectangle maps to the current screen rectangle.

    Parameters

    • simRect: DoubleRect

      the bounding rectangle for this SimView in simulation coordinates.

    Returns void

  • Sets the vertical alignment to use when aligning the SimView's simulation rectangle within its screen rectangle. See CoordMap.

    Parameters

    • alignVert: VerticalAlign

      the vertical alignment to use for aligning the simulation rectangle within the screen rectangle

    Returns void

  • Sets width of the simulation rectangle, and broadcasts a SIM_RECT_CHANGED event.

    Parameters

    • value: number

      width of the simulation 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.

Generated using TypeDoc