UNPKG

958 BJavaScriptView Raw
1
2module.exports = function () {
3
4// example dependencies
5
6var iper = require('iper');
7
8var IperGraph = iper.IperGraph;
9
10// Create an empty graph
11var graph = new IperGraph();
12
13// Use #createNode() to add nodes to the graph.
14//
15// For example, this will create an empty node.
16graph.createNode();
17
18// You can pass any kind of data
19graph.createNode(0);
20graph.createNode('foo');
21graph.createNode(['bar']);
22graph.createNode({quz:'quuz'});
23graph.createNode(
24 function hello() {
25 console.log('Hello iper!');
26 }
27);
28
29// Every node will be given a unique identifier, that is returned by #createNode() as a convenience.
30// Lets create two nodes with an empty array as data,
31// and lets store ids to use them later.
32var id1 = graph.createNode([]);
33var id2 = graph.createNode([]);
34
35// Now we can use id1 and id2 to refer to the nodes,
36// for example we can create an edge joining the nodes.
37graph.createEdge([id1, id2]);
38
39};
40