🎉 JointJS has new documentation! ðŸ¥³

JointJS+ toAdjacencyList

graphUtils.toAdjacencyList


toAdjacencyList(graph)

Converts graph to an adjacency list. The method returns an object with element ids as properties and an array of connected element ids as values (the array includes indirect connections i.e. the path between connected elements includes a link-link connection).

Example:

const graph = new joint.dia.Graph;

const a = new joint.shapes.standard.Circle({ id: 'a' });
const b = new joint.shapes.standard.Circle({ id: 'b' });
const c = new joint.shapes.standard.Circle({ id: 'c' });

const ab = new joint.dia.Link({
    id: `a-b`,
    source: { id: 'a' },
    target: { id: 'b' },
});
const bc = new joint.dia.Link({
    id: `b-c`,
    source: { id: 'b' },
    target: { id: 'c' },
});
const indirectLink = new joint.dia.Link({
    id: `indirectLink`,
    source: { id: 'a' },
    target: { id: 'b-c' },
});

graph.addCells(a, b, c, ab, bc, indirectLink);

// Returns an object:
// {
//   "a": ["b", "c"],
//   "b": ["c"],
//   "c": []
// }
joint.graphUtils.toAdjacencyList(graph);