Skip to content

Commit 28d0ac2

Browse files
RangerMauveRangerMauve
authored andcommitted
Added docs to README
1 parent 728a043 commit 28d0ac2

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,60 @@
11
# graphlib-json-graph
22
Converts json-graph definitions into graphlib graphs.
33

4-
**Note: This is a work in progress**
4+
```
5+
npm install --save graphlib-json-graph
6+
```
7+
8+
## Example
9+
10+
```javascript
11+
var toGraph = require("graphlib-json-graph");
12+
13+
var graphDefinition = {
14+
graph: {
15+
label: "Example graph",
16+
nodes: [{
17+
id: "1"
18+
}, {
19+
id: "2"
20+
}],
21+
edges: [{
22+
id: "e1",
23+
directed: true,
24+
source: "1",
25+
target: "2"
26+
}]
27+
}
28+
};
29+
30+
var graph = toGraph(graphDefinition);
31+
32+
graph.nodes(); // ["1", "2"]
33+
graph.edges(); // {v: "1", w: "2"}
34+
```
35+
36+
## API
37+
The module exports one function: `toGraph(graphDefinition)`.
38+
39+
`graphDefinition` is supposed to be an object that conforms with the [json graph specification](https://github.com/jsongraph/json-graph-specification#graphs-object).
40+
41+
The function returns either one, or a list of [graphlib graphs](https://github.com/cpettitt/graphlib/wiki).
42+
43+
The distinction is based on whether you have a `graphs` property or a `graph` property.
44+
45+
## Notes
46+
- The graph is set to be a `multigraph` by default to support multiple edges that point to the same nodes
47+
- If you do have multiple edges that connect the same nodes, you must provide an `id` property for them so that you can [differentiate them by name](https://github.com/cpettitt/graphlib/wiki/API-Reference#multigraphs)
48+
- the `labels` for the nodes and edges in the graph are set to the objects in the definition JSON
49+
50+
## Testing
51+
Is based on [mochajs](http://mochajs.org/)
52+
- Clone the repo
53+
- `npm install`
54+
- `npm test`
55+
56+
## Contributing
57+
58+
Feel free to [raise an issue](https://github.com/jsongraph/graphlib-json-graph/issues) or [submit a pull request](https://github.com/jsongraph/graphlib-json-graph/pulls)
59+
60+
In terms of styling, please use tabs for indentation

0 commit comments

Comments
 (0)