Published
Edited
Feb 8, 2019
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
// Create a new directed graph
graph = {
const g = new dagre.graphlib.Graph();

// Set an object for the graph label
g.setGraph({});

// Default to assigning a new object as a label for each new edge.
g.setDefaultEdgeLabel(function() { return {}; });

// Add nodes to the graph. The first argument is the node id. The second is
// metadata about the node. In this case we're going to add labels to each of
// our nodes.
g.setNode("kspacey", { label: "Kevin Spacey", width: 144, height: 100 });
g.setNode("rwright", { label: "Robin Wright", width: 144, height: 100 });
g.setNode("bpitt", { label: "Brad Pitt", width: 108, height: 100 });
g.setNode("hford", { label: "Harrison Ford", width: 168, height: 100 });
g.setNode("sweaver", { label: "Sigourney Weaver", width: 168, height: 100 });
g.setNode("kbacon", { label: "Kevin Bacon", width: 121, height: 100 });

// Add edges to the graph.
g.setEdge("kspacey", "rwright");
g.setEdge("rwright", "kbacon");
g.setEdge("bpitt", "kbacon");
g.setEdge("hford", "sweaver");
g.setEdge("sweaver", "kbacon");
return g;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more