Home Reference Source
private class | source

Axis

Extends:

WorldElement → Axis

The Axis class is responsible for drawing the axis onto the canvas and setting the new origin used for the canvas. All objects displayed will be referenced to the position of the axis. Therefore, by changing its position the origin is also displaced.

Constructor Summary

Public Constructor
public

constructor(width: number, height: number, opts: object)

Member Summary

Public Members
public

Sets the color of the main -x and -y axis.

public

Sets the cursor style when the mouse is over the axis.

public

Flag for enabling the display of the -x axis.

public

Flag for enabling the display of the -y axis.

public

Flag for enabling the drawing of the grid.

public

Sets the current height of the axis.

public

Flag for allowing the axis to be dragged around.

public

max: number[]

Stores the maximum dimensions that the axis can have given the current position and dimensions of the axis in both -x and -y directions.

public

min: number[]

Stores the minimum dimensions that the axis can have given the current position and dimensions of the axis in both -x and -y directions.

public

Sets the move style of the axis to change by pixels rather than by units.

public

Flag for enabling the drawing of the negative part of the axis.

public

Flag for placing the numbers on the outside of the first quadrant of the axis.

public

Sets the prerenderer for the Axis.

public

Sets the color of the grid.

public

Sets the distance between the axis and the unit label.

public

Sets the length of the ticks that are placed every "unit" in pixels.

public

Sets the length of the smaller ticks that are placed every "unit" / 2 in pixels.

public

Sets the current width of the axis.

Method Summary

Public Methods
public

Test if a point is visible given the current position of the axis and the canvas size.

Private Methods
private

draw()

Main draw function for the axis called by the World automatically.

private

Draws the axis onto the selected canvas (renderer by default).

private

Tests if the mouse is over the axis.

private

resize()

Updates the dimensions of the axis when the world gets resized.

Inherited Summary

From class WorldElement
public

Sets the color in HEX format of the element.

public

Sets the cursor style when the mouse is over the element.

public

Flag for enabling or diabling this element.

public

Flag set when the element is being dragged around.

public

Sets the font of the element.

public

Sets the current height of the element.

public

Flag for allowing the element to be dragged around.

public

Sets the move style of the element.

public

Flag set when the mouse is over the element.

public

Sets a callback function for when the element is dragged around.

public

Sets the position of the element.

public

Sets the renderer used for the element.

public

Sets the rotation of the element.

public

A copy of the z-index value is stored here.

public

Sets the drawing scale of the element.

public

Flag for determining if the element will be a top-most element when dragged around.

public

Flag used to determine if an object is a child of WorldElement.

public

Sets the current width of the element.

public

Sets the world where this element is found.

public

Sets the z-index of the element.

public

Adds the provided coordinates to the position.

public

Sets if the element is draggable.

public

Function called when the mouse moves to check if the pointer is over the element.

public

Sets the color in HEX format of the element.

public

Sets the position of the element.

public

Sets the scale of the element.

public

setZ(z: number)

Sets the z-index of the element.

private

resize()

Function called when the canvas gets resized.

private

setWorld(world: World)

Sets the world object where element will be drawn.

private

topmost(state: boolean)

Sets the element as a topmost element.

Public Constructors

public constructor(width: number, height: number, opts: object) source

Override:

WorldElement#constructor

Params:

NameTypeAttributeDescription
width number
  • optional
  • default: 0

Initial width of the axis.

height number
  • optional
  • default: 0

Initial height of the canvas.

opts object
  • optional

Object that contains valid Axis properties with values. Their values will be assigned at the end of the constructor. If an invalid property is passed then the value will be ignored.

Public Members

public color: string source

Sets the color of the main -x and -y axis. Default value is #CCCCCC.

Override:

WorldElement#color

public cursor: string source

Sets the cursor style when the mouse is over the axis. Default value is CURSOR.MOVE.

Override:

WorldElement#cursor

public displayX: boolean source

Flag for enabling the display of the -x axis. Default value is true.

public displayY: boolean source

Flag for enabling the display of the -y axis. Default value is true.

public grid: boolean source

Flag for enabling the drawing of the grid. Default value is true.

public height: number source

Sets the current height of the axis.

Override:

WorldElement#height

public isDraggable: boolean source

Flag for allowing the axis to be dragged around. Default value is true.

Override:

WorldElement#isDraggable

public max: number[] source

Stores the maximum dimensions that the axis can have given the current position and dimensions of the axis in both -x and -y directions.

public min: number[] source

Stores the minimum dimensions that the axis can have given the current position and dimensions of the axis in both -x and -y directions.

public mouseMoveStyle: string source

Sets the move style of the axis to change by pixels rather than by units. Default value is MOVE_STYLE.BY_PX.

Override:

WorldElement#mouseMoveStyle

public negative: boolean source

Flag for enabling the drawing of the negative part of the axis. Default value is true.

public outsideNumbers: boolean source

Flag for placing the numbers on the outside of the first quadrant of the axis. Default value is true.

public renderer: Renderer source

Sets the prerenderer for the Axis. It is enabled by default.

Override:

WorldElement#renderer

public subAxisColor: string source

Sets the color of the grid. Default value is #EEEEEE.

public textOffset: number source

Sets the distance between the axis and the unit label. Default value is 5.

public tickSize: number source

Sets the length of the ticks that are placed every "unit" in pixels. Default value is 12.

public tickSizeSmall: number source

Sets the length of the smaller ticks that are placed every "unit" / 2 in pixels. Default value is 8.

public width: number source

Sets the current width of the axis.

Override:

WorldElement#width

Public Methods

public isPointVisible(x: number, y: number): boolean source

Test if a point is visible given the current position of the axis and the canvas size.

Params:

NameTypeAttributeDescription
x number

Coordinate -x to test.

y number

Coordinate -y to test.

Return:

boolean

True if the point is visible, false otherwise.

Private Methods

private draw() source

Main draw function for the axis called by the World automatically. Since the axis is prerendered, this function handles the toggling between the renderer and the canvas.

private drawAxis() source

Draws the axis onto the selected canvas (renderer by default). First, the dimension of the axis are calculated in order for the axis to do not extend more than the visible dimensions of the canvas. With that, a grid is drawn and finally the -x and -y axes are drawn.

private isMouseOver(): boolean source

Tests if the mouse is over the axis. If the axis is enabled it will return true, since at all moments the mouse is over the axis.

Override:

WorldElement#isMouseOver

Return:

boolean

True if the axis is enabled, false otherwise.

private resize() source

Updates the dimensions of the axis when the world gets resized.

Override:

WorldElement#resize