Graph
Extends:
A Graph Box allow for Plot elements to be displayed in the box using a different scale to the main axis in the world. A Graph object is created by calling the method Box.addGraph on the parent Box.
Constructor Summary
| Public Constructor | ||
| public |
constructor(box: Box, width: number, height: number, opts: object) |
|
Member Summary
| Public Members | ||
| public |
Axis object used to draw the graph axis. |
|
| public |
Array that stores the position of the axis. |
|
| public |
Sets the parent box where te Graph will be placed. |
|
| public |
Context of the cavas where the Graph is drawn. |
|
| public |
Sets the height of the Graph in pixels. |
|
| public |
Flag for enabling the display of the plot's legend. Usually turned on when more than one plot is being displayed. Default value is false. |
|
| public |
Sets the padding in pixels that the graph has. |
|
| public |
Array containing the plots displayed on the graph. |
|
| public |
Scale object for the -x axis. |
|
| public |
Scale object for the -y axis. |
|
| public |
Sets the title for the graph. |
|
| public |
Sets the width of the Graph in pixels. |
|
| public |
Sets the label for the -x axis. |
|
| public |
Sets the label for the -y axis. |
|
Method Summary
| Public Methods | ||
| public |
Adds a Plot to the graph. |
|
| public |
Controls if the legens are displayed. |
|
| public |
setAxisPosition(xPos: string, yPos: string) Sets the origin of the axis. |
|
| public |
setDimensions(width: number, height: number) Change the dimensions of the Graph object. |
|
| public |
Sets the labels for the graph. |
|
| public |
setPadding(top: number, right: number, bottom: number, left: number) Sets the padding of the Graph object. |
|
| Private Methods | ||
| private |
debug() Debug function used to draw a box around the dimensions of the Graph object. |
|
| private |
draw() Draw function for the Graph and Plots called by the parent box. |
|
| private |
Calculates the dimensions of the axis based on the total Graph dimensions and the padding set. |
|
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(box: Box, width: number, height: number, opts: object) source
Override:
WorldElement#constructorParams:
| Name | Type | Attribute | Description |
| box | Box | Parent box. |
|
| width | number | Width of the graph in pixels. |
|
| height | number | Height of the graph in pixels. |
|
| opts | object |
|
Object that contains valid Graph 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 axisPosition: string[] source
Array that stores the position of the axis. See Graph.setAxisPosition for more details. Default value is ["left", "bottom"].
public ctx: object source
Context of the cavas where the Graph is drawn. The canvas is saved in order for the plots to be able to find it, since the parent of the Plot is this object.
public legends_enabled: boolean source
Flag for enabling the display of the plot's legend. Usually turned on when more than one plot is being displayed. Default value is false.
public padding: object source
Sets the padding in pixels that the graph has. The padding is used to display the title, x label, and y label. The padding is then adjusted depending on the value of Graph.legends_enabled to accomodate the display of the legends.
Public Methods
public addPlot(opts: object): Plot source
Adds a Plot to the graph.
Params:
| Name | Type | Attribute | Description |
| opts | object | Object that contains valid Plot 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 legends(state: boolean) source
Controls if the legens are displayed. If true, then the padding is adjusted to make space for it.
Params:
| Name | Type | Attribute | Description |
| state | boolean | Desired state for the legends. |
public setAxisPosition(xPos: string, yPos: string) source
Sets the origin of the axis. The -x axis has the following position options: center, right, left. The -y axis has the following position options: center, top, bottom.
public setDimensions(width: number, height: number) source
Change the dimensions of the Graph object.
public setLabels(title: string, xlabel: string, ylabel: string) source
Sets the labels for the graph. Usually the graph title is left blank, and the box's title is used as title.
public setPadding(top: number, right: number, bottom: number, left: number) source
Sets the padding of the Graph object.
Private Methods
private debug() source
Debug function used to draw a box around the dimensions of the Graph object. It also draws boxes around the padding sections with different fill colors in order to distinguish between them. The boxes are only drawn if the parent box has the flag Box.debug enabled.
private setAxisDimensions() source
Calculates the dimensions of the axis based on the total Graph dimensions and the padding set. Then the calculated dimensions are set to the axis.