Fork me on GitHub

Position

Utility class to compute positioning

Constructor

new Position( )

Methods

(static) {Position} check( Object, Position pos , function callback )

Checks if an object is a position. If not, creates a new Position instance with the ```pos``` object. If a new position is created, ```callback``` is fired with the position as a unique parameter. The return of the function, if not false, should be a ```Position``` instance which serves as the reference position.
Parameters:
Name Type Description
pos Object | Position The position object or the object fed into the constructor
callback function The callback fired if a new position is created
Returns:
{ Position } The resulting position object
Example
Position.check( { x: 1, y: 2 }, function() { return someOtherPosition; } );
 

{Object} compute( Graph graph , AxisX xAxis , AxisY yAxis [ , Serie serie ] )

Computes the position of the position
Parameters:
Name Type Attributes Description
graph Graph The graph for which the position has to be computed
xAxis AxisX The x axis to consider (has to belong to the graph)
yAxis AxisY The y axis to consider (has to belong to the graph)
serie Serie <optional>
For non-existing y value, use a serie to compute it automatically from the serie data
Returns:
{ Object } An object in the format ```{x: xPx, y: yPx}``` containing the position in pixels of the position

{String} getDeltaPx( Number value , Axis Axis )

Computes the value in pixels of an amplitude (or a distance) for a certain axis
Parameters:
Name Type Description
value Number The value in axis unit
Axis Axis The x axis to consider (has to belong to the graph)
Returns:
{ String } The value in pixels, e.g. "20px"

{Number|String} getPx( Number value , Axis axis , Boolean rel )

Computes a value in pixels
Parameters:
Name Type Description
value Number The value in axis unit
axis Axis The x or y axis to consider (has to belong to the graph)
rel Boolean Whether or not the value is a distance
Returns:
{ Number | String } The computed value

{Position} relativeTo( Position pos )

Assigns the current position as relative to another. This is used when a position is used with "dx" or "dy" and not "x" or "y"
Parameters:
Name Type Description
pos Position The reference position
Returns:
{ Position } The current position