Axis
Extends:
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 |
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 |
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 |
isPointVisible(x: number, y: number): boolean 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 |
drawAxis() 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 |
addPosition(x: number, y: number) 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 |
setPosition(x: number, y: number) Sets the position of the element. |
|
public |
Sets the scale of the element. |
|
public |
Sets the z-index of the element. |
|
private |
resize() Function called when the canvas gets resized. |
|
private |
Sets the world object where element will be drawn. |
|
private |
Sets the element as a topmost element. |
Public Constructors
public constructor(width: number, height: number, opts: object) source
Override:
WorldElement#constructorParams:
Name | Type | Attribute | Description |
width | number |
|
Initial width of the axis. |
height | number |
|
Initial height of the canvas. |
opts | object |
|
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#colorpublic cursor: string source
Sets the cursor style when the mouse is over the axis. Default value is CURSOR.MOVE.
Override:
WorldElement#cursorpublic 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 isDraggable: boolean source
Flag for allowing the axis to be dragged around. Default value is true.
Override:
WorldElement#isDraggablepublic 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#mouseMoveStylepublic 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#rendererpublic 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 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.
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#isMouseOverprivate resize() source
Updates the dimensions of the axis when the world gets resized.