Helpers.js

Helpers are objects that contain rendering primitives (like rectangles, ellipses, etc), for plotting nodes and edges.  Helpers also contain implementations of the contains method, a method returning a boolean indicating whether the mouse position is over the rendered shape.

Helpers are very useful when implementing new NodeTypes, since you can access them through this.nodeHelper and this.edgeHelper Graph.Plot properties, providing you with simple primitives and mouse-position check functions.

Example

//implement a new node type
$jit.Viz.Plot.NodeTypes.implement({
  'customNodeType': {
    'render': function(node, canvas) {
      this.nodeHelper.circle.render ...
    },
    'contains': function(node, pos) {
      this.nodeHelper.circle.contains ...
    }
  }
});
//implement an edge type
$jit.Viz.Plot.EdgeTypes.implement({
  'customNodeType': {
    'render': function(node, canvas) {
      this.edgeHelper.circle.render ...
    },
    //optional
    'contains': function(node, pos) {
      this.edgeHelper.circle.contains ...
    }
  }
});
Summary
Helpers.jsHelpers are objects that contain rendering primitives (like rectangles, ellipses, etc), for plotting nodes and edges.
NodeHelperContains rendering and other type of primitives for simple shapes.
NodeHelper.circle
Functions
renderRenders a circle into the canvas.
containsReturns true if pos is contained in the area of the shape.
NodeHelper.ellipse
Functions
renderRenders an ellipse into the canvas.
containsReturns true if pos is contained in the area of the shape.
NodeHelper.square
Functions
renderRenders a square into the canvas.
containsReturns true if pos is contained in the area of the shape.
NodeHelper.rectangle
Functions
renderRenders a rectangle into the canvas.
containsReturns true if pos is contained in the area of the shape.
NodeHelper.triangle
Functions
renderRenders a triangle into the canvas.
containsReturns true if pos is contained in the area of the shape.
NodeHelper.star
Functions
renderRenders a star (concave decagon) into the canvas.
containsReturns true if pos is contained in the area of the shape.
EdgeHelperContains rendering primitives for simple edge shapes.
EdgeHelper.line
Functions
renderRenders a line into the canvas.
containsReturns true if pos is contained in the area of the shape.
EdgeHelper.arrow
Functions
renderRenders an arrow into the canvas.
containsReturns true if pos is contained in the area of the shape.
EdgeHelper.hyperline
Functions
renderRenders a hyperline into the canvas.
containsNot Implemented

NodeHelper

Contains rendering and other type of primitives for simple shapes.

NodeHelper.circle

Summary
Functions
renderRenders a circle into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
radius,
canvas)

Renders a circle into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the circle.
radius(number) The radius of the circle to be rendered.
canvas(object) A Canvas instance.

Example

NodeHelper.circle.render('fill', { x: 10, y: 30 }, 30, viz.canvas);

contains

'contains': function(npos,
pos,
radius)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
radius(number) The radius of the rendered circle.

Example

NodeHelper.circle.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30); //true

NodeHelper.ellipse

Summary
Functions
renderRenders an ellipse into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
width,
height,
canvas)

Renders an ellipse into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the ellipse.
width(number) The width of the ellipse.
height(number) The height of the ellipse.
canvas(object) A Canvas instance.

Example

NodeHelper.ellipse.render('fill', { x: 10, y: 30 }, 30, 40, viz.canvas);

contains

'contains': function(npos,
pos,
width,
height)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
width(number) The width of the rendered ellipse.
height(number) The height of the rendered ellipse.

Example

NodeHelper.ellipse.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30, 40);

NodeHelper.square

Summary
Functions
renderRenders a square into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
dim,
canvas)

Renders a square into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the square.
dim(number) The radius (or half-diameter) of the square.
canvas(object) A Canvas instance.

Example

NodeHelper.square.render('stroke', { x: 10, y: 30 }, 40, viz.canvas);

contains

'contains': function(npos,
pos,
dim)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
dim(number) The radius (or half-diameter) of the square.

Example

NodeHelper.square.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30);

NodeHelper.rectangle

Summary
Functions
renderRenders a rectangle into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
width,
height,
canvas)

Renders a rectangle into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the rectangle.
width(number) The width of the rectangle.
height(number) The height of the rectangle.
canvas(object) A Canvas instance.

Example

NodeHelper.rectangle.render('fill', { x: 10, y: 30 }, 30, 40, viz.canvas);

contains

'contains': function(npos,
pos,
width,
height)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
width(number) The width of the rendered rectangle.
height(number) The height of the rendered rectangle.

Example

NodeHelper.rectangle.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30, 40);

NodeHelper.triangle

Summary
Functions
renderRenders a triangle into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
dim,
canvas)

Renders a triangle into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the triangle.
dim(number) Half the base and half the height of the triangle.
canvas(object) A Canvas instance.

Example

NodeHelper.triangle.render('stroke', { x: 10, y: 30 }, 40, viz.canvas);

contains

'contains': function(npos,
pos,
dim)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
dim(number) Half the base and half the height of the triangle.

Example

NodeHelper.triangle.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30);

NodeHelper.star

Summary
Functions
renderRenders a star (concave decagon) into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(type,
pos,
dim,
canvas)

Renders a star (concave decagon) into the canvas.

Parameters

type(string) Possible options are ‘fill’ or ‘stroke’.
pos(object) An x, y object with the position of the center of the star.
dim(number) The length of a side of a concave decagon.
canvas(object) A Canvas instance.

Example

NodeHelper.star.render('stroke', { x: 10, y: 30 }, 40, viz.canvas);

contains

'contains': function(npos,
pos,
dim)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

npos(object) An x, y object with the Graph.Node position.
pos(object) An x, y object with the position to check.
dim(number) The length of a side of a concave decagon.

Example

NodeHelper.star.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, 30);

EdgeHelper

Contains rendering primitives for simple edge shapes.

EdgeHelper.line

Summary
Functions
renderRenders a line into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(from,
to,
canvas)

Renders a line into the canvas.

Parameters

from(object) An x, y object with the starting position of the line.
to(object) An x, y object with the ending position of the line.
canvas(object) A Canvas instance.

Example

EdgeHelper.line.render({ x: 10, y: 30 }, { x: 10, y: 50 }, viz.canvas);

contains

'contains': function(posFrom,
posTo,
pos,
epsilon)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

posFrom(object) An x, y object with a Graph.Node position.
posTo(object) An x, y object with a Graph.Node position.
pos(object) An x, y object with the position to check.
epsilon(number) The dimension of the shape.

Example

EdgeHelper.line.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, { x: 15, y: 35 }, 30);

EdgeHelper.arrow

Summary
Functions
renderRenders an arrow into the canvas.
containsReturns true if pos is contained in the area of the shape.

Functions

render

'render': function(from,
to,
dim,
swap,
canvas)

Renders an arrow into the canvas.

Parameters

from(object) An x, y object with the starting position of the arrow.
to(object) An x, y object with the ending position of the arrow.
dim(number) The dimension of the arrow.
swap(boolean) Whether to set the arrow pointing to the starting position or the ending position.
canvas(object) A Canvas instance.

Example

EdgeHelper.arrow.render({ x: 10, y: 30 }, { x: 10, y: 50 }, 13, false, viz.canvas);

contains

'contains': function(posFrom,
posTo,
pos,
epsilon)

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

posFrom(object) An x, y object with a Graph.Node position.
posTo(object) An x, y object with a Graph.Node position.
pos(object) An x, y object with the position to check.
epsilon(number) The dimension of the shape.

Example

EdgeHelper.arrow.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, { x: 15, y: 35 }, 30);

EdgeHelper.hyperline

Summary
Functions
renderRenders a hyperline into the canvas.
containsNot Implemented

Functions

render

'render': function(from,
to,
r,
canvas)

Renders a hyperline into the canvas.  A hyperline are the lines drawn for the Hypertree visualization.

Parameters

from(object) An x, y object with the starting position of the hyperline.  x and y must belong to [0, 1).
to(object) An x, y object with the ending position of the hyperline.  x and y must belong to [0, 1).
r(number) The scaling factor.
canvas(object) A Canvas instance.

Example

EdgeHelper.hyperline.render({ x: 10, y: 30 }, { x: 10, y: 50 }, 100, viz.canvas);

contains

Not Implemented

Returns true if pos is contained in the area of the shape.  Returns false otherwise.

Parameters

posFrom(object) An x, y object with a Graph.Node position.
posTo(object) An x, y object with a Graph.Node position.
pos(object) An x, y object with the position to check.
epsilon(number) The dimension of the shape.

Example

EdgeHelper.hyperline.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, { x: 15, y: 35 }, 30);
'render': function(type,
pos,
radius,
canvas)
Renders a circle into the canvas.
'contains': function(npos,
pos,
radius)
Returns true if pos is contained in the area of the shape.
'render': function(type,
pos,
width,
height,
canvas)
Renders an ellipse into the canvas.
'contains': function(npos,
pos,
width,
height)
Returns true if pos is contained in the area of the shape.
'render': function(type,
pos,
dim,
canvas)
Renders a square into the canvas.
'contains': function(npos,
pos,
dim)
Returns true if pos is contained in the area of the shape.
'render': function(type,
pos,
width,
height,
canvas)
Renders a rectangle into the canvas.
'contains': function(npos,
pos,
width,
height)
Returns true if pos is contained in the area of the shape.
'render': function(type,
pos,
dim,
canvas)
Renders a triangle into the canvas.
'contains': function(npos,
pos,
dim)
Returns true if pos is contained in the area of the shape.
'render': function(type,
pos,
dim,
canvas)
Renders a star (concave decagon) into the canvas.
'contains': function(npos,
pos,
dim)
Returns true if pos is contained in the area of the shape.
'render': function(from,
to,
canvas)
Renders a line into the canvas.
'contains': function(posFrom,
posTo,
pos,
epsilon)
Returns true if pos is contained in the area of the shape.
'render': function(from,
to,
dim,
swap,
canvas)
Renders an arrow into the canvas.
'contains': function(posFrom,
posTo,
pos,
epsilon)
Returns true if pos is contained in the area of the shape.
'render': function(from,
to,
r,
canvas)
Renders a hyperline into the canvas.
Graph rendering and animation methods.
A canvas widget used by all visualizations.
A Graph node.
A Hyperbolic Tree/Graph visualization.
Close