Home Reference Source
import DataCursor from 'newton-lib/src/elements/DataCursor.js'
public class | source

DataCursor

Extends:

WorldElement → DataCursor

The DataCursor class is used to add data cursors to plots. It works with plots added to Graph and World objects.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Object that contains info about the closest point to the cursor.

public

Sets the color of the data cursor box.

public

Updates the data cursor every frame.

public

Sets the cursor that appears when hovering a point in a plot.

public

Sets the radius of the cursor.

public

Flag for allowing the element to be dragged around.

public

plots: [Plot]

Array with Plot elements that can have data cursors.

Method Summary

Public Methods
public

add(args: ...*)

public

remove(args: ...*)

Private Methods
private

draw()

Draws the data cursor.

private

Tests if the mouse is over any plot.

private

isMouseOverPlot(plot: *): *

Determines which is the closest point to the pointer.

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(opts: object) source

Override:

WorldElement#constructor

Params:

NameTypeAttributeDescription
opts object
  • optional

Object that contains valid DataCursor 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 closest: object source

Object that contains info about the closest point to the cursor.

Properties:

NameTypeAttributeDescription
Squared distance

distance to the closest point.

-x px

coordinate in pixels, referenced to the main axis.

-y py

coordinate in pixels, referenced to the main axis.

Label label

with the -x and -y coordinates to be displayed in the data cursor.

Plot's color

color.

public color: object source

Sets the color of the data cursor box. The color must have the format as in BOX_COLORS. The default value is BOX_COLORS.BLUE.

Override:

WorldElement#color

Properties:

NameTypeAttributeDescription
BACKGROUND string

Background color.

BORDER string

Border color.

public constant: boolean source

Updates the data cursor every frame.

public cursor: string source

Sets the cursor that appears when hovering a point in a plot.

Override:

WorldElement#cursor

public cursorRadius: number source

Sets the radius of the cursor. Default value is 4.

public isDraggable: boolean source

Flag for allowing the element to be dragged around. Must be set to true, in order for the cursor to be changed.

Override:

WorldElement#isDraggable

public plots: [Plot] source

Array with Plot elements that can have data cursors.

Public Methods

public add(args: ...*) source

Params:

NameTypeAttributeDescription
args ...*

public remove(args: ...*) source

Params:

NameTypeAttributeDescription
args ...*

Private Methods

private draw() source

Draws the data cursor.

private isMouseOver(): boolean source

Tests if the mouse is over any plot.

Override:

WorldElement#isMouseOver

Return:

boolean

Returns true if the pointer is over any plot.

private isMouseOverPlot(plot: *): * source

Determines which is the closest point to the pointer.

Params:

NameTypeAttributeDescription
plot *

Return:

*