Published
Edited
May 14, 2018
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
// Create the input graph
var g = new dagreD3.graphlib.Graph({compound:true})
.setGraph({})
.setDefaultEdgeLabel(function() { return {}; });

// Here we're setting the nodes
g.setNode('a', {label: 'A'});
g.setNode('b', {label: 'B'});
g.setNode('c', {label: 'C'});
g.setNode('d', {label: 'D'});
g.setNode('e', {label: 'E'});
g.setNode('f', {label: 'F'});
g.setNode('g', {label: 'G'});
g.setNode('group', {label: 'Group', clusterLabelPos: 'top', style: 'fill: #d3d7e8'});
g.setNode('top_group', {label: 'Top Group', clusterLabelPos: 'bottom', style: 'fill: #ffd47f'});
g.setNode('bottom_group', {label: 'Bottom Group', style: 'fill: #5f9488'});

// Set the parents to define which nodes belong to which cluster
g.setParent('top_group', 'group');
g.setParent('bottom_group', 'group');
g.setParent('b', 'top_group');
g.setParent('c', 'bottom_group');
g.setParent('d', 'bottom_group');
g.setParent('e', 'bottom_group');
g.setParent('f', 'bottom_group');

// Set up edges, no special attributes.
g.setEdge('a', 'b');
g.setEdge('b', 'c');
g.setEdge('b', 'd');
g.setEdge('b', 'e');
g.setEdge('b', 'f');
g.setEdge('b', 'g');

g.nodes().forEach(function(v) {
var node = g.node(v);
// Round the corners of the nodes
node.rx = node.ry = 5;
});


// Create the renderer
var render = new dagreD3.render();

// Set up an SVG group so that we can translate the final graph.
var svg = d3.select("svg"),
svgGroup = svg.append("g");

// Run the renderer. This is what draws the final graph.
render(d3.select("svg g"), g);

}
Insert cell
demo = {
var bodyElem = d3.select('body'),
jsElem = d3.select('#js'),
jsPanel = bodyElem.append('div').attr('id', 'jsPanel');

function setupPanel(panel, elem, title) {
panel.append('h2').text(title);
return panel.append('pre').append('code').text(elem.html().trim());
}

var hljsRoot = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1';

bodyElem.append('link')
.attr('rel', 'stylesheet')
.attr('href', hljsRoot + '/styles/xcode.min.css');
bodyElem.append('script')
.attr('src', hljsRoot + '/highlight.min.js')
.on('load', function() {
});
}
Insert cell
Insert cell
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