UNPKG

gojs

Version:

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

205 lines (191 loc) 9.45 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/> <meta name="description" content="TypeScript: A custom Layout that arranges a collection of nodes and links where there is a single &#39;split&#39; node and a single &#39;merge&#39; node, and all nodes are in paths of links that come from the &#39;split&#39; node and go to the &#39;merge&#39; node."/> <link rel="stylesheet" href="../assets/css/style.css"/> <!-- Copyright 1998-2023 by Northwoods Software Corporation. --> <title>Parallel Layout</title> </head> <body> <!-- This top nav is not part of the sample code --> <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary"> <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2"> <div class="md:pl-4"> <a class="text-white hover:text-white no-underline hover:no-underline font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../"> <h1 class="my-0 p-1 ">GoJS</h1> </a> </div> <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation"> <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6"> <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path> <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button> <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20"> <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0"> <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li> </ul> </div> </div> <hr class="border-b border-gray-600 opacity-50 my-0 py-0" /> </nav> <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto"> <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div> <!-- * * * * * * * * * * * * * --> <!-- Start of GoJS sample code --> <div id="allSampleContent" class="p-4 w-full"> <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" target="_blank">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> <script type="module" id="code"> import * as go from "../release/go-module.js"; import { ParallelLayout } from './ParallelLayout.js'; if (window.goSamples) window.goSamples(); // init for these samples -- you don't need to call this const $ = go.GraphObject.make; // for conciseness in defining templates const myDiagram = new go.Diagram('myDiagramDiv', // must be the ID or reference to div { allowCopy: false, allowDelete: false, 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 }, $(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" }) ); myDiagram.model = new go.GraphLinksModel([ { 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' } ], [ { 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 } ]); window.myDiagram = myDiagram; // Attach to the window for console debugging </script> </div> <!-- * * * * * * * * * * * * * --> <!-- End of GoJS sample code --> </div> </body> <!-- This script is part of the gojs.net website, and is not needed to run the sample --> <script src="../assets/js/goSamples.js"></script> </html>