Draws linear horizontal and vertical axes within a given simulation coordinates rectangle. The simulation rectangle determines where the axes are drawn, and the numbering scale shown, see setSimRect.

Axes are drawn with numbered tick marks. Axes are labeled with names which can be specified by setHorizName and setVerticalName. Axes are drawn using specified font and color, see setColor and setFont.

Options exist for drawing the vertical axis near the left, center, or right, and for drawing the horizontal axis near the top, center, or bottom of the screen. See setXAxisAlignment and setYAxisAlignment.

You can set the axes alignment to go thru particular points, like the origin:

axes.setXAxisAlignment(VerticalAlign.VALUE, 0);
axes.setYAxisAlignment(HorizAlign.VALUE, 0);

To keep the DisplayAxes in sync with a SimView, when doing for example pan/zoom of the SimView, you can arrange for setSimRect to be called by an Observer. See for example CommonControls.makeAxes which makes a GenericObserver that keeps the DisplayAxes in sync with the SimView.

TO DO add option to set the number of tick marks (instead of automatic)?

Implements

Constructors

  • Parameters

    • Optional opt_simRect: DoubleRect

      the area to draw axes for in simulation coordinates.

    • Optional opt_font: string

      the Font to draw numbers and names of axes with

    • Optional opt_color: string

      the Color to draw the axes with

    Returns DisplayAxes

Properties

drawColor_: string

the color to draw the axes with

fontAscent: number = 12

Font ascent in pixels (guesstimate).

fontDescent: number = 8

Font descent in pixels (guesstimate). TO DO find a way to get this for the current font, similar to the TextMetrics object. http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript http://pomax.nihongoresources.com/pages/Font.js/

horizAlignValue_: number = 0

The number on vertical axis to align with when using VerticalAlign.VALUE

horizAxisAlignment_: VerticalAlign = VerticalAlign.VALUE

location of the horizontal axis

horizName_: string = 'x'

name of horizontal axis

numDecimal_: number = 0

Number of fractional decimal places to show.

numFont_: string

the font to use for drawing numbers and text on the axis Oct 2014: increased from 10pt to 14pt because standard canvas is now larger

simRect_: DoubleRect

bounds rectangle of area to draw

vertAlignValue_: number = 0

The number on horizontal axis to align with when using HorizAlign.VALUE

vertAxisAlignment_: HorizAlign = HorizAlign.VALUE

location of the vertical axis

verticalName_: string = 'y'

name of vertical axis

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 the tick marks for the horizontal axis.

    Parameters

    • y0: number

      the vertical placement of the horizontal axis, in screen coords

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • map: CoordMap

      the mapping to use for translating between simulation and screen coordinates

    • r: DoubleRect

      the view area in simulation coords

    Returns void

  • Draws the tick marks for the vertical axis.

    Parameters

    • x0: number

      the horizontal placement of the vertical axis, in screen coords

    • context: CanvasRenderingContext2D

      the canvas's context to draw into

    • map: CoordMap

      the mapping to use for translating between simulation and screen coordinates

    • r: DoubleRect

      the view area in simulation coords

    Returns void

  • Returns the color to draw the graph axes with.

    Returns string

    the color to draw the graph axes with

  • Returns the font to draw the graph axes with.

    Returns string

    the font to draw the graph axes with

  • Returns the name shown next to the horizontal axis.

    Returns string

    the name of the horizontal axis.

  • Returns an increment to use for spacing of tick marks on an axis. The increment should be a 'round' number, with few fractional decimal places. It should divide the given range into around 5 to 7 pieces.

    Side effect: modifies the number of fractional digits to show

    Parameters

    • range: number

      the span of the axis

    Returns number

    an increment to use for spacing of tick marks on an axis.

  • Returns the bounding rectangle for this DisplayAxes in simulation coordinates, which determines the numbering scale shown.

    Returns DoubleRect

    the bounding rectangle for this DisplayAxes in simulation coordinates.

  • Returns the name shown next to the vertical axis.

    Returns string

    the name of the vertical axis.

  • 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

  • Set the color to draw the graph axes with.

    Parameters

    • color: string

      the color to draw the graph axes with

    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

  • Set the font to draw the graph axes with.

    Parameters

    • font: string

      the font to draw the graph axes with

    Returns void

  • Sets the name shown next to the horizontal axis

    Parameters

    • name: string

      name of the horizontal axis

    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 bounding rectangle for this DisplayAxes in simulation coordinates; this determines the numbering scale shown.

    Parameters

    • simRect: DoubleRect

      the bounding rectangle for this DisplayAxes in simulation coordinates.

    Returns void

  • Sets the name shown next to the vertical axis

    Parameters

    • name: string

      name of the vertical axis

    Returns void

  • Sets the X-axis alignment: whether it should appear at bottom, top or middle of the simulation rectangle, or go thru a particular value of the Y-axis.

    Parameters

    Returns DisplayAxes

    this object for chaining setters

  • Sets the Y-axis alignment: whether it should appear at left, right or middle of the simulation rectangle, or go thru a particular value of the X-axis.

    Parameters

    • alignment: HorizAlign

      Y-axis alignment option

    • Optional value: number

      number on horizontal axis to align with when using HorizAlign.VALUE

    Returns DisplayAxes

    this object for chaining setters

  • 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

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

  • Returns the starting value for the tick marks on an axis.

    Parameters

    • start: number

      the lowest value on the axis

    • incr: number

      the increment between tick marks on the axis

    Returns number

    the starting value for the tick marks on the axis.

Generated using TypeDoc