UNPKG

10.2 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8"/>
5<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
6<meta name="description" content="Arrange disconnected circular subgraphs in a circle and put disconnected nodes in a grid underneath."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>Arranging Layout of the Class Hierarchy</title>
10</head>
11
12<body>
13 <!-- This top nav is not part of the sample code -->
14 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
15 <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">
16 <div class="md:pl-4">
17 <a class="text-white hover:text-white no-underline hover:no-underline
18 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
19 <h1 class="mb-0 p-1 ">GoJS</h1>
20 </a>
21 </div>
22 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
23 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
24 <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>
25 <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>
26 </svg>
27 </button>
28 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
29 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
30 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
31 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
32 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
33 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
34 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
38 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
40 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
41 </ul>
42 </div>
43 </div>
44 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
45 </nav>
46 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
47 <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
48 <!-- * * * * * * * * * * * * * -->
49 <!-- Start of GoJS sample code -->
50
51
52 <div class="p-4 w-full">
53<div id="sample">
54 <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:800px; min-width: 200px"></div>
55 <p>
56 This sample demonstrates a custom Layout, <a>ArrangingLayout</a>, that provides layouts of layouts.
57 It assumes the graph should be split up and laid out by potentially three separate Layouts.
58 </p>
59 <p>
60 The first step of ArrangingLayout is that all unconnected nodes are separated out to be laid out later by
61 the <a>ArrangingLayout.sideLayout</a>, which by default is a <a>GridLayout</a>.
62 </p>
63 <p>
64 The remaining nodes and links are partitioned into separate subgraphs with no links between subgraphs.
65 The <a>ArrangingLayout.primaryLayout</a> is performed on each subgraph.
66 </p>
67 <p>
68 If there is more than one subgraph, those subgraphs are treated as if they were individual nodes and are
69 laid out by the <a>ArrangingLayout.arrangingLayout</a>.
70 </p>
71 <p>
72 Finally the unconnected nodes are laid out by <a>ArrangingLayout.sideLayout</a> and they are all positioned
73 at the <a>ArrangingLayout.side</a> Spot relative to the main body of nodes and links.
74 </p>
75 <p>
76 This extension layout is defined in its own file, as <a href="ArrangingLayout.js">ArrangingLayout.js</a>.
77 </p>
78 <script type="module" id="code">
79 import * as go from "../release/go-module.js";
80 import { ArrangingLayout } from "./ArrangingLayout.js";
81 import { PackedLayout } from "./PackedLayout.js";
82
83 if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
84 var $ = go.GraphObject.make;
85
86 const myDiagram =
87 $(go.Diagram, "myDiagramDiv", // create a Diagram for the DIV HTML element
88 {
89 initialAutoScale: go.Diagram.Uniform,
90 layout:
91 $(ArrangingLayout,
92 { // create a circular arrangement of circular layouts
93 primaryLayout: $(go.CircularLayout), // must specify the primaryLayout
94 arrangingLayout: $(go.CircularLayout, { nodeDiameterFormula: go.CircularLayout.Circular, spacing: 30 }),
95
96 // Uncommenting this filter will force all of the nodes and links to go into the main subset and thus
97 // will cause all those nodes to be arranged by this.arrangingLayout, here a CircularLayout,
98 // rather than by the this.sideLayout, which by default is a GridLayout.
99 //filter: function(part) { return true; },
100
101 // additional custom properties for use by preparePrimaryLayout
102 _colors: ["red", "orange", "yellow", "lime", "cyan"], // possible node colors
103 _colorIndex: 0, // cycle through the given colors
104
105 // called for each separate connected subgraph
106 preparePrimaryLayout: function(lay, coll) { // color all of the nodes in each subgraph
107 var root = null; // find the root node in this subgraph
108 coll.each(function(node) {
109 if (node instanceof go.Node && node.findLinksInto().count === 0) root = node;
110 });
111 var color = "white"; // determine the color for the nodes in this subgraph
112 if (root !== null) {
113 // root.key will be the name of the class that this node represents
114 // Special case: "LayoutNetwork", "LayoutVertex", and "LayoutEdge" classes are "violet"
115 if (root.key.indexOf("Layout") === 0 && root.key.length > "Layout".length) {
116 color = "violet";
117 } else { // otherwise cycle through the Array of colors
118 color = this._colors[this._colorIndex++ % this._colors.length];
119 }
120 }
121 coll.each(function(node) { // assign the fill color for all of the nodes in the subgraph
122 if (node instanceof go.Node) {
123 var shape = node.findObject("SHAPE");
124 if (shape !== null) shape.fill = color;
125 }
126 });
127 },
128
129 prepareSideLayout: function(lay, coll, b) { // called once for the sideLayout
130 // adjust how wide the GridLayout lays out
131 lay.wrappingWidth = Math.max(b.width, this.diagram.viewportBounds.width);
132 }
133 })
134 });
135
136 myDiagram.nodeTemplate =
137 $(go.Node, go.Panel.Auto,
138 $(go.Shape, { name: "SHAPE", figure: "RoundedRectangle", fill: "lightgray" },
139 new go.Binding("fill", "color")),
140 $(go.TextBlock, { margin: 2, textAlign: "center" },
141 new go.Binding("text", "key", function(s) {
142 // insert newlines between lowercase followed by uppercase characters
143 var arr = s.split("");
144 for (let i = 1; i < arr.length-1; i++) {
145 var a = arr[i-1];
146 var b = arr[i];
147 if (a === a.toLowerCase() && b === b.toUpperCase()) {
148 arr.splice(i, 0, "\n");
149 i += 2;
150 }
151 }
152 return arr.join("");
153 })));
154
155 myDiagram.linkTemplate =
156 $(go.Link,
157 { layerName: "Background" },
158 $(go.Shape));
159
160 // Collect all of the data for the model of the class hierarchy
161 var nodeDataArray = [];
162
163 // Iterate over all of the classes in "go"
164 for (var k in go) {
165 var cls = go[k];
166 if (!cls) continue;
167 var proto = cls.prototype;
168 if (!proto) continue;
169 proto.constructor.className = k; // remember name
170 // find base class constructor
171 var base = Object.getPrototypeOf(proto).constructor;
172 if (base === Object) { // "root" node?
173 nodeDataArray.push({ key: k });
174 } else {
175 // add a node for this class and a tree-parent reference to the base class name
176 nodeDataArray.push({ key: k, parent: base.className });
177 }
178 }
179
180 // Create the model for the hierarchy diagram
181 myDiagram.model = new go.TreeModel(nodeDataArray);
182 window.myDiagram = myDiagram; // Attach to the window for console debugging
183 </script>
184</div>
185 </div>
186 <!-- * * * * * * * * * * * * * -->
187 <!-- End of GoJS sample code -->
188 </div>
189</body>
190<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
191<script src="../assets/js/goSamples.js"></script>
192</html>