1 | # iper
|
2 |
|
3 | > Hypergraphs for breakfast!
|
4 |
|
5 | [![Node engine](https://img.shields.io/node/v/iper.svg)](https://nodejs.org/en/) [![NPM version](https://badge.fury.io/js/iper.svg)](http://badge.fury.io/js/iper) [![Build Status](https://travis-ci.org/fibo/iper.svg?branch=master)](https://travis-ci.org/fibo/iper?branch=master) [![Dependency Status](https://gemnasium.com/fibo/iper.svg)](https://gemnasium.com/fibo/iper) [![Coverage Status](https://coveralls.io/repos/fibo/iper/badge.svg?branch=master)](https://coveralls.io/r/fibo/iper?branch=master) [![Test page](https://img.shields.io/badge/test-page-blue.svg)](http://g14n.info/iper/test)
|
6 |
|
7 | [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
|
8 |
|
9 | [![NPM](https://nodei.co/npm-dl/iper.png)](https://nodei.co/npm-dl/iper/)
|
10 |
|
11 | ## Installation
|
12 |
|
13 | With [npm](https://npmjs.org/) do
|
14 |
|
15 | ```bash
|
16 | npm install iper
|
17 | ```
|
18 |
|
19 | With [bower](http://bower.io/) do
|
20 |
|
21 | ```bash
|
22 | bower install iper
|
23 | ```
|
24 |
|
25 | ## API
|
26 |
|
27 | ### `new Graph([graph])`
|
28 |
|
29 | > Hypergraph constructor.
|
30 |
|
31 | ```javascript
|
32 | const Graph = require('iper').Graph
|
33 |
|
34 | const graph = new Graph()
|
35 | ```
|
36 |
|
37 | * **@param** `{Object}` [graph]
|
38 | * **@param** `{Object}` [graph.edges]
|
39 | * **@param** `{Object}` [graph.nodes]
|
40 | * **@param** `{Boolean}` [graph.multigraph] can contain duplicated edges
|
41 | * **@param** `{Boolean}` [graph.pseudograph] is a multigraph with loops allowed
|
42 | * **@param** `{Number}` [graph.uniform] all edges has the same cardinality (i.e. number of nodes)
|
43 |
|
44 | ### `graph.addEdge(nodeIds)`
|
45 |
|
46 | > Add an hyperedge that connects given nodeIds.
|
47 |
|
48 | * **@param** `{Array}` nodeIds
|
49 | * **@returns** `{String}` id
|
50 |
|
51 | ### `graph.addNode(data)`
|
52 |
|
53 | > Add a node, containing given data.
|
54 |
|
55 | ```javascript
|
56 | var nodeId = graph.addNode({ label: 'foo' })
|
57 | ```
|
58 |
|
59 | * **@param** `{*}` [data]
|
60 | * **@returns** `{String}` id of the node created
|
61 |
|
62 | ### `graph.degreeOf(nodeId)`
|
63 |
|
64 | > Returns the degree of a node, that is the number of incident edges with loops counted twice.
|
65 |
|
66 | * **@param** `{String}` id
|
67 | * **@returns** `{void}`
|
68 |
|
69 | ### `graph.delEdge(id)`
|
70 |
|
71 | > Delete edge by given id.
|
72 |
|
73 | * **@param** `{String}` id
|
74 | * **@returns** `{void}`
|
75 |
|
76 | ### `graph.delNode(id)`
|
77 |
|
78 | > Delete node by given id.
|
79 |
|
80 | * **@param** `{String}` id
|
81 | * **@returns** `{void}`
|
82 |
|
83 | ### `graph.generateId()`
|
84 |
|
85 | > Returns a random string to be used as id.
|
86 |
|
87 | * **@returns** `{String}`
|
88 |
|
89 | Override this method if you want to customize how ids are generated, for example
|
90 |
|
91 | ```javascript
|
92 | const uniqueid = require('lodash.uniqueid')
|
93 | const Graph = require('iper').Graph
|
94 |
|
95 | class MyGraph extends Graph {
|
96 | generateId () {
|
97 | return uniqueid()
|
98 | }
|
99 | }
|
100 |
|
101 | module.exports = MyGraph
|
102 | ```
|
103 |
|
104 |
|
105 | ### `graph.getRank()`
|
106 |
|
107 | > Returns the max cardinality of any of the edges in the hypergraph.
|
108 |
|
109 | * **@returns** `{Number}`
|
110 |
|
111 | ## License
|
112 |
|
113 | [MIT](http://www.g14n.info/mit-license)
|