UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

892 lines (831 loc) 36.1 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"/> <link rel="preconnect" href="https://rsms.me/"> <link rel="stylesheet" href="../assets/css/style.css"> <!-- Copyright 1998-2025 by Northwoods Software Corporation. --> <meta itemprop="name" content="Geometry Path Strings" /> <meta property="og:title" content="Geometry Path Strings" /> <meta name="twitter:title" content="Geometry Path Strings" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" /> <meta property="og:url" content="https://gojs.net/latest/intro/geometry.html" /> <meta property="twitter:url" content="https://gojs.net/latest/intro/geometry.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Geometry Path Strings | GoJS </title> <link rel="stylesheet" href="../assets/css/prism.css"/> </head> <script> window.diagrams = []; window.goCode = function (pre, w, h, parentid, animation) { window .diagrams .push([pre, w, h, parentid, animation]); } </script> <body> <nav id="navTop" class=" w-full h-[var(--topnav-h)] z-30 bg-white border-b border-b-gray-200"> <div class="max-w-screen-xl mx-auto flex flex-wrap items-start justify-between px-4"> <a class="text-white bg-nwoods-primary font-bold !leading-[calc(var(--topnav-h)_-_1px)] my-0 px-2 text-4xl lg:text-5xl logo" href="../"> GoJS </a> <div class="relative"> <button id="topnavButton" class="h-[calc(var(--topnav-h)_-_1px)] px-2 m-0 text-gray-900 bg-inherit shadow-none md:hidden hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation"> <svg class="h-7 w-7 block" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"> <path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/> </svg> </button> <div id="topnavList" class="hidden md:block"> <div class="absolute right-0 z-30 flex flex-col items-end rounded border border-gray-200 p-4 pl-12 shadow bg-white text-gray-900 font-semibold md:flex-row md:space-x-4 md:items-start md:border-0 md:p-0 md:shadow-none md:bg-inherit"> <a href="../learn/">Learn</a> <a href="../samples/">Samples</a> <a href="../intro/">Intro</a> <a href="../api/">API</a> <a href="../download.html">Download</a> <a href="https://forum.nwoods.com/c/gojs/11" target="_blank" rel="noopener">Forum</a> <a id="tc" href="https://nwoods.com/contact.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a> <a id="tb" href="https://nwoods.com/sales/index.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a> </div> </div> </div> </div> </nav> <script> window.addEventListener("DOMContentLoaded", function () { // topnav var topButton = document.getElementById("topnavButton"); var topnavList = document.getElementById("topnavList"); if (topButton && topnavList) { topButton.addEventListener("click", function (e) { topnavList .classList .toggle("hidden"); e.stopPropagation(); }); document.addEventListener("click", function (e) { // if the clicked element isn't the list, close the list if (!topnavList.classList.contains("hidden") && !e.target.closest("#topnavList")) { topButton.click(); } }); // set active <a> element var url = window .location .href .toLowerCase(); var aTags = topnavList.getElementsByTagName('a'); for (var i = 0; i < aTags.length; i++) { var lowerhref = aTags[i] .href .toLowerCase(); if (lowerhref.endsWith('.html')) lowerhref = lowerhref.slice(0, -5); if (url.startsWith(lowerhref)) { aTags[i] .classList .add('active'); break; } } } }); </script> <div class="sticky top-0 left-0 z-10 px-2 w-full bg-white border-b border-b-gray-200 md:hidden"> <button id="sidenavButton" class="flex p-2 text-gray-900 bg-inherit shadow-none items-center text-sm font-semibold hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation"> <svg class="h-7 w-7 block mr-2" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"> <path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/> </svg> <span>Menu</span> </button> </div> <script> window.addEventListener("DOMContentLoaded", function () { // sidenav var sideButton = document.getElementById("sidenavButton"); var sidenav = document.getElementById("sidenav"); if (sideButton && sidenav) { sideButton.addEventListener("click", function (e) { sidenav .classList .toggle("hidden"); e.stopPropagation(); }); document.addEventListener("click", function (e) { // if the clicked element isn't the list, close the list if (!sidenav.classList.contains("hidden") && !e.target.closest("#sidenavList")) { sideButton.click(); } }); } }); </script> <div class="flex flex-row md:min-h-screen w-full max-w-screen-xl mx-auto"> <aside id="sidenav" class="hidden fixed top-0 left-0 z-10 w-full bg-black/10 min-h-screen max-h-screen overflow-x-hidden overflow-y-auto shrink-0 md:block md:sticky md:w-52 md:min-h-0 md:bg-inherit md:border-r md:border-r-gray-200 md:overscroll-auto"> <nav id="sidenavList" class="flex flex-col bg-white w-52 min-h-screen pl-2 pt-4 pb-24 md:w-full md:min-h-0"> <a href="index.html">Basics</a> <a href="buildingObjects.html">Building Parts</a> <a href="usingModels.html">Using Models</a> <a href="dataBinding.html">Data Binding</a> <a href="react.html">GoJS with React</a> <a href="svelte.html">GoJS with Svelte</a> <a href="angular.html">GoJS with Angular</a> <a href="textBlocks.html">TextBlocks</a> <a href="shapes.html">Shapes</a> <a href="pictures.html">Pictures</a> <a href="panels.html">Panels</a> <a href="tablePanels.html">Table Panels</a> <a href="brush.html">Brushes</a> <a href="sizing.html">Sizing Objects</a> <a href="itemArrays.html">Item Arrays</a> <a href="changedEvents.html">Changed Events</a> <a href="transactions.html">Transactions</a> <a href="viewport.html">Coordinates</a> <a href="initialView.html">Initial View</a> <a href="collections.html">Collections</a> <a href="links.html">Links</a> <a href="linkLabels.html">Link Labels</a> <a href="connectionPoints.html">Link Points</a> <a href="ports.html">Ports</a> <a href="nodes.html">Nodes</a> <a href="typings.html">Typings</a> <a href="debugging.html">Debugging</a> <a href="layouts.html">Layouts</a> <a href="routers.html">Routers</a> <a href="trees.html">Trees</a> <a href="subtrees.html">SubTrees</a> <a href="groups.html">Groups</a> <a href="subgraphs.html">SubGraphs</a> <a href="sizedGroups.html">Sized Groups</a> <a href="selection.html">Selection</a> <a href="highlighting.html">Highlighting</a> <a href="theming.html">Theming</a> <a href="tooltips.html">ToolTips</a> <a href="contextMenus.html">Context Menus</a> <a href="events.html">Diagram Events</a> <a href="tools.html">Tools</a> <a href="commands.html">Commands</a> <a href="accessibility.html">Accessibility</a> <a href="buttons.html">Buttons</a> <a href="permissions.html">Permissions</a> <a href="validation.html">Validation</a> <a href="animation.html">Animation</a> <a href="HTMLInteraction.html">HTML Interaction</a> <a href="layers.html">Layers &amp; Z-ordering</a> <a href="palette.html">Palette</a> <a href="overview.html">Overview</a> <a href="replacingDeleting.html">Replacing and Deleting</a> <a href="templateMaps.html">Template Maps</a> <a href="legends.html">Legends and Titles</a> <a href="extensions.html">Extensions</a> <a href="geometry.html">Geometry Strings</a> <a href="grids.html">Grid Patterns</a> <a href="graduatedPanels.html">Graduated Panels</a> <a href="SVGContext.html">Rendering to SVG</a> <a href="makingSVG.html">Snapshot to SVG</a> <a href="makingImages.html">Diagram Images</a> <a href="printing.html">Printing</a> <a href="serverSideImages.html">Server-side Images</a> <a href="nodeScript.html">GoJS in Node.js</a> <a href="testing.html">Testing</a> <a href="performance.html">Performance</a> <a href="platforms.html">Platforms</a> <a href="deployment.html">Deployment</a> </nav> </aside> <script> var navList = document.getElementById('sidenavList'); if (navList !== null) { var url = window.location.href; var lindex = url.lastIndexOf('/'); url = url .slice(lindex + 1) .toLowerCase(); var aTags = navList.getElementsByTagName('a'); var currentindex = -1; for (var i = 0; i < aTags.length; i++) { var lowerhref = aTags[i] .href .toLowerCase(); if (lowerhref.indexOf('/' + url) !== -1) { currentindex = i; aTags[i] .classList .add('active'); break; } } } </script> <div class="px-4 pb-16 w-full overflow-hidden prose"> <h1>Geometry Path Strings</h1> <p> The <b>GoJS</b> <a>Geometry</a> class controls the "shape" of a <a>Shape</a>, whereas the <a>Shape.fill</a> and <a>Shape.stroke</a> and other shape properties control the colors and appearance of the shape. For common shape figures, there are predefined geometries that can be used by setting <a>Shape.figure</a>. However one can also define custom geometries. </p> <p> One can construct any Geometry by allocating and initializing a <a>Geometry</a> of at least one <a>PathFigure</a> holding some <a>PathSegment</a>s. But you may find that using the string representation of a Geometry is easier to write and save in a database. Use the static method <a>Geometry.parse</a> or the <a>Shape.geometryString</a> property to transform a geometry path string into a <a>Geometry</a> object. </p> <p>See samples that make use of Geometries in the <a href="../samples/index.html#geometries">samples index</a>.</p> <h2 id="GeometryPathStringSyntax">Geometry Path String Syntax</h2> <p> The syntax for a geometry path string is an extension of the SVG path string syntax. The string consists of a number of commands, each a single letter followed by some command-specific numeric parameters. </p> <p> Below are the possible commands along with the parameters they take. The parameter notation <code>(x y)+</code> means that the command requires exactly two parameters, but there can be 1 or more sets of parameters for each command. For instance, the <code>L (x y)+</code> command can be written as <code>L 10 10 20 20</code> to denote two straight line segments. </p> <p> Commands written with an uppercase letter indicate absolute coordinates; lowercase commands specify coordinates relative to the last command. Some commands do not care about case because they do not take coordinates as arguments. </p> <ul style="padding-left: 0px; list-style: none"> <li> <pre class="lang-js"><code>M (x y)+</code></pre> Move commands begin a new subpath in a <a>PathFigure</a>. One is essential to begin a PathFigure and therefore must be the first segment type in the path string, with the exception of a Fill command (<code>F</code>) that can precede it. <p> Additional sets of parameters for a move command are automatically considered Line commands, so <code>M 10 10 20 20</code> is identical to <code>M 10 10 L 20 20</code>. </p> </li> <li> <pre class="lang-js"><code>L (x y)+</code></pre> Line command adds a straight line segment from the previous point to the new point. </li> <li> <pre class="lang-js"><code>H (x)+</code></pre> Horizontal line command specifies only an x value for a straight horizontal line. </li> <li> <pre class="lang-js"><code>V (y)+</code></pre> Vertical line command specifies only a y value for a straight vertical line. </li> <li> <pre class="lang-js"><code>Q (x1 y1 x y)+</code></pre> Quadratic Bezier Curves. <code>x1</code>, <code>y1</code> is the control point. See <a href="https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands">SVG Quadratic Bezier command</a> for more details. </li> <li> <pre class="lang-js"><code>T (x y)+</code></pre> Short-hand Quadratic Bezier Curves. The control point is calculated based on <a href="https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands">SVG's path rules.</a> </li> <li> <pre class="lang-js"><code>C (x1 y1 x2 y2 x y)+</code></pre> Cubic Bezier Curves. <code>x1</code>, <code>y1</code> and <code>x2</code>, <code>y2</code> are the control points. See <a href="https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands">SVG Cubic Bezier command</a> for more details. </li> <li> <pre class="lang-js"><code>S (x2 y2 x y)+</code></pre> Short-hand Cubic Bezier Curves. The two control points are calculated based on <a href="https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands">SVG's path rules.</a> </li> <li> <pre class="lang-js"><code>A (rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</code></pre> Elliptical Arcs. These follow the <a href="https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands">SVG arc conventions</a>. </li> <li> <pre class="lang-js"><code>Z</code></pre> <code>Z</code> denotes that the current segment is closed. This is placed after the last segment of a subpath. There are no parameters, and case does not matter with this command. </li> </ul> <hr /> <p>For detailed information on the SVG path strings, see the <a href="https://www.w3.org/TR/SVG/paths.html">W3C's page on SVG Paths</a>.</p> <hr /> <p>Additionally there are some tokens specific to <b>GoJS</b>:</p> <ul style="padding-left: 0px; list-style: none"> <li> <pre class="lang-js"><code>B (startAngle, sweepAngle, centerX, centerY, radiusX, radiusY) </code></pre> Arcs following <b>GoJS</b> canvas arc convention. These arcs create a new line from the last point in the subpath to the first point of an arc defined by the five arguments. Unlike all other commands with parameters, multiple sets of parameters are not allowed for B-arcs. </li> <li> <pre class="lang-js"><code>X</code></pre> Used before <code>M</code> commands to denote separate PathFigures instead of a subpath. There are no parameters, and case does not matter with this command. Separate PathFigures are important when different fills are desired per figure component. </li> <li> <pre class="lang-js"><code>F</code></pre> <pre class="lang-js"><code>F0</code></pre> The existence of this command specifies whether the current PathFigure is filled (true if <code>F</code> is present). <code>F0</code> specifies a fill with the even-odd rule (setting <a>PathFigure.isEvenOdd</a>) instead of the default non-zero winding number rule. <code>F1</code> is a synonym of <code>F</code>. This is placed at the beginning of a figure. Case does not matter with this command. </li> <li> <pre class="lang-js"><code>U</code></pre> The existence of this command specifies whether the current PathFigure is shadowed (<strong>false</strong> if <code>U</code> is present. A shadowed PathFigure is the default). Shadows on shapes (and therefore PathFigures) only exist if <a>Part.isShadowed</a> is set to true on the containing part. This is placed at the beginning of a figure. Case does not matter with this command. </li> </ul> <h2 id="GeometryPathStringExamples">Geometry Path String Examples</h2> <p>Here is a simple usage of a geometry path string when initializing a <a>Shape</a> without setting <a>Shape.figure</a>:</p> <pre class="lang-js" id="s1"><code> diagram.add( new go.Node() .add( new go.Shape({ geometryString: "F M120 0 L80 80 0 50z", fill: "lightgreen" }) )); </code></pre> <script> goCode('s1', 600, 140); </script> <p>Here is a geometry path string that uses quadratic Bezier curves:</p> <pre class="lang-js" id="s2"><code> diagram.add( new go.Node() .add( new go.Shape({ geometryString: "F M0 0 L100 0 Q150 50 100 100 L0 100 Q50 50 0 0z", fill: "lightgreen" }) )); </code></pre> <script> goCode('s2', 600, 140); </script> <p>This geometry uses <b>GoJS</b> arcs:</p> <pre class="lang-js" id="s3"><code> diagram.add( new go.Node("Spot") .add( new go.Shape({ geometryString: "F M0 0 L80 0 B-90 90 80 20 20 20 L100 100 20 100 B90 90 20 80 20 20z", fill: "lightgreen" }), new go.TextBlock("custom shape") )); </code></pre> <script> goCode('s3', 600, 140); </script> <p> The following geometry uses <b>GoJS</b> arcs. Because the <a>Shape</a> is stretched to fit around the <a>TextBlock</a>, and because the default value of <a>Shape.geometryStretch</a> causes the <a>Geometry</a> to be stretched too, the custom geometry is also stretched to fit around the text. </p> <pre class="lang-js" id="s4"><code> diagram.add( new go.Node("Auto") .add( new go.Shape({ geometryString: "F M0 0 L.8 0 B-90 90 .8 .2 .2 .2 L1 1 .2 1 B90 90 .2 .8 .2 .2z", fill: "lightgreen" }), new go.TextBlock("custom shape", { margin: 4 }) )); </code></pre> <script> goCode('s4', 600, 140); </script> <p> In the following Diagram we use a path string that contains three PathFigures. Note the <code>X</code> commands separating the figures and the <code>F</code> commands denoting fill. </p> <pre class="lang-js" id="a"><code> diagram.add( new go.Part() .add( new go.Shape({ geometryString: "F M 0 0 l 30,30 10,10 35,0 0,-35 x m 50 0 l 0,-50 10,0 35,35 x" + "f m 50 0 l 0,-50 10,0 35,35z", strokeWidth: 10, stroke: "lightblue", fill: "gray" }) )); </code></pre> <script> goCode('a', 600, 140); </script> The first two PathFigures are open; the first and third figures are filled. The <code>Z</code> command only closes the PathFigure that it ends. <p> In the following Diagram we use a path string that contains four PathFigures, two of which have a shadow. Note that figures are shadowed by default if the containing Part has <a>Part.isShadowed</a> set to true. To un-shadow specific path figures we use the <code>U</code> command. </p> <pre class="lang-js" id="a2"><code> diagram.add( new go.Part({ isShadowed: true, shadowOffset: new go.Point(10, 10) }) .add( new go.Shape({ geometryString: "F M 0 0 l 30,30 10,10 35,0 0,-35 x u m 50 0 l 0,-50 10,0 35,35 x" + "u f m 50 0 l 0,-50 10,0 35,35z x m 70 0 l 0,30 30,0 5,-35z", strokeWidth: 8, stroke: "lightblue", fill: "lightcoral" }) )); </code></pre> <script> goCode('a2', 600, 140); </script> The first and last PathFigures are shadowed; the second and third are unshadowed. <h3 id="EvenOdd">Even Odd</h3> <pre class="lang-js" id="even-odd"><code> diagram.add( new go.Part() .add( new go.Shape({ geometryString: "F M 0 100 L 100 100 100 30 20 30 20 50 70 50 70 80 40 80 40 0 0 0z", strokeWidth: 2, stroke: "black", fill: "lightcoral" }) )); diagram.add( new go.Part() .add( new go.Shape({ geometryString: "F0 M 0 100 L 100 100 100 30 20 30 20 50 70 50 70 80 40 80 40 0 0 0z", strokeWidth: 2, stroke: "black", fill: "lightcoral" }) )); </code></pre> <script> goCode('even-odd', 600, 140); </script> <p> Use <code>F</code> to fill with the (default) non-zero winding number rule, or <code>F0</code> to fill with the even-odd <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule">fill rule</a>. </p> <h3 id="GeometryParse">Geometry.parse</h3> <p>Use the static function <a>Geometry.parse</a> to convert a <b>GoJS</b> syntax path string into a <a>Geometry</a>.</p> <pre class="lang-js" id="s11"><code> diagram.add( new go.Node("Horizontal") .add( new go.TextBlock("Custom Triangle:"), new go.Shape({ geometry: go.Geometry.parse("M120 0 L80 80 0 50z"), // Geometry is not filled fill: "green", background: "whitesmoke", stroke: "orange", strokeWidth: 2 }) )); </code></pre> <script> goCode('s11', 600, 140); </script> <p> Note that even though a <a>Shape.fill</a> is specified, the shape does not appear filled. This is because the geometry's one <a>PathFigure</a> is not declared to be filled -- there is no <code>F</code> command. Importing SVG path strings that are filled also requires declaring that the geometry is filled. There are several ways to do that: </p> <ul> <li> Call <a>Geometry.fillPath</a> for converting the SVG path string to <b>GoJS</b> syntax before calling <a>Geometry.parse</a>. For literal SVG path strings it is often easiest just to prefix it with "F ". </li> <li>Call <a>Geometry.parse</a> with a second argument that is true.</li> <li>Modify the <a>Geometry</a> returned by <a>Geometry.parse</a>, by setting <a>PathFigure.isFilled</a> to true on the desired PathFigures.</li> </ul> <p>Here is the same example, but using a filled geometry path string.</p> <pre class="lang-js" id="s11a"><code> diagram.add( new go.Node("Horizontal") .add( new go.TextBlock("Custom Triangle:"), new go.Shape({ geometry: go.Geometry.parse("F M120 0 L80 80 0 50z"), // Geometry is filled fill: "green", background: "whitesmoke", stroke: "orange", strokeWidth: 2 }) )); </code></pre> <script> goCode('s11a', 600, 140); </script> <p> All Geometry objects have bounds that contain the origin, so a geometry created with no points at x==0 or y==0 will have extra space to the left of it or above it. Note how there is extra space in the following node, causing the shape to appear farther away from the text and shifted down: </p> <pre class="lang-js" id="s12"><code> diagram.add( new go.Node("Horizontal") .add( new go.TextBlock("Custom Triangle:"), new go.Shape({ geometry: go.Geometry.parse("M120 50 L80 80 50 50z", true), // Geometry is filled fill: "green", background: "whitesmoke", stroke: "orange", strokeWidth: 2 }) )); </code></pre> <script> goCode('s12', 600, 140); </script> <p> Often when importing SVG shapes created by drawing applications into <b>GoJS</b> we do not want any extra space above or to the left, so we need to normalize the geometry. There is a function for this, <a>Geometry.normalize</a>, which modifies the Geometry's points in-place and returns a Point describing the amount they were offset. </p> <pre class="lang-js" id="s12a"><code> const geo = go.Geometry.parse("M120 50 L80 80 50 50z", true); geo.normalize(); diagram.add( new go.Node("Horizontal") .add( new go.TextBlock("Custom Triangle:"), new go.Shape({ geometry: geo, // normalized above fill: "green", background: "whitesmoke", stroke: "orange", strokeWidth: 2 }) )); </code></pre> <script> goCode('s12a', 600, 140); </script> <h3 id="ShapeGeometryString">Shape.geometryString</h3> <p> The <a>Shape.geometryString</a> property setter parses a given <b>GoJS</b> path string as a Geometry, normalizes it, sets the <a>Shape.geometry</a> to this new Geometry, and offsets the Shape's position by the amount it was shifted in normalization. The positioning is useful when the shape is inside a <a>Panel.Position</a> panel. But when the shape is used in any other kind of panel (thus ignoring the <a>GraphObject.position</a>), it is still useful to remove the extra space so that the shape fits in well with the other objects in the panel. </p> <p> The example below adds three Parts with Shapes to the diagram. The first shape uses <a>Geometry.parse</a> to set the Shape's Geometry, the second one uses <a>Geometry.parse</a> and <a>Geometry.normalize</a>. The third uses <a>Shape.geometryString</a>. Note the difference in size between the first Part and the other two. </p> <pre class="lang-js" id="b"><code> const pathstring = "M30 100 C 50 50, 70 20, 100 100, 110, 130, 45, 150, 65, 100"; // Just parsing the geometry diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometry: go.Geometry.parse(pathstring), strokeWidth: 10, stroke: "lightcoral", background: "whitesmoke" }), new go.TextBlock("parse") )); // Parsing the geometry and normalizing it const geo = go.Geometry.parse(pathstring); geo.normalize(); diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometry: geo, strokeWidth: 10, stroke: "lightgreen", background: "whitesmoke" }), new go.TextBlock("parse/normalize") )); // Using geometryString to parse and normalize the geometry diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometryString: pathstring, strokeWidth: 10, stroke: "lightblue", background: "whitesmoke" }), new go.TextBlock("geometryString") )); diagram.layout = new go.GridLayout(); // Select them all to more easily see their sizes diagram.commandHandler.selectAll(); </code></pre> <script> goCode('b', 600, 180); </script> <h2 id="FlippingGeometriesHorizontallyAndVertically">Flipping Geometries Horizontally and Vertically</h2> <p> GoJS Geometries have several methods for modifying the geometry's points by a transformation matrix. We can use these methods to flip or mirror the geometries if needed. </p> <p><code>geometry.scale(-1, 1)</code> will flip a geometry horizontally. <code>geometry.scale(1, -1)</code> will flip a geometry vertically.</p> <pre class="lang-js" id="b2"><code> const pathstring = "M30 100 C 50 50, 70 20, 100 100, 110, 130, 45, 150, 65, 100"; const geo = go.Geometry.parse(pathstring); geo.normalize(); diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometry: geo, strokeWidth: 10, stroke: "lightgreen", background: "whitesmoke" }), new go.TextBlock("geometry from string\n(normalized)") )); const geo2 = geo.copy(); geo2.scale(-1, 1); // flips a geometry horizontally diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometry: geo2, strokeWidth: 10, stroke: "lightgreen", background: "whitesmoke" }), new go.TextBlock("flipped horizontally") )); const geo3 = geo.copy(); geo3.scale(1, -1); // flips a geometry vertically diagram.add( new go.Part("Vertical") .add( new go.Shape({ geometry: geo3, strokeWidth: 10, stroke: "lightgreen", background: "whitesmoke" }), new go.TextBlock("flipped vertically") )); diagram.layout = new go.GridLayout(); </code></pre> <script> goCode('b2', 600, 180); </script> <h2 id="ConvertingPathStrings">Converting Path Strings</h2> <p> The static method <a>Geometry.stringify</a> can be used to output a Geometry as a string. This string will have the <b>GoJS</b> path string syntax. You can use Geometry.stringify and Geometry.parse to data bind custom shape geometries. </p> <p> <code>Geometry.parse(Geometry.stringify(myGeometry))</code> will return a geometry equal to <code>myGeometry</code>, though if myGeometry was created from a string, the string itself is not guaranteed to be the same. If you merely want to copy a Geometry you should use <a>Geometry.copy</a>. </p> <p></p> <pre class="lang-js"><code> // These path strings represent identical geometries: const a = "m0 0 t 50 50, q 40 20, 50 10 h 10 v -23 l 45, 5, 65, 100" const b = "M0 0 Q0 0 50 50 Q90 70 100 60 L110 60 L110 37 L155 42 L220 142" go.Geometry.stringify(Geometry.parse(a)); // returns the string in b go.Geometry.stringify(Geometry.parse(b)); // returns the string in b </code></pre> <p>Because of the additional non-SVG commands, a string generated from <a>Geometry.stringify</a> will not necessarily be a valid SVG path.</p> <p> The static method <a>Geometry.fillPath</a> takes a path string of either syntax and adds <code>F</code> tokens before each PathFigure that does not have them. Because SVG path strings are not considered to be "filled" by themselves, if you are converting an SVG Path shape to <b>GoJS</b> you will want to call <a>Geometry.fillPath</a> on the SVG string. </p> <pre class="lang-js"><code> go.Geometry.fillPath("M0 0 L20 20 L20 0"); // returns "F M0 0 L20 20 L20 0" </code></pre> The result can then be passed to <a>Geometry.parse</a> or <a>Shape.geometryString</a>. <h2 id="ParameterizedGeometries">Parameterized Geometries</h2> <p> Although individual <a>Geometry</a> objects cannot be dynamically parameterized based on the intended size or other properties, the <a>Shape</a> class does support such parameterization via <a>Shape.defineFigureGenerator</a>. When you set or bind the <a>Shape.figure</a> property, the shape will call the named figure generator to generate a Geometry appropriate for the desired width and height and other Shape properties. </p> <p> You can see the definitions of all of the predefined figures in the extensions file: <a href="../extensions/Figures.js" target="_blank">Figures.js</a>. </p> </div> </div> <footer class="bg-white text-gray-900 border-t border-t-gray-200"> <div class="w-full max-w-screen-lg mx-auto px-4 py-6"> <p id="version" class="text-xs text-gray-900 m-0"></p> <div class="text-sm px-0 mb-4 grid grid-cols-2 sm:grid-cols-3 gap-y-10"> <div> <h2 class="text-base font-semibold text-nwoods-primary">GoJS</h2> <ul class="list-none space-y-4 md:space-y-1 px-0"> <li> <a href="../samples/index.html">Samples</a> </li> <li> <a href="../learn/index.html">Learn</a> </li> <li> <a href="../intro/index.html">Intro</a> </li> <li> <a href="../api/index.html">API</a> </li> <li> <a href="../changelog.html">Changelog</a> </li> <li> <a href="https://github.com/NorthwoodsSoftware/GoJS" target="_blank" rel="noopener">GitHub</a> </li> </ul> </div> <div> <h2 class="text-base font-semibold text-nwoods-primary">Support</h2> <ul class="list-none space-y-4 md:space-y-1 px-0"> <li> <a href="https://nwoods.com/contact.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a> </li> <li> <a href="https://forum.nwoods.com/c/gojs" target="_blank" rel="noopener">Forum</a> </li> <li> <a href="https://nwoods.com/app/activate.aspx?sku=gojs" target="_blank" rel="noopener">Activate</a> </li> <li> <a href="https://nwoods.com/sales/index.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a> </li> <li> <a href="https://nwoods.com/register.html" target="_blank" rel="noopener">Register</a> </li> </ul> </div> <div> <h2 class="text-base font-semibold text-nwoods-primary">Company</h2> <ul class="list-none space-y-4 md:space-y-1 px-0"> <li> <a target="_blank" href="https://nwoods.com" target="_blank" rel="noopener">Northwoods</a> </li> <li> <a target="_blank" href="https://nwoods.com/about.html" target="_blank" rel="noopener">About Us</a> </li> <li> <a target="_blank" href="https://nwoods.com/contact.html" target="_blank" rel="noopener">Contact Us</a> </li> <li> <a target="_blank" href="https://nwoods.com/consulting.html" target="_blank" rel="noopener">Consulting</a> </li> <li> <a target="_blank" href="https://twitter.com/northwoodsgo" target="_blank" rel="noopener">Twitter</a> </li> </ul> </div> </div> <p class="text-sm text-gray-900 md:mb-6"> Copyright 1998-2025 <a href="https://nwoods.com">Northwoods Software</a> </p> </div> </footer> </body> <script async src="https://www.googletagmanager.com/gtag/js?id=G-S5QK8VSK84"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'G-S5QK8VSK84'); var getOutboundLink = function (url, label) { gtag('event', 'click', { 'event_category': 'outbound', 'event_label': label, 'transport_type': 'beacon' }); } const params = new URL(document.location).searchParams let a = params.get('a'); if (a) localStorage.setItem('a', a); a = localStorage.getItem('a'); if (a) { const links = [...document.body.getElementsByTagName("a")].filter((l) => l.href.includes('nwoods.com')); for (const l of links) { const url = new URL(l.href); url.searchParams.set('a', a); l.href = url; } } </script> <script src="../assets/js/prism.js"></script> <script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script> <script src="../assets/js/goDoc.js"></script> <script> document.addEventListener("DOMContentLoaded", function () { if (window.go) document .getElementById('version') .textContent = "GoJS version " + go.version; if (window.goDoc) window.goDoc(); var d = window.diagrams; for (var i = 0; i < d.length; i++) { var dargs = d[i]; goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]); } if (window.extra) window.extra(); } ); </script> </html>