View on GitHub

PsynthJS

An open-source javascript library for generating graphs in Psymphonic Psynth.

Download this project as a .zip file Download this project as a tar.gz file

PsynthJS

PsynthJS is a Javascript library for programmatically generating graphs in Psymphonic Psynth. It requires jQuery when used in the browser, but not if used with Node. It is published under the MIT license, and you are encouraged to do anything you want with it, for fun and profit.

Installation

In html

<script src={{PATH TO JQUERY}}></script>
<script src="js/psynth.js"></script>

In bower:

bower install psynthjs

In npm:

npm install psynthjs

Quickstart

// Include the Psynth package if using node.
var Psynth = require('psynthjs');

// A shortcut function to get random integers.
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Define the Graph properties
var graphInfo = {name: 'test map',
                 username: 'myusername',
                 key: 'myapikey',
                 url: 'https://psynth.psymphonic.com/'};

// Create the Graph
Psynth.createGraph(graphInfo, function(g)
{
    // Create 10 Nodes.
    for(var i = 0; i < 10; i++)
    {
        g.addNode({name: 'Node '+i});
    }

    // Grab a list of all the Nodes.
    var ns = g.nodeList();

    // Create a default LinkType
    var lt = g.addLinkType(new Psynth.LinkType());

    // Create 30 random Links
    for(var i = 0; i < 30; i++)
    {
        var o = getRandomInt(0, ns.length-1);
        var t = getRandomInt(0, ns.length-1);
        while(t === o)
        {
            t = getRandomInt(0, ns.length-1);
        }
        g.addLink({name: 'Link '+i, origin_uid: ns[o].uid, terminus_uid: ns[t].uid, type: lt.name, value: getRandomInt(1, lt.max)});
    }

    // Grab a list of all the Links
    var ls = g.linkList();

    // Add 3 Details to each Node
    for(var i = 0; i < ns.length; i++)
    {
        for(var j = 0; j < 3; j++)
        {
            ns[i].addDetail({content: 'http://psymphonic.com', type: 'link'});
        }
    }

    // Add 3 Details to each Link
    for(var i = 0; i < ls.length; i++)
    {
        for(var j = 0; j < 3; j++)
        {
            ls[i].addDetail({content: 'http://psymphonic.com', type: 'link'});
        }
    }

    // Calculate a layout for the Graph.
    g.draw();
});

Documentation

Check out the docs.

Authors and Contributors

This project is supported by Psymphonic.