UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

367 lines (315 loc) 15.3 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="An interactive GoJS Diagram demonstrating viewports and document bounds and alignment and scaling." /> <meta itemprop="description" content="An interactive GoJS Diagram demonstrating viewports and document bounds and alignment and scaling." /> <meta property="og:description" content="An interactive GoJS Diagram demonstrating viewports and document bounds and alignment and scaling." /> <meta name="twitter:description" content="An interactive GoJS Diagram demonstrating viewports and document bounds and alignment and scaling." /> <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="Content Alignment Demonstration" /> <meta property="og:title" content="Content Alignment Demonstration" /> <meta name="twitter:title" content="Content Alignment Demonstration" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/contentalign.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/contentalign.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/contentalign.png" /> <meta property="og:url" content="https://gojs.net/latest/samples/contentAlign.html" /> <meta property="twitter:url" content="https://gojs.net/latest/samples/contentAlign.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Content Alignment Demonstration | GoJS Diagramming Library </title> </head> <body> <!-- This top nav is not part of the sample code --> <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="flex flex-col prose"> <div class="w-full max-w-screen-xl mx-auto"> <!-- * * * * * * * * * * * * * --> <!-- Start of GoJS sample code --> <script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script> <div id="allSampleContent" class="p-4 w-full"> <script id="code"> function init() { myDiagram = new go.Diagram('myDiagramDiv', { 'undoManager.isEnabled': true }); for (var i = 0; i < 15; i++) { myDiagram.add( // add an unbound Node to the diagram at a random position new go.Node({ position: new go.Point(Math.random() * 251, Math.random() * 251) }) .add( new go.Shape('Circle', { fill: go.Brush.randomColor(150), strokeWidth: 2, desiredSize: new go.Size(30, 30) }) ) ); } // automatically update information in the panel myDiagram.addDiagramListener('DocumentBoundsChanged', updateDOM); myDiagram.addDiagramListener('ViewportBoundsChanged', updateDOM); var myPosX = document.getElementById('positionX'); var myPosY = document.getElementById('positionY'); var myScale = document.getElementById('scale'); var myDocBounds = document.getElementById('docBounds'); function updateDOM(e) { var d = e.diagram; var pos = d.position; myPosX.value = Math.round(pos.x, 2); myPosY.value = Math.round(pos.y, 2); myScale.value = d.scale; var b = d.documentBounds; myDocBounds.textContent = b.x.toFixed(2) + ', ' + b.y.toFixed(2) + ' ' + b.width.toFixed(2) + ' x ' + b.height.toFixed(2); } } // disable all inputs and buttons in the specified element function setDisabled(elem, isDisabled) { for (let c of elem.children) { if (c.tagName === 'INPUT' || c.tagName === 'BUTTON') { c.disabled = !!isDisabled; } } } // occurs when one of the contentAlign radio buttons is clicked function changeContentAlign(spot) { myDiagram.startTransaction(''); myDiagram.contentAlignment = go.Spot[spot]; myDiagram.commitTransaction(''); setDisabled(document.getElementById('posP'), spot !== 'None'); } function changePosition(posx, posy) { myDiagram.startTransaction(''); var x = parseInt(posx); var y = parseInt(posy); myDiagram.position = new go.Point(x, y); myDiagram.commitTransaction(''); } function changeScale(scale) { var scale = parseFloat(scale); if (scale > 0) { myDiagram.startTransaction(''); myDiagram.scale = scale; myDiagram.commitTransaction(''); } } function changeFixedBounds(fx, fy, fw, fh) { myDiagram.startTransaction(''); var x = parseFloat(fx); var y = parseFloat(fy); var h = parseFloat(fw); var w = parseFloat(fh); myDiagram.fixedBounds = new go.Rect(x, y, Math.max(1, w), Math.max(1, h)); myDiagram.commitTransaction(''); } function changePadding(pt, pr, pb, pl) { myDiagram.startTransaction(''); var t = parseFloat(pt); var r = parseFloat(pr); var b = parseFloat(pb); var l = parseFloat(pl); myDiagram.padding = new go.Margin(t, r, b, l); myDiagram.commitTransaction(''); } function changeAutoScale(scaleType) { myDiagram.startTransaction(''); myDiagram.autoScale = go.Diagram[scaleType]; myDiagram.commitTransaction(''); setDisabled(document.getElementById('scaleP'), scaleType !== 'None'); } window.addEventListener('DOMContentLoaded', init); </script> <div id="sample"> <div style="width: 100%; display: flex;flex-direction: row;flex-wrap: wrap; gap: 5px;"> <div style="flex: 1;min-width: 330px;"> <div id="myDiagramDiv" style="height: 400px; background: whitesmoke; border: solid 1px black"></div> </div> <div style="flex: 1; min-width: 330px;"> <div style="border: solid 1px black; padding: 5px"> Diagram.documentBounds: <div id="docBounds" style="display: inline-block"></div> <p id="alignP"> Diagram.contentAlignment:<br /> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="None" checked /><label for="None">None</label> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="Center" /><label for="Center">Center</label><br /> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="Left" /><label for="Left">Left</label> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="Right" /><label for="Right">Right</label><br /> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="Top" /><label for="Top">Top</label> <input type="radio" name="contentAlign" onclick="changeContentAlign(this.id)" id="Bottom" /><label for="Bottom">Bottom</label><br /> </p> <p id="posP"> Diagram.position:<br /> <input type="text" size="3" id="positionX" value="NaN" /> <input type="text" size="3" id="positionY" value="NaN" /> <button onclick="changePosition(positionX.value, positionY.value)">Set</button> </p> <p id="scaleP"> Diagram.scale:<br /> <input type="text" size="3" id="scale" value="1" /> <button onclick="changeScale(scale.value)">Set</button> <button onclick="scale.value=1;changeScale(scale.value)">Reset</button> </p> <p id="fixedP"> Diagram.fixedBounds (x, y, width, height):<br /> <input type="text" size="3" id="fixedX" value="NaN" /> <input type="text" size="3" id="fixedY" value="NaN" /> <input type="text" size="3" id="fixedW" value="NaN" /> <input type="text" size="3" id="fixedH" value="NaN" /> <button id="fixedSet" onclick="changeFixedBounds(fixedX.value, fixedY.value, fixedW.value, fixedH.value)">Set</button> <button onclick="fixedX.value=NaN;fixedY.value=NaN;fixedW.value=NaN;fixedH.value=NaN;fixedSet.onclick()">Reset</button> </p> <p id="padP"> Diagram.padding (top, right, bottom, left):<br /> <input type="text" size="3" id="padT" value="5" /> <input type="text" size="3" id="padR" value="5" /> <input type="text" size="3" id="padB" value="5" /> <input type="text" size="3" id="padL" value="5" /> <button onclick="changePadding(padT.value, padR.value, padB.value, padL.value)">Set</button> </p> <p id="autoP"> Diagram.autoScale:<br /> <input type="radio" name="autoScale" onclick="changeAutoScale(this.value)" id="DiagramNone" value="None" checked /><label for="DiagramNone" >AutoScale.None</label ><br /> <input type="radio" name="autoScale" onclick="changeAutoScale(this.id)" id="Uniform" /><label for="Uniform">AutoScale.Uniform</label><br /> <input type="radio" name="autoScale" onclick="changeAutoScale(this.id)" id="UniformToFill" /><label for="UniformToFill">AutoScale.UniformToFill</label ><br /> (but no greater than CommandHandler.defaultScale) </p> <button onclick="myDiagram.commandHandler.zoomToFit()">Zoom to Fit</button> </div> </div> </div> <p> A Diagram's <a>Diagram.contentAlignment</a> property determines how parts are positioned when the <a>Diagram.viewportBounds</a> width or height is different than the <a>Diagram.documentBounds</a> width or height. </p> <p> <a>Diagram.position</a> changes where in the document the view port is located. This means that <a>Diagram.position</a> is always equal to <a>Diagram.viewportBounds</a> x and y. </p> <p> <a>Diagram.scale</a> changes how zoomed in/out the diagram is. </p> <p> <a>Diagram.fixedBounds</a> changes the bound returned by <a>Diagram.documentBounds</a>, by default this is <code>NaN, NaN, NaN, NaN</code> meaning that <a>Diagram.documentBounds</a> returns <a>Diagram.computeBounds</a>. </p> <p> <a>Diagram.padding</a> is the extra space between the nodes and the edge of the canvas. </p> <p> <a>Diagram.autoScale</a> automatically sets the <a>Diagram.scale</a> and <a>Diagram.position</a> of the diagram to fit the document bounds inside the view. <a>AutoScale.Uniform</a> will fit the document to the view. <a>AutoScale.UniformToFill</a> will scale and position the diagram such that in on direction it fits the view, and the other requires a scroll bar. </p> </div> </div> <!-- * * * * * * * * * * * * * --> <!-- End of GoJS sample code --> </div> <div id="allTagDescriptions" class="p-4 w-full max-w-screen-xl mx-auto"> <hr/> <h3 class="text-xl">GoJS Features in this sample</h3> <!-- blacklist tags that do not correspond to a specific GoJS feature --> <h4>HTML Interaction</h4> <p> GoJS Diagrams can be used alongside other HTML elements in a webapp. For custom Text Editors, Context Menus, and ToolTips, which are invoked and hidden via GoJS tool operations, it is best to use the <a href="../api/symbols/HTMLInfo.html" target="api">HTMLInfo</a> class. </p> <p> More information can be found in the <a href="../intro/HTMLinteraction.html">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#html">Related samples</a> </p> <hr> </div> </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>