1 |
|
2 | module.exports = function () {
|
3 |
|
4 | // example dependencies
|
5 |
|
6 | var iper = require('iper');
|
7 |
|
8 | var IperGraph = iper.IperGraph;
|
9 |
|
10 | // Create an empty graph
|
11 | var graph = new IperGraph();
|
12 |
|
13 | // Use #createNode() to add nodes to the graph.
|
14 | //
|
15 | // For example, this will create an empty node.
|
16 | graph.createNode();
|
17 |
|
18 | // You can pass any kind of data
|
19 | graph.createNode(0);
|
20 | graph.createNode('foo');
|
21 | graph.createNode(['bar']);
|
22 | graph.createNode({quz:'quuz'});
|
23 | graph.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.
|
32 | var id1 = graph.createNode([]);
|
33 | var 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.
|
37 | graph.createEdge([id1, id2]);
|
38 |
|
39 | };
|
40 |
|