Class: Graph

Psynth. Graph

new Graph(params)

This constructor cannot be directly accessed, but instead should be accessed through the Psynth.createGraph or Psynth.loadGraph methods.
Parameters:
Name Type Description
params object
Properties
Name Type Description
name string The name of this Graph.
filename string The filename of this Graph. Must be unique to your Psynth server. This is assigned by the server.
username string A Psynth username authorized to access the graph.
key string A key which matches the username.
url string The base URL for your Psynth server. e.g. https://psynth.psymphonic.com/
Source:
Example
var g = new Graph({name: 'My Graph', filename: 'b8e1241a-c90c-46ca-a55e-6cbb9145ab19.gt',
                          username: 'myusername', key: 'mykey', url: 'https://psynth.psymphonic.com'}

Members

filename :string

The filename of the graph. Should end in '.gt'
Type:
  • string
Source:

key :string

The key which matches the username.
Type:
  • string
Source:

name :string

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

url :string

The url of your psynth server. e.g. https://psynth.psymphonic.com/
Type:
  • string
Source:

username :string

The username authorized to access the graph.
Type:
  • string
Source:

Methods

addDetail(detail, callback, update) → {Psynth.Detail}

Adds a Detail object to the graph and returns it.
Parameters:
Name Type Argument Default Description
detail Psynth.Detail | Object Either a Detail object, or the parameters with which to construct one.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
true Whether or not to immediately enqueue the task to send to the server.
Source:
Returns:
Type
Psynth.Detail
Example
var dDef = {
             anchor_uid: 'ec918bb1-7463-427f-919f-26fbe3760b6a',
             anchor_type: 'Node',
             type: 'link',
             x: g.node('ec918bb1-7463-427f-919f-26fbe3760b6a').x+50,
             y: g.node('ec918bb1-7463-427f-919f-26fbe3760b6a').y+50,
             content: 'http://psymphonic.com'
           };
function MyFunction(response)
{
     console.log(response);
}
var d = g.addDetail(dDef, MyFunction);
console.log(d.anchor().name, d.content);
Adds a Link to the graph, and returns the Link.
Parameters:
Name Type Argument Default Description
link Psynth.Link | object Either a Link object, or the parameters with which to construct one.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
true Whether or not to immediately enqueue this task to send to the server.
Source:
Returns:
Type
Psynth.Link
Example
var linkDef = {origin_uid: 'b8e1241a-c90c-46ca-a55e-6cbb9145ab19',
                 terminus_uid: 'a287d501-2ee9-42e3-bfbd-2a41dff6ecda', type: 'Nitrogen', value: 14};
function MyFunction(response)
{
     console.log(response);
}
var l = g.addLink(linkDef, MyFunction);
console.log(l.origin().name, l.terminus().name);

addLinkType(linktype, callback, update) → {Psynth.LinkType}

Adds a LinkType to the Graph, and returns it.
Parameters:
Name Type Argument Default Description
linktype Psynth.LinkType The LinkType object to add.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
true Whether or not to immediate enqueue this task to send to the server.
Source:
Returns:
Type
Psynth.LinkType
Example
function MyFunction(response)
{
     console.log(response);
}
var lt = g.addLinkType(new Psynth.LinkType(), MyFunction)
console.log(lt.name, lt.color);

addNode(node, callback, update) → {Psynth.Node}

This adds a Node to the graph, and returns the Node.
Parameters:
Name Type Argument Default Description
node Psynth.Node | object Can be a Node, or parameters with which to construct a Node object.
callback function <optional>
An optional function to handle the response from the server.
update boolean <optional>
true Whether or not to immediately enqueue this task to send to the server.
Source:
Returns:
Type
Psynth.Node
Example
function MyFunction(response)
{
     console.log(response);
}
var n = g.addNode({name: 'Node 1'}, MyFunction); //n is a Node object
console.log(n.name, n.radius);

detail(uid) → {Psynth.Detail|number}

Returns a Detail by uid. Returns -1 if the Detail does not exist.
Parameters:
Name Type Description
uid string
Source:
Returns:
Type
Psynth.Detail | number
Example
var d = g.detail('d5976550-551c-4489-a777-b8e839c75515');
console.log(d.type, d.content);

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

Returns an array of all Details in the Graph.
Source:
Returns:
Type
Array.<Psynth.Detail>
Example
var theDetails = g.detailList();
for(var i = 0; i < theDetails.length; i++)
{
     console.log(theDetails[i].anchor().name, theDetails[i].anchor_type);
}

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

Returns a uid-indexed collection of all Details in the Graph.
Source:
Returns:
Type
Object.<string, Psynth.Detail>
Example
var theDetails = g.details();
for(var uid in theDetails)
{
     if(theDetails.hasOwnProperty(uid))
     {
         console.log(theDetails[uid].content);
     }
}

draw(callback)

Calculates a layout for the graph, and updates all Node and Detail positions.
Parameters:
Name Type Argument Description
callback function <optional>
An optional function to handle the server response.
Source:
Example
function MyFunction(response)
{
     console.log(response);
}
g.draw(MyFunction);

height() → {number}

Returns the height of the Graph.
Source:
Returns:
Type
number
Example
console.log(g.height());
Returns a Link by uid. Returns -1 if the Link does not exist.
Parameters:
Name Type Description
uid string
Source:
Returns:
Type
Psynth.Link | number
Example
var l = g.link('a287d501-2ee9-42e3-bfbd-2a41dff6ecda');
console.log(l.name, l.type);
Returns an array of all Links in the Graph.
Source:
Returns:
Type
Array.<Psynth.Link>
Example
var theLinks = g.linkList();
for(var i = 0; i < theLinks.length; i++)
{
     console.log(theLinks[i].origin().name, theLinks[i].terminus().name);
}
Returns a uid-indexed collection of all Links in the Graph.
Source:
Returns:
Type
Object.<string, Psynth.Link>
Example
var theLinks = g.links();
for(var uid in theLinks)
{
     if(theLinks.hasOwnProperty(uid))
     {
             var l = theLinks[uid];
             console.log(l.name, l.origin().name);
     }
}

linkType(name) → {Psynth.LinkType|number}

Returns a LinkType by name. Returns -1 if the LinkType does not exist.
Parameters:
Name Type Description
name string
Source:
Returns:
Type
Psynth.LinkType | number
Example
var lt = g.linkType('Nitrogen');
console.log(lt.color, lt.max);

linkTypes() → {Object.<string, Psynth.LinkType>}

Returns a name-indexed collection of LinkTypes.
Source:
Returns:
Type
Object.<string, Psynth.LinkType>
Example
var lt = g.linkTypes();
for(var name in lt)
{
     if(lt.hasOwnProperty(name))
     {
         console.log(lt[name].color);
     }
}

maxX() → {number}

Finds the highest x-value of any Node in the Graph.
Source:
Returns:
Type
number
Example
console.log(g.maxX());

maxY() → {number}

Finds the highest y-value of any Node in the Graph.
Source:
Returns:
Type
number
Example
console.log(g.maxY());

minX() → {number}

Finds the lowest x-value of any Node in the Graph.
Source:
Returns:
Type
number
Example
console.log(g.minX());

minY() → {number}

Finds the lowest y-value of any Node in the Graph.
Source:
Returns:
Type
number
Example
console.log(g.minY());

node(uid) → {Psynth.Node|number}

Returns a Node by uid. Returns -1 if the node does not exist.
Parameters:
Name Type Description
uid string
Source:
Returns:
Type
Psynth.Node | number
Example
var n = g.node('b8e1241a-c90c-46ca-a55e-6cbb9145ab19');
console.log(n.name, n.radius);

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

Returns an array of all Nodes in the graph.
Source:
Returns:
Type
Array.<Psynth.Node>
Example
var theNodes = g.nodeList();
for(var i = 0; i < theNodes.length; i++)
{
     console.log(theNodes[i].name, theNodes[i].radius);
}

nodes() → {Object.<string, Psynth.Node>}

Returns a uid-indexed collection of all Nodes in the graph.
Source:
Returns:
Type
Object.<string, Psynth.Node>
Example
var theNodes = g.nodes();
for(var uid in theNodes)
{
     if(theNodes.hasOwnProperty(uid))
     {
         var n = theNodes[uid] //n is a Node object.
         console.log(n.name, n.radius);
     }
}

publish(callback)

Creates a publicly accessible version of the Graph. Logs the URL where it can be found. It's important to do this after the final draw command is issued.
Parameters:
Name Type Argument Description
callback function <optional>
An optional function to handle the server response.
Source:
Example
g.draw(function(){
     g.publish();
}

queue(q, handler)

All queries should be queued through this function to ensure that they complete in order. Not doing this can result in links trying to attach to non-existent nodes.
Parameters:
Name Type Argument Description
q object The query to be completed.
handler function <optional>
Aan optional function to handle the response from the query.
Source:
Example
g.queue({query: 'drawgraph'}, function(response){console.log(response);});

removeDetail(detail, callback, update)

Removes a Detail from the graph.
Parameters:
Name Type Argument Description
detail Psynth.Detail The Detail to remove.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
Whether or not to immediately enqueue the task to send to the server.
Source:
Example
function MyFunction(response)
{
     console.log(response);
}
g.removeDetail(g.detail('d5976550-551c-4489-a777-b8e839c75515'), MyFunction);
Removes a Link from the Graph.
Parameters:
Name Type Argument Default Description
link Psynth.Link The Link to remove.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
true Whether or not to immediately enqueue this task to send to the server.
Source:
Example
var l = g.link('a287d501-2ee9-42e3-bfbd-2a41dff6ecda');
function MyFunction(response)
{
     console.log(response);
}
g.removeLink(l, MyFunction);

removeNode(node, callback, update)

Removes a Node from the graph.
Parameters:
Name Type Argument Default Description
node Psynth.Node The node to remove.
callback function <optional>
An optional function to handle the server response.
update boolean <optional>
true Whether or not to immediately enqueue this task to send to the server.
Source:
Example
var n = g.node('b8e1241a-c90c-46ca-a55e-6cbb9145ab19');
function MyFunction(response)
{
     console.log(response);
}
g.removeNode(n, MyFunction);

width() → {number}

Returns the width of the Graph.
Source:
Returns:
Type
number
Example
console.log(g.width());