1.0.0 • Published 9 years ago

graphlib-json-graph v1.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
9 years ago

graphlib-json-graph

Converts json-graph definitions into graphlib graphs.

npm install --save graphlib-json-graph

Example

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"}

API

The module exports one function: toGraph(graphDefinition).

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 JSON

Testing

Is based on mochajs

  • Clone the repo
  • npm install
  • npm test

Contributing

Feel free to raise an issue or submit a pull request

In terms of styling, please use tabs for indentation