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
|
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
-
created :boolean
-
Identifies whether this node has been created yet in the server.
Type:
- boolean
-
graph :Psynth.Graph
-
This is the Graph to which this Node belongs.
Type:
-
image :string
-
A URL for an image to display on the Node. Requires a shape of 1 to display.
Type:
- string
-
name :string
-
The name of the Node.
Type:
- string
-
radius :number
-
The radius of the Node, in Pixels.
Type:
- number
-
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
-
uid :string
-
A unique identifier for this Node. This is what the node is indexed by at Graph#nodes.
Type:
- string
-
x :number
-
The x-coordinate of the Node, in Pixels. Assumes web-standard grid with (0,0) at (top,left)
Type:
- number
-
y :number
-
The y-coordinate of the Node, in Pixels. Assumes web-standard grid with (0,0) at (top,left)
Type:
- number
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. Returns:
- Type
- Psynth.Detail
Example
var d = n.addDetail({content: 'http://psymphonic.com', type: 'link'}); console.log(d.anchor_uid === n.uid) //true
-
allLinks() → {Array.<Psynth.Link>}
-
Returns an array of Links which are connected to this Node.
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.
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.
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.
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); } }
-
inLinks() → {Array.<Psynth.Link>}
-
Returns an array of Links which terminate at this Node.
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:
- 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.
Returns:
- Type
- simpleNode
Example
var q = n.object(); q.query = "newnode"; g.queue(q);
-
outLinks() → {Array.<Psynth.Link>}
-
Returns an array of Links which originate at this Node.
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:
- 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>
Example
n.name = "different name"; n.x += 5; n.radius +=6; n.update();