| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <!doctype html>
- <meta charset="utf-8">
- <title>Dagre D3 Demo: Clusters</title>
- <link rel="stylesheet" href="demo.css">
- <script src="../../node_modules/graphlibrary/dist/graphlib.js"></script>
- <script src="../../node_modules/d3/build/d3.js"></script>
- <script src="../dagre-d3.js"></script>
- <h1>Dagre D3 Demo: Clusters</h1>
- <style id="css">
- .clusters rect {
- fill: #00ffd0;
- stroke: #999;
- stroke-width: 1.5px;
- }
- text {
- font-weight: 300;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;
- font-size: 14px;
- }
- .node rect {
- stroke: #999;
- fill: #fff;
- stroke-width: 1.5px;
- }
- .edgePath path {
- stroke: #333;
- stroke-width: 1.5px;
- }
- </style>
- <svg id="svg-canvas" width=960 height=600></svg>
- <section>
- <p>An example of visualizing clusters. This example shows
- how clusters can be applied to a rendered graph.
- </section>
- <script id="js">
- // Create the input graph
- var g = new 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);
- // Center the graph
- var xCenterOffset = (svg.attr("width") - g.graph().width) / 2;
- svgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");
- svg.attr("height", g.graph().height + 40);
- </script>
- <script src="demo.js"></script>
|