UNPKG

8.3 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="TypeScript: A custom layout that arranges a chain of nodes in a spiral manner."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>Spiral Layout</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:700px; min-width: 200px"></div>
55 <p>
56 This sample demonstrates a custom Layout, SpiralLayout, which assumes the graph consists of a chain of nodes. The layout
57 is defined in its own file, as <a href="SpiralLayout.ts">SpiralLayout.ts</a>.
58 </p>
59 </div>
60 <script type="module" id="code">
61 import * as go from "../release/go-module.js";
62 import { SpiralLayout } from './SpiralLayout.js';
63
64 if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
65 const $ = go.GraphObject.make;
66
67 const myDiagram = $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
68 {
69 initialAutoScale: go.Diagram.Uniform,
70 isTreePathToChildren: false,
71 layout: $(SpiralLayout) // defined in SpiralLayout.js
72 });
73 myDiagram.nodeTemplate =
74 $(go.Node, go.Panel.Auto,
75 { locationSpot: go.Spot.Center },
76 $(go.Shape,
77 { figure: 'Circle', fill: 'white' },
78 new go.Binding('fill', 'color')),
79 $(go.TextBlock,
80 { margin: 4 },
81 new go.Binding('text', 'key'))
82 );
83
84 myDiagram.linkTemplate =
85 $(go.Link,
86 { curve: go.Link.Bezier, curviness: 10 },
87 $(go.Shape),
88 $(go.Shape, { toArrow: 'Standard' })
89 );
90
91 const model = new go.TreeModel();
92 model.nodeParentKeyProperty = 'next';
93 model.nodeDataArray = [
94 { key: 'Alpha', next: 'Beta', color: 'coral' },
95 { key: 'Beta', next: 'Gamma', color: 'tomato' },
96 { key: 'Gamma', next: 'Delta', color: 'goldenrod' },
97 { key: 'Delta', next: 'Epsilon', color: 'orange' },
98 { key: 'Epsilon', next: 'Zeta', color: 'coral' },
99 { key: 'Zeta', next: 'Eta', color: 'tomato' },
100 { key: 'Eta', next: 'Theta', color: 'goldenrod' },
101 { key: 'Theta', next: 'Iota', color: 'orange' },
102 { key: 'Iota', next: 'Kappa', color: 'coral' },
103 { key: 'Kappa', next: 'Lambda', color: 'tomato' },
104 { key: 'Lambda', next: 'Mu', color: 'goldenrod' },
105 { key: 'Mu', next: 'Nu', color: 'orange' },
106 { key: 'Nu', next: 'Xi', color: 'coral' },
107 { key: 'Xi', next: 'Omicron', color: 'tomato' },
108 { key: 'Omicron', next: 'Pi', color: 'goldenrod' },
109 { key: 'Pi', next: 'Rho', color: 'orange' },
110 { key: 'Rho', next: 'Sigma', color: 'coral' },
111 { key: 'Sigma', next: 'Tau', color: 'tomato' },
112 { key: 'Tau', next: 'Upsilon', color: 'goldenrod' },
113 { key: 'Upsilon', next: 'Phi', color: 'orange' },
114 { key: 'Phi', next: 'Chi', color: 'coral' },
115 { key: 'Chi', next: 'Psi', color: 'tomato' },
116 { key: 'Psi', next: 'Omega', color: 'goldenrod' },
117 { key: 'Omega', next: 'Alpha2', color: 'orange' },
118 { key: 'Alpha2', next: 'Beta2', color: 'coral' },
119 { key: 'Beta2', next: 'Gamma2', color: 'tomato' },
120 { key: 'Gamma2', next: 'Delta2', color: 'goldenrod' },
121 { key: 'Delta2', next: 'Epsilon2', color: 'orange' },
122 { key: 'Epsilon2', next: 'Zeta2', color: 'coral' },
123 { key: 'Zeta2', next: 'Eta2', color: 'tomato' },
124 { key: 'Eta2', next: 'Theta2', color: 'goldenrod' },
125 { key: 'Theta2', next: 'Iota2', color: 'orange' },
126 { key: 'Iota2', next: 'Kappa2', color: 'coral' },
127 { key: 'Kappa2', next: 'Lambda2', color: 'tomato' },
128 { key: 'Lambda2', next: 'Mu2', color: 'goldenrod' },
129 { key: 'Mu2', next: 'Nu2', color: 'orange' },
130 { key: 'Nu2', next: 'Xi2', color: 'coral' },
131 { key: 'Xi2', next: 'Omicron2', color: 'tomato' },
132 { key: 'Omicron2', next: 'Pi2', color: 'goldenrod' },
133 { key: 'Pi2', next: 'Rho2', color: 'orange' },
134 { key: 'Rho2', next: 'Sigma2', color: 'coral' },
135 { key: 'Sigma2', next: 'Tau2', color: 'tomato' },
136 { key: 'Tau2', next: 'Upsilon2', color: 'goldenrod' },
137 { key: 'Upsilon2', next: 'Phi2', color: 'orange' },
138 { key: 'Phi2', next: 'Chi2', color: 'coral' },
139 { key: 'Chi2', next: 'Psi2', color: 'tomato' },
140 { key: 'Psi2', next: 'Omega2', color: 'goldenrod' },
141 { key: 'Omega2', color: 'orange' }
142 ];
143 myDiagram.model = model;
144
145 window.myDiagram = myDiagram; // Attach to the window for console debugging
146 </script>
147 </div>
148 <!-- * * * * * * * * * * * * * -->
149 <!-- End of GoJS sample code -->
150 </div>
151</body>
152<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
153<script src="../assets/js/goSamples.js"></script>
154</html>