UNPKG

31 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
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. --> <title> GoJS Shapes -- Northwoods Software </title>
9 <link rel="stylesheet" href="../assets/css/prism.css" />
10 </head>
11 <script>
12
13 window.diagrams = [];
14 window.goCode = function(pre, w, h, parentid, animation) {
15 window.diagrams.push([pre, w, h, parentid, animation]);
16 }
17 </script>
18 <body>
19 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
20 <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">
21 <div class="md:pl-4">
22 <a class="text-white hover:text-white no-underline hover:no-underline
23 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
24 <h1 class="mb-0 p-1 ">GoJS</h1>
25 </a>
26 </div>
27 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
28 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
29 <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>
30 <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>
31 </svg>
32 </button>
33 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
34 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
38 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
40 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
41 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
42 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
43 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
44 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
45 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
46 </ul>
47 </div>
48 </div>
49 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
50 </nav>
51
52 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
53
54 <div id="navSide" class="flex flex-col w-full md:w-40 lg:w-48 text-gray-700 bg-white flex-shrink-0">
55 <div class="flex-shrink-0 px-8 py-4">
56 <button id="navButton" class="rounded-lg md:hidden focus:outline-none focus:ring" aria-label="Navigation">
57 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
58 <path id="navOpen" 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>
59 <path id="navClosed" 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>
60 </svg>
61 </button>
62 </div>
63 <nav id="navList" class="min-h-screen hidden md:block sidebar-nav flex-grow px-1 lg:px-4 pb-4 md:pb-0 md:overflow-y-auto break-words">
64 <a href="index.html">Basics</a>
65 <a href="buildingObjects.html">Building Parts</a>
66 <a href="usingModels.html">Using Models</a>
67 <a href="dataBinding.html">Data Binding</a>
68 <a href="react.html">GoJS with React</a>
69 <a href="angular.html">GoJS with Angular</a>
70 <a href="textBlocks.html">TextBlocks</a>
71 <a href="shapes.html">Shapes</a>
72 <a href="pictures.html">Pictures</a>
73 <a href="panels.html">Panels</a>
74 <a href="tablePanels.html">Table Panels</a>
75 <a href="brush.html">Brushes</a>
76 <a href="sizing.html">Sizing Objects</a>
77 <a href="itemArrays.html">Item Arrays</a>
78 <a href="changedEvents.html">Changed Events</a>
79 <a href="transactions.html">Transactions</a>
80 <a href="viewport.html">Coordinates</a>
81 <a href="initialView.html">Initial View</a>
82 <a href="collections.html">Collections</a>
83 <a href="links.html">Links</a>
84 <a href="linkLabels.html">Link Labels</a>
85 <a href="connectionPoints.html">Link Points</a>
86 <a href="ports.html">Ports</a>
87 <a href="nodes.html">Nodes</a>
88 <a href="debugging.html">Debugging</a>
89 <a href="layouts.html">Layouts</a>
90 <a href="trees.html">Trees</a>
91 <a href="subtrees.html">SubTrees</a>
92 <a href="groups.html">Groups</a>
93 <a href="subgraphs.html">SubGraphs</a>
94 <a href="sizedGroups.html">Sized Groups</a>
95 <a href="selection.html">Selection</a>
96 <a href="highlighting.html">Highlighting</a>
97 <a href="animation.html">Animation</a>
98 <a href="toolTips.html">ToolTips</a>
99 <a href="contextmenus.html">Context Menus</a>
100 <a href="events.html">Diagram Events</a>
101 <a href="tools.html">Tools</a>
102 <a href="commands.html">Commands</a>
103 <a href="permissions.html">Permissions</a>
104 <a href="validation.html">Validation</a>
105 <a href="HTMLInteraction.html">HTML Interaction</a>
106 <a href="layers.html">Layers &amp; Z-ordering</a>
107 <a href="palette.html">Palette</a>
108 <a href="overview.html">Overview</a>
109 <a href="resizing.html">Resizing Diagrams</a>
110 <a href="replacingDeleting.html">Replacing and Deleting</a>
111 <a href="buttons.html">Buttons</a>
112 <a href="templateMaps.html">Template Maps</a>
113 <a href="legends.html">Legends and Titles</a>
114 <a href="extensions.html">Extensions</a>
115 <a href="geometry.html">Geometry Strings</a>
116 <a href="grids.html">Grid Patterns</a>
117 <a href="graduatedPanels.html">Graduated Panels</a>
118 <a href="makingImages.html">Diagram Images</a>
119 <a href="makingSVG.html">Diagram SVG</a>
120 <a href="printing.html">Printing</a>
121 <a href="serverSideImages.html">Server-side Images</a>
122 <a href="nodeScript.html">GoJS in Node.js</a>
123 <a href="testing.html">Testing</a>
124 <a href="storage.html">Storage</a>
125 <a href="performance.html">Performance</a>
126 <a href="source.html">Building from Source</a>
127 <a href="platforms.html">Platforms</a>
128 <a href="deployment.html">Deployment</a>
129 </nav>
130 </div>
131 <div class="pt-4 px-2 md:px-0 lg:px-4 pb-16 w-full overflow-hidden">
132
133<h1>Shapes</h1>
134<p>
135Use the <a>Shape</a> class to paint a geometrical figure.
136You can control what kind of shape is drawn and how it is stroked and filled.
137</p>
138<p>
139Shapes, like <a>TextBlock</a>s and <a>Picture</a>s, are "atomic" objects -- they cannot contain any other objects.
140So a Shape will never draw some text or an image.
141</p>
142<p>
143In these simplistic demonstrations, the code programmatically creates a Part and adds it to the Diagram.
144Once you learn about models and data binding you will generally not create parts (nodes or links) programmatically.
145</p>
146
147<h2 id="Figures">Figures</h2>
148<p>
149You can set the <a>Shape.figure</a> property to commonly named kinds of shapes.
150When using <a>GraphObject,make</a>, you can pass the figure name as a string argument.
151You may also need to set the <a>GraphObject.desiredSize</a> or <a>GraphObject.width</a> and <a>GraphObject.height</a> properties,
152although it is also common to have the size determined by the Panel that the shape is in.
153</p>
154<p>
155Here are several of the most often used Shape figures:
156</p>
157<pre class="lang-js" id="figureShapes"><code>
158 diagram.add(
159 $(go.Part, "Horizontal",
160 $(go.Shape, "Rectangle", { width: 40, height: 60, margin: 4, fill: null }),
161 $(go.Shape, "RoundedRectangle", { width: 40, height: 60, margin: 4, fill: null }),
162 $(go.Shape, "Ellipse", { width: 40, height: 60, margin: 4, fill: null }),
163 $(go.Shape, "Diamond", { width: 40, height: 60, margin: 4, fill: null }),
164 $(go.Shape, "TriangleRight", { width: 40, height: 60, margin: 4, fill: null }),
165 $(go.Shape, "TriangleDown", { width: 40, height: 60, margin: 4, fill: null }),
166 $(go.Shape, "TriangleLeft", { width: 40, height: 60, margin: 4, fill: null }),
167 $(go.Shape, "TriangleUp", { width: 40, height: 60, margin: 4, fill: null }),
168 $(go.Shape, "MinusLine", { width: 40, height: 60, margin: 4, fill: null }),
169 $(go.Shape, "PlusLine", { width: 40, height: 60, margin: 4, fill: null }),
170 $(go.Shape, "XLine", { width: 40, height: 60, margin: 4, fill: null })
171 ));
172</code></pre>
173<script>goCode("figureShapes", 600, 100)</script>
174<p>
175You can see all of the named geometrical figures in the
176<a href="../samples/shapes.html" target="samples">shapes</a> sample.
177Some of the most commonly used figures are predefined in the <b>GoJS</b> library.
178But most figures are defined in the <a href="../extensions/Figures.js" target="_blank">Figures.js</a> file
179in the extensions directory.
180</p>
181
182<h2 id="FillAndStrokes">Fill and Strokes</h2>
183<p>
184The <a>Shape.stroke</a> property specifies the brush used to draw the shape's outline.
185The <a>Shape.fill</a> property specifies the brush used to fill the shape's outline.
186Additional "stroke..." properties also control how the shape's outline is drawn.
187The most common such property is <a>Shape.strokeWidth</a>.
188</p>
189<pre class="lang-js" id="strokedShapes"><code>
190 diagram.add(
191 $(go.Part, "Horizontal",
192 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4
193 }), // default fill and stroke are "black"
194 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
195 fill: "green" }),
196 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
197 fill: "green", stroke: null }),
198 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
199 fill: null, stroke: "green" }),
200 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
201 fill: null, stroke: "green", strokeWidth: 3 }),
202 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
203 fill: null, stroke: "green", strokeWidth: 6 }),
204 $(go.Shape, { figure: "Club", width: 40, height: 40, margin: 4,
205 fill: "green", background: "orange" })
206 ));
207</code></pre>
208<script>goCode("strokedShapes", 600, 100)</script>
209
210<p>
211The <a>Shape.stroke</a> and <a>Shape.fill</a> properties take <a>Brush</a>es
212but most often are given a CSS color string to denote solid color brushes.
213These two properties default to a solid black brush.
214However it is common to assign one of them to be either null or "transparent".
215A null brush means that nothing is drawn for that stroke or fill.
216A transparent brush produces the same appearance but different hit-testing behavior.
217A shape with a null <a>Shape.fill</a> produces a "hollow" shape -- clicking inside
218the shape will not "hit" that shape and thus not select the <a>Node</a> that that shape is in.
219But a shape with a transparent fill produces a "filled" shape -- a mouse event inside the
220shape will "hit" that shape.
221</p>
222<pre class="lang-js" class="lang-js" id="fill"><code>
223 diagram.div.style.background = "lightgray";
224 diagram.add(
225 $(go.Part, "Table",
226 $(go.Shape, { row: 0, column: 0, figure: "Club", width: 60, height: 60, margin: 4,
227 fill: "green" }),
228 $(go.TextBlock, "green", { row: 1, column: 0 }),
229 $(go.Shape, { row: 0, column: 1, figure: "Club", width: 60, height: 60, margin: 4,
230 fill: "white" }),
231 $(go.TextBlock, "white", { row: 1, column: 1 }),
232 $(go.Shape, { row: 0, column: 2, figure: "Club", width: 60, height: 60, margin: 4,
233 fill: "transparent" }),
234 $(go.TextBlock, "transparent", { row: 1, column: 2 }),
235 $(go.Shape, { row: 0, column: 3, figure: "Club", width: 60, height: 60, margin: 4,
236 fill: null }),
237 $(go.TextBlock, "null", { row: 1, column: 3 })
238 ));
239</code></pre>
240<script>goCode("fill", 600, 100)</script>
241<p>
242Try clicking inside each of the shapes to see which ones will respond to the click and cause the whole panel to be selected.
243Note that with the "transparent" fill you can see the diagram background, yet when you click in it you "hit" the Shape.
244Only the last one, with a null fill, is truly "hollow".
245Clicking in the last shape will only result in a click on the diagram background, unless you click on the stroke outline.
246</p>
247
248<h2 id="Geometry">Geometry</h2>
249<p>
250Every <a>Shape</a> gets its "shape" from the <a>Geometry</a> that it uses.
251A Geometry is just a saved description of how to draw some lines given a set of points.
252Setting <a>Shape.figure</a> uses a named predefined geometry that can be parameterized.
253In general it is most efficient to give a Shape a Geometry rather than giving it a figure.
254</p>
255<p>
256If you want something different from all of the predefined figures in <b>GoJS</b>,
257you can construct your own Geometry and set <a>Shape.geometry</a>.
258One way of building your own <a>Geometry</a> is by building <a>PathFigure</a>s
259consisting of <a>PathSegment</a>s.
260This is often necessary when building a geometry whose points are computed based on some data.
261</p>
262<p>
263But an easier way to create constant geometries is by
264calling <a>Geometry,parse</a> to read a string that has a geometry-defining path expression,
265or to set <a>Shape.geometryString</a> to such a string.
266These expressions have commands for moving an imaginary "pen".
267The syntax for geometry paths is documented in the <a href="geometry.html">Geometry Path Strings</a> page.
268</p>
269<p>
270This example creates a Geometry that looks like the letter "W"
271and uses it in several Shape objects with different stroke characteristics.
272Geometry objects may be shared by multiple Shapes.
273Note that there may be no need to specify the <a>GraphObject.desiredSize</a> or <a>GraphObject.width</a> and <a>GraphObject.height</a>,
274because the Geometry defines its own size.
275If the size is set or if it is imposed by the containing Panel, the effective geometry is determined by the <a>Shape.geometryStretch</a> property.
276Depending on the value of the geometryStretch property, this may result in extra empty space or the clipping of the shape.
277</p>
278<pre class="lang-js" id="geometries"><code>
279 var W_geometry = go.Geometry.parse("M 0,0 L 10,50 20,10 30,50 40,0", false);
280 diagram.add(
281 $(go.Part, "Horizontal",
282 $(go.Shape, { geometry: W_geometry, strokeWidth: 2 }),
283 $(go.Shape, { geometry: W_geometry, stroke: "blue", strokeWidth: 10,
284 strokeJoin: "miter", strokeCap: "butt" }),
285 $(go.Shape, { geometry: W_geometry, stroke: "blue", strokeWidth: 10,
286 strokeJoin: "miter", strokeCap: "round" }),
287 $(go.Shape, { geometry: W_geometry, stroke: "blue", strokeWidth: 10,
288 strokeJoin: "miter", strokeCap: "square" }),
289 $(go.Shape, { geometry: W_geometry, stroke: "green", strokeWidth: 10,
290 strokeJoin: "bevel", strokeCap: "butt" }),
291 $(go.Shape, { geometry: W_geometry, stroke: "green", strokeWidth: 10,
292 strokeJoin: "bevel", strokeCap: "round" }),
293 $(go.Shape, { geometry: W_geometry, stroke: "green", strokeWidth: 10,
294 strokeJoin: "bevel", strokeCap: "square" }),
295 $(go.Shape, { geometry: W_geometry, stroke: "red", strokeWidth: 10,
296 strokeJoin: "round", strokeCap: "butt" }),
297 $(go.Shape, { geometry: W_geometry, stroke: "red", strokeWidth: 10,
298 strokeJoin: "round", strokeCap: "round" }),
299 $(go.Shape, { geometry: W_geometry, stroke: "red", strokeWidth: 10,
300 strokeJoin: "round", strokeCap: "square" }),
301 $(go.Shape, { geometry: W_geometry, stroke: "purple", strokeWidth: 2,
302 strokeDashArray: [4, 2] }),
303 $(go.Shape, { geometry: W_geometry, stroke: "purple", strokeWidth: 2,
304 strokeDashArray: [6, 6, 2, 2] })
305 ));
306</code></pre>
307<script>goCode("geometries", 600, 100)</script>
308
309<h2 id="AngleAndScale">Angle and Scale</h2>
310<p>
311Besides setting the <a>GraphObject.desiredSize</a> or <a>GraphObject.width</a> and <a>GraphObject.height</a> to declare the size of a <a>Shape</a>,
312you can also set other properties to affect the appearance.
313For example, you can set the <a>GraphObject.angle</a> and <a>GraphObject.scale</a> properties.
314</p>
315<pre class="lang-js" id="transformedShapes"><code>
316 diagram.add(
317 $(go.Part, "Table",
318 $(go.Shape, { row: 0, column: 1,
319 figure: "Club", fill: "green", width: 40, height: 40,
320 }), // default angle is zero; default scale is one
321 $(go.Shape, { row: 0, column: 2,
322 figure: "Club", fill: "green", width: 40, height: 40,
323 angle: 30 }),
324 $(go.Shape, { row: 0, column: 3,
325 figure: "Club", fill: "green", width: 40, height: 40,
326 scale: 1.5 }),
327 $(go.Shape, { row: 0, column: 4,
328 figure: "Club", fill: "green", width: 40, height: 40,
329 angle: 30, scale: 1.5 })
330 ));
331</code></pre>
332<script>goCode("transformedShapes", 600, 100)</script>
333
334<p>
335The <a>Shape.fill</a> and <a>GraphObject.background</a> brushes scale and rotate along with the shape.
336The <a>GraphObject.areaBackground</a> is drawn in the containing panel's coordinates,
337so it is not affected by the object's scale or angle.
338</p>
339<p>
340The following two shapes each use three separate linear gradient brushes, one for each of the three properties.
341Note the unrotated shape on the left. Because its <a>GraphObject.background</a> brush is opaque,
342you cannot see the <a>GraphObject.areaBackground</a> brush that fills the same area behind it.
343</p>
344<pre class="lang-js" id="backgrounds"><code>
345 var bluered = $(go.Brush, "Linear", { 0.0: "blue", 1.0: "red" });
346 var yellowgreen = $(go.Brush, "Linear", { 0.0: "yellow", 1.0: "green" });
347 var grays = $(go.Brush, "Linear", { 0.0: "black", 1.0: "lightgray" });
348
349 diagram.add(
350 $(go.Part, "Table",
351 $(go.Shape, { row: 0, column: 0,
352 figure: "Club", width: 40, height: 40, angle: 0, scale: 1.5,
353 fill: bluered,
354 background: yellowgreen,
355 areaBackground: grays
356 }),
357 $(go.Shape, { row: 0, column: 1, width: 10, fill: null, stroke: null }),
358 $(go.Shape, { row: 0, column: 2,
359 figure: "Club", width: 40, height: 40, angle: 45, scale: 1.5,
360 fill: bluered,
361 background: yellowgreen,
362 areaBackground: grays
363 })
364 ));
365</code></pre>
366<script>goCode("backgrounds", 600, 120)</script>
367
368<h2 id="CustomFigures">Custom Figures</h2>
369<p>
370As shown above, one can easily create custom shapes just by setting <a>Shape.geometry</a> or <a>Shape.geometryString</a>.
371This is particularly convenient when importing SVG.
372However it is also possible to define additional named figures, which is convenient when you want to be able to easily
373specify or change the geometry of an existing Shape by setting or data binding the <a>Shape.figure</a> property.
374</p>
375<p>
376The static function <a>Shape,defineFigureGenerator</a> can be used to define new figure names.
377The second argument is a function that is called with the <a>Shape</a> and the expected width and height
378in order to generate and return a <a>Geometry</a>.
379This permits parameterization of the geometry based on properties of the Shape and the expected size.
380In particular, the <a>Shape.parameter1</a> and <a>Shape.parameter2</a> properties can be considered,
381in addition to the width and height, while producing the Geometry.
382To be valid, the generated Geometry bounds must be equal to or less than the supplied width and height.
383</p>
384<pre class="lang-js" id="defineFigure"><code>
385 go.Shape.defineFigureGenerator("RoundedTopRectangle", function(shape, w, h) {
386 // this figure takes one parameter, the size of the corner
387 var p1 = 5; // default corner size
388 if (shape !== null) {
389 var param1 = shape.parameter1;
390 if (!isNaN(param1) && param1 >= 0) p1 = param1; // can't be negative or NaN
391 }
392 p1 = Math.min(p1, w / 2);
393 p1 = Math.min(p1, h / 2); // limit by whole height or by half height?
394 var geo = new go.Geometry();
395 // a single figure consisting of straight lines and quarter-circle arcs
396 geo.add(new go.PathFigure(0, p1)
397 .add(new go.PathSegment(go.PathSegment.Arc, 180, 90, p1, p1, p1, p1))
398 .add(new go.PathSegment(go.PathSegment.Line, w - p1, 0))
399 .add(new go.PathSegment(go.PathSegment.Arc, 270, 90, w - p1, p1, p1, p1))
400 .add(new go.PathSegment(go.PathSegment.Line, w, h))
401 .add(new go.PathSegment(go.PathSegment.Line, 0, h).close()));
402 // don't intersect with two top corners when used in an "Auto" Panel
403 geo.spot1 = new go.Spot(0, 0, 0.3 * p1, 0.3 * p1);
404 geo.spot2 = new go.Spot(1, 1, -0.3 * p1, 0);
405 return geo;
406 });
407
408 go.Shape.defineFigureGenerator("RoundedBottomRectangle", function(shape, w, h) {
409 // this figure takes one parameter, the size of the corner
410 var p1 = 5; // default corner size
411 if (shape !== null) {
412 var param1 = shape.parameter1;
413 if (!isNaN(param1) && param1 >= 0) p1 = param1; // can't be negative or NaN
414 }
415 p1 = Math.min(p1, w / 2);
416 p1 = Math.min(p1, h / 2); // limit by whole height or by half height?
417 var geo = new go.Geometry();
418 // a single figure consisting of straight lines and quarter-circle arcs
419 geo.add(new go.PathFigure(0, 0)
420 .add(new go.PathSegment(go.PathSegment.Line, w, 0))
421 .add(new go.PathSegment(go.PathSegment.Line, w, h - p1))
422 .add(new go.PathSegment(go.PathSegment.Arc, 0, 90, w - p1, h - p1, p1, p1))
423 .add(new go.PathSegment(go.PathSegment.Line, p1, h))
424 .add(new go.PathSegment(go.PathSegment.Arc, 90, 90, p1, h - p1, p1, p1).close()));
425 // don't intersect with two bottom corners when used in an "Auto" Panel
426 geo.spot1 = new go.Spot(0, 0, 0.3 * p1, 0);
427 geo.spot2 = new go.Spot(1, 1, -0.3 * p1, -0.3 * p1);
428 return geo;
429 });
430
431 diagram.nodeTemplate =
432 $(go.Part, "Spot",
433 {
434 selectionAdorned: false, // don't show the standard selection handle
435 resizable: true, resizeObjectName: "SHAPE", // user can resize the Shape
436 rotatable: true, rotateObjectName: "SHAPE", // user can rotate the Shape
437 // without rotating the label
438 },
439 $(go.Shape,
440 {
441 name: "SHAPE",
442 fill: $(go.Brush, "Linear", { 0.0: "white", 1.0: "gray" }),
443 desiredSize: new go.Size(100, 50)
444 },
445 new go.Binding("figure", "fig"),
446 new go.Binding("parameter1", "p1")),
447 $(go.Panel, "Vertical",
448 $(go.TextBlock,
449 new go.Binding("text", "fig")),
450 $(go.TextBlock, { stroke: "blue" },
451 new go.Binding("text", "parameter1", function(p1) { return p1; }).ofObject("SHAPE"))
452 )
453 );
454
455 diagram.model = new go.Model([
456 { fig: "RoundedTopRectangle" },
457 { fig: "RoundedTopRectangle", p1: 0 },
458 { fig: "RoundedTopRectangle", p1: 3 },
459 { fig: "RoundedTopRectangle", p1: 10 },
460 { fig: "RoundedTopRectangle", p1: 50 },
461 { fig: "RoundedTopRectangle", p1: 250 },
462 { fig: "RoundedBottomRectangle" },
463 { fig: "RoundedBottomRectangle", p1: 0 },
464 { fig: "RoundedBottomRectangle", p1: 3 },
465 { fig: "RoundedBottomRectangle", p1: 10 },
466 { fig: "RoundedBottomRectangle", p1: 50 },
467 { fig: "RoundedBottomRectangle", p1: 250 }
468 ]);
469</code></pre>
470<script>goCode("defineFigure", 700, 300)</script>
471<p>
472Note how the <a>Shape.parameter1</a> property, data bound to the "p1" property, controls how rounded the corners are.
473The definition of each figure limits the roundedness based on the actual size of the geometry.
474You can see the effects by resizing the last shape -- the curve on the shape with p1==250 can be huge if the shape becomes huge.
475</p>
476<p>
477You can find the definitions for many figures at: <a href="../extensions/Figures.js" target="_blank">Figures.js</a>.
478The "RoundedTopRectangle" and "RoundedBottomRectangle" figures shown above are available at:
479<a href="../extensions/RoundedRectangles.js" target="_blank">RoundedRectangles.js</a>.
480</p>
481
482 </div>
483 </div>
484
485 <div class="bg-nwoods-primary">
486 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
487 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
488 </section>
489 </div><footer class="bg-nwoods-primary text-white">
490 <div class="container max-w-screen-lg mx-auto px-8">
491 <div class="w-full py-6">
492
493 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
494 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
495 <li class="list-none row-span-2">
496 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
497 <ul class="list-none space-y-4 md:space-y-1 px-0">
498 <li>
499 <a href="../samples/index.html">Samples</a>
500 </li>
501 <li>
502 <a href="../learn/index.html">Learn</a>
503 </li>
504 <li>
505 <a href="../intro/index.html">Intro</a>
506 </li>
507 <li>
508 <a href="../api/index.html">API</a>
509 </li>
510 <li>
511 <a href="../changelog.html">Changelog</a>
512 </li>
513 <li>
514 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
515 </li>
516 </ul>
517 </li>
518 <li class="list-none row-span-2">
519 <h2 class="text-base font-semibold tracking-wide">Support</h2>
520 <ul class="list-none space-y-4 md:space-y-1 px-0">
521 <li>
522 <a href="https://www.nwoods.com/contact.html"
523 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
524 </li>
525 <li>
526 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
527 </li>
528 <li>
529 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
530 </li>
531 <li>
532 <a href="https://www.nwoods.com/sales/index.html"
533 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
534 </li>
535 <li>
536 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
537 </li>
538 </ul>
539 </li>
540 <li class="list-none row-span-2">
541 <h2 class="text-base font-semibold tracking-wide">Company</h2>
542 <ul class="list-none space-y-4 md:space-y-1 px-0">
543 <li>
544 <a href="https://www.nwoods.com">Northwoods</a>
545 </li>
546 <li>
547 <a href="https://www.nwoods.com/about.html">About Us</a>
548 </li>
549 <li>
550 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
551 </li>
552 <li>
553 <a href="https://twitter.com/northwoodsgo">Twitter</a>
554 </li>
555
556 </ul>
557 </li>
558 </ul>
559
560
561 <p class="text-sm text-gray-100 md:mb-6">
562 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
563 </p>
564 </div>
565 </div>
566</footer> </body>
567
568<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
569<script>
570 window.dataLayer = window.dataLayer || [];
571 function gtag(){dataLayer.push(arguments);}
572 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
573 var getOutboundLink = function(url, label) {
574 gtag('event', 'click', {
575 'event_category': 'outbound',
576 'event_label': label,
577 'transport_type': 'beacon'
578 });
579 }
580
581 // topnav
582 var topButton = document.getElementById("topnavButton");
583 var topnavList = document.getElementById("topnavList");
584 topButton.addEventListener("click", function() {
585 this.classList.toggle("active");
586 topnavList.classList.toggle("hidden");
587 document.getElementById("topnavOpen").classList.toggle("hidden");
588 document.getElementById("topnavClosed").classList.toggle("hidden");
589 });
590</script>
591 <script src="../assets/js/prism.js"></script>
592 <script src="../release/go.js"></script>
593<script src="../extensions/Figures.js"></script> <script src="../assets/js/goDoc.js"></script>
594 <script>
595 document.addEventListener("DOMContentLoaded", function() {
596 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
597 if (window.goDoc) window.goDoc();
598 var d = window.diagrams;
599 for (var i = 0; i < d.length; i++) {
600 var dargs = d[i];
601 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
602 }
603 if (window.extra) window.extra();
604 });
605 </script>
606</html>