UNPKG

gojs

Version:

Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams

164 lines (154 loc) 6.29 kB
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Parallel Layout</title> <meta name="description" content="A custom Layout that arranges a collection of nodes and links where there is a single 'split' node and a single 'merge' node, and all nodes are in paths of links that come from the 'split' node and go to the 'merge' node." /> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Copyright 1998-2020 by Northwoods Software Corporation. --> <script src="../release/go.js"></script> <script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework --> <script src="ParallelLayout.js"></script> <script id="code"> function init() { if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this var $ = go.GraphObject.make; // for conciseness in defining templates myDiagram = $(go.Diagram, "myDiagramDiv", // must be the ID or reference to div { allowCopy: false, // would need to merge copied nodes and links to allowDelete: false, // use the single "Split" and "Merge" nodes layout: $(ParallelLayout, { layerSpacing: 20, nodeSpacing: 10 }) }); // define the Node templates myDiagram.nodeTemplate = $(go.Node, "Auto", { locationSpot: go.Spot.Center }, $(go.Shape, "Rectangle", { fill: "wheat", stroke: null, strokeWidth: 0 }), $(go.TextBlock, { margin: 3 }, new go.Binding("text")) ); myDiagram.nodeTemplateMap.add("Split", $(go.Node, "Auto", { locationSpot: go.Spot.Center }, $(go.Shape, "Diamond", { fill: "deepskyblue", stroke: null, strokeWidth: 0, desiredSize: new go.Size(28, 28) }), $(go.TextBlock, new go.Binding("text")) )); myDiagram.nodeTemplateMap.add("Merge", $(go.Node, "Auto", { locationSpot: go.Spot.Center }, $(go.Shape, "Circle", { fill: "deepskyblue", stroke: null, strokeWidth: 0, desiredSize: new go.Size(28, 28) }), $(go.TextBlock, new go.Binding("text")) )); // define the Link template to be minimal myDiagram.linkTemplate = $(go.Link, { routing: go.Link.Orthogonal, corner: 5, reshapable: true }, $(go.Shape, { stroke: "gray", strokeWidth: 1.5 }) ); // define the Group template to be fairly simple myDiagram.groupTemplate = $(go.Group, "Auto", { layout: $(ParallelLayout, { layerSpacing: 20, nodeSpacing: 10 }) }, $(go.Shape, { fill: "transparent", stroke: "darkgoldenrod" }), $(go.Placeholder, { padding: 10 }), $("SubGraphExpanderButton", { alignment: go.Spot.TopLeft, "ButtonBorder.figure": "Rectangle" }) ); var model = $(go.GraphLinksModel); model.nodeDataArray = [ { key: -1, isGroup: true }, { key: -2, isGroup: true }, { key: -3, isGroup: true }, { key: 1, text: "S", category: "Split", group: -1 }, { key: 2, text: "C", group: -1 }, { key: 3, text: "Longer Node", group: -1 }, { key: 4, text: "A", group: -1 }, { key: 5, text: "B\nB", group: -1 }, { key: 6, text: "Another", group: -1 }, { key: 9, text: "J", category: "Merge", group: -1 }, { key: 11, text: "T", category: "Split", group: -2 }, { key: 12, text: "C", group: -2 }, { key: 13, text: "Here", group: -2 }, { key: 14, text: "D", group: -2 }, { key: 15, text: "Everywhere", group: -2 }, { key: 16, text: "EEEEE", group: -2 }, { key: 19, text: "K", category: "Merge", group: -2 }, { key: 21, text: "U", category: "Split", group: -3 }, { key: 22, text: "F", group: -3 }, { key: 23, text: "Medium\nTall\nNode", group: -3 }, { key: 24, text: "G", group: -3 }, { key: 25, text: "AS", group: -3 }, { key: 26, text: "H\nHH\nHHH", group: -3 }, { key: 27, text: "I", group: -3 }, { key: 29, text: "L", category: "Merge", group: -3 }, { key: 101, text: "0", category: "Split" }, { key: 107, text: "ABCDEFG" }, { key: 109, text: "*", category: "Merge" } ]; model.linkDataArray = [ { from: 1, to: 2 }, { from: 2, to: 3 }, { from: 3, to: 4 }, { from: 4, to: 9 }, { from: 1, to: 5 }, { from: 5, to: 6 }, { from: 6, to: 9 }, { from: 9, to: 11 }, { from: 9, to: 21 }, { from: 11, to: 12 }, { from: 12, to: 13 }, { from: 13, to: 14 }, { from: 14, to: 19 }, { from: 11, to: 15 }, { from: 15, to: 16 }, { from: 16, to: 19 }, { from: 21, to: 22 }, { from: 22, to: 24 }, { from: 24, to: 26 }, { from: 23, to: 29 }, { from: 21, to: 25 }, { from: 25, to: 23 }, { from: 21, to: 27 }, { from: 26, to: 29 }, { from: 27, to: 29 }, { from: 101, to: 1 }, { from: 19, to: 109 }, { from: 29, to: 107 }, { from: 107, to: 109 } ]; myDiagram.model = model; } </script> </head> <body onload="init()"> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; background: white; width: 100%; height: 500px"></div> <p> This sample demonstrates a custom <a>TreeLayout</a>, ParallelLayout, which assumes that there is a single "Split" node that is the root of a tree, other than links that connect with a single "Merge" node. The layout is defined in its own file, as <a href="ParallelLayout.js">ParallelLayout.js</a>. </p> <p> Both the <a>Diagram.layout</a> and the <a>Group.layout</a> are instances of ParallelLayout, allowing for nested layouts that appear in parallel. </p> </div> </body> </html>