Converts json-graph definitions into graphlib graphs.
npm install graphlib-json-graph```
npm install --save graphlib-json-graph
`javascript
var toGraph = require("graphlib-json-graph");
var graphDefinition = {
graph: {
label: "Example graph",
nodes: [{
id: "1"
}, {
id: "2"
}],
edges: [{
id: "e1",
directed: true,
source: "1",
target: "2"
}]
}
};
var graph = toGraph(graphDefinition);
graph.nodes(); // ["1", "2"]
graph.edges(); // {v: "1", w: "2"}
`
.graphDefinition is supposed to be an object that conforms with the json graph specification.The function returns either one, or a list of graphlib graphs.
The distinction is based on whether you have a
graphs property or a graph property.Notes
- The graph is set to be a multigraph by default to support multiple edges that point to the same nodes
- 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
- the labels for the nodes and edges in the graph are set to the objects in the definition JSONTesting
Is based on mochajs
- Clone the repo
- npm install
- npm test`Feel free to raise an issue or submit a pull request
In terms of styling, please use tabs for indentation