Class: Node

Psynth. Node

new Node(params)

Creates a Node Object. While this constructor can be accessed directly, it's easier to use it through Psynth.Graph#addNode. A Node must be added to a Graph to be functional.
Parameters:
Name Type Description
params object
Properties
Name Type Argument Default Description
name string <optional>
Node The name of the Node.
x number <optional>
1 The x-coordinate of the Node.
y number <optional>
1 the y-coordinate of the Node.
shape number | string <optional>
6 The shape of the Node. 0 for circle, 1 for image, otherwise the number of sides. Can also be 'circle','triangle','square','pentagon','hexagon','septagon','octagon'
radius number <optional>
24 The radius of the Node, in Pixels.
color string <optional>
'dynamic' A color string (e.g. #FFFFFF). 'dynamic' will cause the node to color itself responsively with the user selected palette. 'static' will leave a node image's color unaffected. This is displayed as a Photo setting in the GUI.
image string <optional>
'default' A url for an image to display on the Node. Requires a shape of 1.
uid string <optional>
Defaults to global unique id.
Source:
Examples

Adding a node in two steps.

var n = new Psynth.Node({radius: 48, shape: 3});
g.addNode(n);
console.log(n.name, n.color);

A more convenient 1-liner

var n = g.addNode({radius: 48, shape: 3});
console.log(n.name, n.color);

Members

color :string

The color of the node. 'default' will make the node responsive to user palette selection. Otherwise should be in the form of "#FFFFFF"
Type:
  • string
Source:

created :boolean

Identifies whether this node has been created yet in the server.
Type:
  • boolean
Default Value:
  • false
Source:

graph :Psynth.Graph

This is the Graph to which this Node belongs.
Type:
Source:

image :string

A URL for an image to display on the Node. Requires a shape of 1 to display.
Type:
  • string
Source:

name :string

The name of the Node.
Type:
  • string
Source:

radius :number

The radius of the Node, in Pixels.
Type:
  • number
Source:

shape :number

The shape of the Node, in number of sides. 0 for circle, 1 for image. 3+ for n-gon. Although shapes can be instantiated with strings at Node construction, they are stored as numbers for internal use.
Type:
  • number
Source:

uid :string

A unique identifier for this Node. This is what the node is indexed by at Graph#nodes.
Type:
  • string
Source:

x :number

The x-coordinate of the Node, in Pixels. Assumes web-standard grid with (0,0) at (top,left)
Type:
  • number
Source:

y :number

The y-coordinate of the Node, in Pixels. Assumes web-standard grid with (0,0) at (top,left)
Type:
  • number
Source:

Methods

addDetail(detail) → {Psynth.Detail}

Attaches a Detail to this Node, and returns it.
Parameters:
Name Type Description
detail Psynth.Detail | object Either a Detail object, or parameters for the constuction of one.
Source:
Returns:
Type
Psynth.Detail
Example
var d = n.addDetail({content: 'http://psymphonic.com', type: 'link'});
console.log(d.anchor_uid === n.uid)
//true
Returns an array of Links which are connected to this Node.
Source:
Returns:
Type
Array.<Psynth.Link>
Example
var links = n.allLinks();
for(var i = 0; i < links.length; i++)
{
     console.log(links[i].type, links[i].value);
}

allNeighbors() → {Array.<Psynth.Node>}

Returns an array of Nodes which are neighbors of this node.
Source:
Returns:
var nodes = n.allNeighbors(); for(var i = 0; i < nodes.length; i++) { console.log(nodes[i].name, nodes[i].color); }
Type
Array.<Psynth.Node>

detailList() → {Array.<Psynth.Detail>}

Returns an array of Details which are anchored to this Node.
Source:
Returns:
Type
Array.<Psynth.Detail>
Example
var dets = n.detailList();
for(var i = 0; i < dets.length; i++)
{
     console.log(dets[i].content);
}

details() → {Object.<string, Psynth.Detail>}

Returns a uid-indexed collection of Details which are anchored to this Node.
Source:
Returns:
Type
Object.<string, Psynth.Detail>
Example
var dets = n.details();
for(var uid in dets)
{
     if(dets.hasOwnProperty(uid))
     {
         console.log(dets[uid].content);
     }
}
Returns an array of Links which terminate at this Node.
Source:
Returns:
Type
Array.<Psynth.Link>
Example
var links = n.inLinks();
for(var i = 0; i < links.length; i++)
{
     console.log(links[i].type, links[i].value);
}

inNeighbors() → {Array.<Psynth.Node>}

Returns an array of Nodes which are neighbors of this node, by incoming Links
Source:
Returns:
Type
Array.<Psynth.Node>
Example
var nodes = n.inNeighbors();
for(var i = 0; i < nodes.length; i++)
{
     console.log(nodes[i].name, nodes[i].color);
}

object() → {simpleNode}

Formats the node as a JSON-serializable object which contains all necessary information. This is mostly used internally to prepare queries for the server.
Source:
Returns:
Type
simpleNode
Example
var q = n.object();
q.query = "newnode";
g.queue(q);
Returns an array of Links which originate at this Node.
Source:
Returns:
Type
Array.<Psynth.Link>
Example
var links = n.outLinks();
for(var i = 0; i < links.length; i++)
{
     console.log(links[i].type, links[i].value);
}

outNeighbors() → {Array.<Psynth.Node>}

Returns an array of Nodes which are neighbors of this node, by outgoing Links
Source:
Returns:
Type
Array.<Psynth.Node>
Example
var nodes = n.outNeighbors();
for(var i = 0; i < nodes.length; i++)
{
     console.log(nodes[i].name, nodes[i].color);
}

update(callback)

Updates the information for this Node on the server. This allows you to make multiple edits to a node while only making 1 server call.
Parameters:
Name Type Argument Description
callback function <optional>
Source:
Example
n.name = "different name";
n.x += 5;
n.radius +=6;
n.update();