new Link(params)
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
|
Examples
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);
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
-
graph :Psynth.Graph
-
This is the Graph to which this Link belongs.
Type:
-
name :string
-
The name of this Link.
Type:
- string
-
origin_uid :string
-
The Node#uid of the Origin Node.
Type:
- string
-
terminus_uid :string
-
The Node#uid of the Terminus Node.
Type:
- string
-
type :string
-
The LinkType#name of this Link.
Type:
- string
-
uid :string
-
A unique identifier for this Link. This is what is indexed for Graph#links.
Type:
- string
-
value :number
-
The value of this Link.
Type:
- number
Methods
-
addDetail(detail) → {Psynth.Detail}
-
Attaches a Detail to this Link, and returns it.
Parameters:
Name Type Description detail
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}
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.
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.
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.
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.
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.
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.
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.
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. Example
l.name = "Best Friends"; l.value = 8; l.update();