Class: Link

Psynth. Link

Creates a Link Object. Although this constructor can be accessed directly, it's easier to use it through A Link must be added to a [Graph]{@link Psynth.Graph before it is fully functional.
Parameters:
Name Type Description
params object
Properties
Name Type Argument Default Description
name string <optional>
The name of the Link.
type string The LinkType#name of this Link.
value number <optional>
1 The value of this Link.
uid string <optional>
A unique identifier for this link. Defaults to a global unique id.
origin_uid string The Node#uid for the origin Node of this Link.
terminus_uid string The Node#uid for the terminus Node of this Link.
Source:
Examples

Using the constructor directly

var lt = g.addLinkType(new Psynth.LinkType());
var l = new Psynth.Link({origin_uid: n1.uid, terminus_uid: n2.uid, type: lt.name, value: 2});
g.addLink(l);
console.log(l.origin().name, l.terminus().name);

A better 1-liner.

var lt = g.addLinkType(new Psynth.LinkType());
var l = g.addLink({origin_uid: n1.uid, terminus_uid: n2.uid, type: lt.name, value: 2});
console.log(l.origin().name, l.terminus().name);

Members

created :boolean

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

graph :Psynth.Graph

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

name :string

The name of this Link.
Type:
  • string
Source:

origin_uid :string

The Node#uid of the Origin Node.
Type:
  • string
Source:

terminus_uid :string

The Node#uid of the Terminus Node.
Type:
  • string
Source:

type :string

The LinkType#name of this Link.
Type:
  • string
Source:

uid :string

A unique identifier for this Link. This is what is indexed for Graph#links.
Type:
  • string
Source:

value :number

The value of this Link.
Type:
  • number
Source:

Methods

addDetail(detail) → {Psynth.Detail}

Attaches a Detail to this Link, and returns it.
Parameters:
Name Type Description
detail
Source:
Returns:
Type
Psynth.Detail
Example
var d = l.addDetail({content: 'http://psymphonic.com', type: 'link'});
console.log(d.anchor_uid === l.uid)
//true

center() → {Object}

Returns the point at the center of the Link. {x, y}
Source:
Returns:
Type
Object
Example
detail.x = link.center().x+10;

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

Returns an array of Details which are anchored to this Link.
Source:
Returns:
Type
Array.<Psynth.Detail>
Example
var dets = l.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 Link.
Source:
Returns:
Type
Object.<string, Psynth.Detail>
Example
var dets = l.details();
for(var uid in dets)
{
     if(dets.hasOwnProperty(uid))
     {
         console.log(dets[uid].content);
     }
}

linkType() → {Psynth.LinkType|number}

Returns the LinkType object for this Link.
Source:
Returns:
Type
Psynth.LinkType | number
Example
var hue = link.linkType().color;

object() → {simpleLink}

Formats the Link as a JSON-serializable object which contains all necessary information. This is mostly used internally to prepare queries for the server.
Source:
Returns:
Type
simpleLink
Example
var q = l.object();
q.query = "newrel";
g.queue(q);

origin() → {Psynth.Node|number}

Returns the Origin Node, or -1 if the Node is invalid.
Source:
Returns:
Type
Psynth.Node | number
Example
console.log(l.origin().name);

parallel() → {Array.<Psynth.Link>}

Returns an array of Links which are parallel to this one, including this one.
Source:
Returns:
Type
Array.<Psynth.Link>
Example
var p = l.parallel();
for(var i = 0; i < p.length; i++)
{
     console.log(p[i].value, p[i].type);
}

terminus() → {Psynth.Node|number}

Returns the Termins Node, or -1 if the Node is invalid.
Source:
Returns:
Type
Psynth.Node | number
Example
console.log(l.terminus().name);

update(callback)

Updates the information for this Link on the server. This allows you to make multiple edits to a Link while only making 1 server call.
Parameters:
Name Type Argument Description
callback function <optional>
An optional function to handle the server response.
Source:
Example
l.name = "Best Friends";
l.value = 8;
l.update();