UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

734 lines (647 loc) 39.8 kB
<!DOCTYPE html> <html lang="en"> <head> <!-- You do not need this import map in your own code if you are installing gojs via a package manager --> <script type="importmap"> { "imports": { "gojs": "https://cdn.jsdelivr.net/npm/gojs@3.1.0/release/go-module.js" } } </script> <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="TypeScript: Arrange nodes into rectangular or elliptical areas, ignoring any links." /> <meta itemprop="description" content="TypeScript: Arrange nodes into rectangular or elliptical areas, ignoring any links." /> <meta property="og:description" content="TypeScript: Arrange nodes into rectangular or elliptical areas, ignoring any links." /> <meta name="twitter:description" content="TypeScript: Arrange nodes into rectangular or elliptical areas, ignoring any links." /> <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="Packed Layout for Packing Nodes into an Area" /> <meta property="og:title" content="Packed Layout for Packing Nodes into an Area" /> <meta name="twitter:title" content="Packed Layout for Packing Nodes into an Area" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/packedlayout.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/packedlayout.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/packedlayout.png" /> <meta property="og:url" content="https://gojs.net/latest/samples/PackedLayout.html" /> <meta property="twitter:url" content="https://gojs.net/latest/samples/PackedLayout.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Packed Layout for Packing Nodes into an Area | 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 --> <link rel="stylesheet" href="../assets/css/prism.css"/> <script src="../assets/js/prism.js"></script> <div id="allSampleContent" class="p-4 w-full"> <script type="module" id="code"> import * as go from 'gojs'; import { PackedLayout, PackMode, PackShape, SortMode, SortOrder } from '../extensionsJSM/PackedLayout.js'; var myDiagram; function init() { myDiagram = new go.Diagram('myDiagramDiv', { // must be the ID or reference to div 'animationManager.isEnabled': true, layout: new PackedLayout(), scale: 0.75, isReadOnly: true }); myDiagram.nodeTemplate = new go.Node('Auto') .bind('visible') .add( new go.Shape({ strokeWidth: 0 }) .bind('figure') .bind('width') .bind('height') .bind('fill') ); myDiagram.model = new go.GraphLinksModel([]); buildSettingsMenu(); rebuildGraph(); layout(); } function layout(change = false) { myDiagram.startTransaction('change Layout'); var lay = myDiagram.layout; var d = document; disable('aspectRatio', false); disable('width', false); disable('height', false); disable('spacing', false); disable('hasCircularNodes', false); var code = 'new PackedLayout({' var packShape = d.getElementById('packShape').value; if (packShape === 'Elliptical') lay.packShape = PackShape.Elliptical; else if (packShape === 'Rectangular') lay.packShape = PackShape.Rectangular; else if (packShape === 'Spiral') { lay.packShape = PackShape.Spiral; disable('aspectRatio', true); disable('width', true); disable('height', true); disable('hasCircularNodes', true); d.getElementById('hasCircularNodes').value = 'Circle'; change = true; } if (packShape != d.getElementById('packShape').name) code += `\n packShape: go.PackShape.${packShape},` var packMode = d.getElementById('packMode').value.split(/\s+/).join(''); if (packMode === 'AspectRatio') {lay.packMode = PackMode.AspectOnly; disable('width', true); disable('height', true);} else if (packMode === 'ExpandtoFit') {lay.packMode = PackMode.ExpandToFit; disable('aspectRatio', true); disable('spacing', true); } else if (packMode === 'Fit') {lay.packMode = PackMode.Fit; disable('aspectRatio', true);} if (packMode != d.getElementById('packMode').name.split(/\s+/).join('')) code += `\n packMode: go.PackMode.${packMode},` var sortOrder = d.getElementById('sortOrder').value; if (sortOrder === 'Descending') lay.sortOrder = SortOrder.Descending; else if (sortOrder === 'Ascending') lay.sortOrder = SortOrder.Ascending; if (sortOrder != d.getElementById('sortOrder').name) code += `\n sortOrder: go.SortOrder.${sortOrder},` var sortMode = d.getElementById('sortMode').value.split(/\s+/).join(''); if (sortMode === 'None') lay.sortMode = SortMode.None; else if (sortMode === 'MaxSide') lay.sortMode = SortMode.MaxSide; else if (sortMode === 'Area') lay.sortMode = SortMode.Area; if (sortMode != d.getElementById('sortMode').name.split(/\s+/).join('')) code += `\n sortMode: go.SortMode.${sortMode},` var aspectRatio = d.getElementById('aspectRatio').value; lay.aspectRatio = parseFloat(aspectRatio); if ((d.getElementById('aspectRatio').name != aspectRatio) && (packShape !== 'Spiral') && (packMode === 'AspectRatio')) code += `\n aspectRatio: ${aspectRatio},` var layoutWidth = d.getElementById('width').value; var layoutHeight = d.getElementById('height').value; lay.size = new go.Size(parseFloat(layoutWidth), parseFloat(layoutHeight)); if (((d.getElementById('width').name !== layoutWidth) || (d.getElementById('height').name !== layoutHeight)) && (packShape !== 'Spiral') && (packMode !== 'AspectRatio')) code += `\n size: new go.Size(${layoutWidth}, ${layoutHeight}),` var spacing = d.getElementById('spacing').value; lay.spacing = parseFloat(spacing); if ((d.getElementById('spacing').name != spacing) && (packMode !== 'ExpandtoFit')) code += `\n spacing: ${spacing},` var hasCircularNodes = (d.getElementById('hasCircularNodes').value === 'Circle'); lay.hasCircularNodes = hasCircularNodes; if (hasCircularNodes) code += `\n hasCircularNodes: ${hasCircularNodes},` if (code === 'new PackedLayout({') code = 'new PackedLayout()'; // If no changes made to layout else code = code.slice(0, -1) + '\n})'; // Removes last comma and adds closing bracket d.getElementById('layoutBuilder').textContent = code; if (window.Prism) window.Prism.highlightAll(); myDiagram.commitTransaction('change Layout'); myDiagram.zoomToFit(); if (change) rebuildGraph(); } function disable(element, bool) { document.getElementById(element + 'Row').style.opacity = (bool)? 0.5 : 1; document.getElementById(element + 'Row').style.pointerEvents = (bool)? 'none' : 'auto'; } function rebuildGraph() { var numNodes = document.getElementById('numNodes').value; numNodes = parseInt(numNodes, 10); var minSide = document.getElementById('nodeMinSide').value; minSide = parseInt(minSide, 10); var maxSide = document.getElementById('nodeMaxSide').value; maxSide = parseInt(maxSide, 10); var sameSides = false; var shape = document.getElementById('hasCircularNodes').value; if (shape === 'Ellipse') {shape = 'Ellipse'} else if (shape === 'Rectangle') {shape = 'Rectangle'} else if (shape === 'Square') {shape = 'Rectangle'; sameSides = true;} else if (shape === 'Circle') {shape = 'Ellipse'; sameSides = true;} generateNodeData(numNodes, minSide, maxSide, shape, sameSides); myDiagram.zoomToFit(); } function generateNodeData(numNodes, min, max, shape, sameSides) { var nodeArray = []; for (var i = 0; i < numNodes; i++) { var height = min + (Math.random()* (max - min)); var width = min + (Math.random()* (max - min)); if (sameSides) height = width; nodeArray.push({ key: i, figure: shape, fill: go.Brush.randomColor(), width: width, height: height }); } for (i = 0; i < nodeArray.length; i++) { var swap = Math.floor(Math.random() * nodeArray.length); var temp = nodeArray[swap]; nodeArray[swap] = nodeArray[i]; nodeArray[i] = temp; } myDiagram.model.nodeDataArray = nodeArray; } function buildSettingsMenu() { buildButtonRow('aspectRatio', 0.05, 1.00, 'Aspect Ratio', 'table1', 0.1, 100, 2); buildButtonRow('width', 50, 600, 'Layout Width', 'table1', 0); buildButtonRow('height', 50, 600, 'Layout Height', 'table1', 0); buildButtonRow('spacing', 10, 0, 'Spacing', 'table1'); buildDropdown('packShape', 'Pack Shape', 'table2', ['Elliptical', 'Rectangular', 'Spiral']) buildDropdown('packMode', 'Pack Mode', 'table2', ['Aspect Ratio', 'Expand to Fit', 'Fit']) buildDropdown('sortOrder', 'Sort Order', 'table2', ['Descending', 'Ascending']) buildDropdown('sortMode', 'Sort Mode', 'table2', ['None', 'Max Side Length', 'Area']) document.querySelectorAll('.info').forEach(element => { element.addEventListener('mouseover', () => { iframe(element); }) element.addEventListener('mouseout', () => { document.getElementById('frame').style.display = 'none'; document.getElementById('description').innerHTML = ''; }) }) } function changeNodes(max, value) { var e = document; if (max) { e.getElementById('nodeMaxSide').value = Math.max(e.getElementById('nodeMaxSide').value - -value, 1); } else { e.getElementById('nodeMinSide').value = Math.max(e.getElementById('nodeMinSide').value - -value, 1); } if (parseInt(e.getElementById('nodeMinSide').value) > parseInt(e.getElementById('nodeMaxSide').value)) { (max)? e.getElementById('nodeMinSide').value = e.getElementById('nodeMaxSide').value : e.getElementById('nodeMaxSide').value = e.getElementById('nodeMinSide').value; } } function changeDropdown(element) { element.parentNode.querySelector('.button1').style = (element.value != element.name)? "background-color: lightcoral;" : "background-color: lightgray;"; layout(); } function resetButton(element) { var e = element.parentNode.querySelector('.input'); e.value = e.name; element.style = "background-color: lightgray;"; layout(); } function changeInput(element, change = true) { var e = element.parentNode.querySelector('.inputBox'); var number = change? element.name: number = 0; const max = element.parentNode.querySelector('.maximum').name; const min = element.parentNode.querySelector('.minimum').name; const decimal = element.parentNode.querySelector('.decimal').name; var value = (e.value - -number); if (max !== null) value = Math.min(value, max); if (min !== null) value = Math.max(value, min); e.value = (value).toFixed(((value - value.toFixed(0)) == 0)? 0 : decimal); e.parentNode.querySelector('.button1').style = (e.name == e.value)? "background-color: lightgray;" : "background-color: lightcoral;"; layout(); } function buildButtonRow(id, change, start, title, table, min = null, max = null, decimal = 0) { var template = document.getElementById('buttonRow'); var clone = template.content.cloneNode(true); clone.querySelector('.button3').name = change; clone.querySelector('.button2').name = -change; clone.querySelector('.inputBox').name = start; clone.querySelector('.inputBox').id = id; clone.querySelector('.inputBox').value = start; clone.querySelector('.maximum').name = max; clone.querySelector('.minimum').name = min; clone.querySelector('.decimal').name = decimal; clone.querySelector('.title').textContent = title; clone.querySelector('.row').id = (id + 'Row') document.getElementById(table).appendChild(clone); } function buildDropdown(id, title, table, options) { var template = document.getElementById('dropdown'); var clone = template.content.cloneNode(true); var dropdown = clone.querySelector('.input') dropdown.name = options[0]; dropdown.id = id; clone.querySelector('.title').textContent = title; clone.querySelector('.row').id = (id + 'Row') options.forEach(element => { let option = document.createElement('option'); option.value = element; // Set the value to be the index + 1 option.text = element; // Set the text to be the element from the array dropdown.add(option); }); dropdown.options[0].selected = true; document.getElementById(table).appendChild(clone); } function copyCode() { navigator.clipboard.writeText(document.getElementById('layoutBuilder').textContent); document.getElementById('default').style.display = 'none' document.getElementById('clicked').style.display = 'inline-flex' document.getElementById('copyButton').style.pointerEvents = 'none' setTimeout(() => { document.getElementById('default').style.display = 'inline-flex' document.getElementById('clicked').style.display = 'none' document.getElementById('copyButton').style.pointerEvents = 'auto' }, 1500); } function iframe(element) { var iframe = document.getElementById('apiFrame'); var frame = document.getElementById('frame'); frame.style.display = 'block'; var id = element.parentElement.querySelector('.input').id; if (id === 'width' || id === 'height') id = 'size'; document.getElementById('description').innerHTML = (iframe.contentWindow.document.getElementById(id).parentElement.children[2].firstChild.firstChild.innerHTML); document.getElementById('name').textContent = id; frame.style.left = (element.getBoundingClientRect().left) + 'px'; frame.style.top = (element.getBoundingClientRect().top - 10 + window.pageYOffset) + 'px'; } window.addEventListener('DOMContentLoaded', init); window.layout = layout; window.copyCode = copyCode; window.rebuildGraph = rebuildGraph; window.changeInput = changeInput; window.resetButton = resetButton; window.changeDropdown = changeDropdown; window.changeNodes = changeNodes </script> <script> if (window.location.protocol === 'file:') { alert('For security reasons this page must be served from a web server.'); } </script> <style> .table { display: table; width: 100%; } .row { display: table-row; } .cell { display: table-cell; vertical-align: middle; } .celldif { display: table-cell; } .sampleWrapper { display: flex; flex-direction: column; @media (min-width: 800px) { flex-direction: row; } & > div:first-child { margin-bottom: 0.5rem; @media (min-width: 800px) { margin-right: 0; margin-bottom: 0; } } } .info { display: inline-block; cursor: pointer; } .copyButton:hover { background-color: #e9e9e9 !important; color: #000000 !important; } </style> <template id="buttonRow"> <div class="row tooltip" > <svg onclick="" class="cell info shrink-0 inline w-4 h-4 align-middle" style="margin-right: 2px; margin-bottom: 0px;" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/> </svg> <div class="title cell whitespace-nowrap p-1 select-none" style="font-size: large;"></div> <div class="cell"> <div class="relative flex items-center"> <div class="maximum" ></div> <div class="minimum" ></div> <div class="decimal" ></div> <button type="button" onclick="resetButton(this)" class="button1 rounded-s-lg rounded-e-none h-7 m-0 pr-[2px] pl-[2px]" style="background-color: lightgray;"> <svg fill="#000000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px" viewBox="0 0 528.919 528.919" xml:space="preserve"> <path id="reset" stroke-width="2" d= "M70.846,324.059c3.21,3.926,8.409,3.926,11.619,0l69.162-84.621c3.21-3.926,1.698-7.108-3.372-7.108h-36.723 c-5.07,0-8.516-4.061-7.427-9.012c18.883-85.995,95.625-150.564,187.207-150.564c105.708,0,191.706,85.999,191.706,191.706 c0,105.709-85.998,191.707-191.706,191.707c-12.674,0-22.95,10.275-22.95,22.949s10.276,22.949,22.95,22.949 c131.018,0,237.606-106.588,237.606-237.605c0-131.017-106.589-237.605-237.606-237.605 c-116.961,0-214.395,84.967-233.961,196.409c-0.878,4.994-5.52,9.067-10.59,9.067H5.057c-5.071,0-6.579,3.182-3.373,7.108 L70.846,324.059z"/> </svg> </button> <button type="button" onclick="changeInput(this)" class="button2 bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-none h-7 m-0 pr-[11px] pl-[6px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 2"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h16"/> </svg> </button> <input type="text" onchange="changeInput(this, false)" class="input inputBox bg-gray-50 border-x-1 border-gray-300 h-7 text-center outline-none text-gray-900 text-sm w-10 m-[-4.5px] z-10" required /> <button type="button" onclick="changeInput(this)" class="button3 bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-e-lg h-7 m-0 pr-[7px] pl-[12px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/> </svg> </button> </div> </div> </div> </template> <template id="dropdown"> <div class="row"> <svg onclick="" class="cell info shrink-0 inline w-4 h-4 align-middle" style="margin-top: 17px; margin-right: 3px; margin-left: 4px" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/> </svg> <div class="title cell whitespace-nowrap p-1 select-none pt-4"></div> <div class="cell pt-4"> <div class="relative flex"> <button type="button" onclick="resetButton(this)" class="button1 rounded-s-lg rounded-e-none h-8.1 m-0 pr-[2px] pl-[2px] align-middle" style="background-color: lightgray;"> <svg fill="#000000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px" viewBox="0 0 528.919 528.919" xml:space="preserve"> <path id="reset" stroke-width="2" d= "M70.846,324.059c3.21,3.926,8.409,3.926,11.619,0l69.162-84.621c3.21-3.926,1.698-7.108-3.372-7.108h-36.723 c-5.07,0-8.516-4.061-7.427-9.012c18.883-85.995,95.625-150.564,187.207-150.564c105.708,0,191.706,85.999,191.706,191.706 c0,105.709-85.998,191.707-191.706,191.707c-12.674,0-22.95,10.275-22.95,22.949s10.276,22.949,22.95,22.949 c131.018,0,237.606-106.588,237.606-237.605c0-131.017-106.589-237.605-237.606-237.605 c-116.961,0-214.395,84.967-233.961,196.409c-0.878,4.994-5.52,9.067-10.59,9.067H5.057c-5.071,0-6.579,3.182-3.373,7.108 L70.846,324.059z"/> </svg> </button> <select onchange="changeDropdown(this)" style="width: 160px;" class="input outline-none bg-gray-50 border rounded-s-none rounded-e-lg border-gray-300 text-gray-900 text-sm block p-1.5"></select> </div> </div> </div> </template> <div id="sample"> <iframe id="apiFrame" src="https://gojs.net/latest/api/symbols/PackedLayout.html" style="display: none;"></iframe> <div id="frame" style="z-index: 100; pointer-events: none; position: absolute; display: none; "> <div id="container" style="border: 1px solid #ddd; border-radius: 5px; padding: 15px; max-width: 600px;margin: 20px auto; font-family: Arial, sans-serif; background-color: #fff;"> <div id="name" class="name" style="font-weight: bold; font-size: 16px; display: flex; align-items: center;"></div> <div id="description" style=" margin-top: 10px; font-size: 14px; color: #000;"></div> </div> </div> <div class="sampleWrapper"> <div id="myDiagramDiv" style="flex-grow: 1; height: 550px; border: solid 1px black; margin-right: 10px;"></div> <div style="flex: 1;"> <section class="grid grid-cols-1 gap-y-3 divide-y"> <details open class="group py-1 text-lg select-none"> <summary class="flex cursor-pointer flex-row items-center whitespace-nowrap justify-between py-1 font-semibold marker:[font-size:0px]">Node Settings <svg class="h-6 w-6 rotate-0 transform text-gray-400 group-open:rotate-180" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"></path> </svg> </summary> <span class="sampleWrapper"> <div class="table " style="padding-right: 15px;"> <div class="row" > <!--Num Nodes--> <div class="cell whitespace-nowrap p-1 select-none" style="font-size: large; padding-right: 15px;">Number of Nodes</div> <div class="cell max-w-xs"> <label for="numNodes" class="items-center cursor-pointer"> <div class="relative flex items-center max-w-[6.5rem] "> <button type="button" onclick="getElementById('numNodes').value = Math.max(getElementById('numNodes').value - 10, 1)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-s-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[12px] pl-[7px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 2"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h16"/> </svg> </button> <input type="text" id="numNodes" onchange="this.value = Math.max(this.value, 1)" aria-describedby="helper-text-explanation" class="bg-gray-50 border-x-1 border-gray-300 h-7 text-center outline-none text-gray-900 text-sm w-11 m-[-4.5px] z-10" value="100" required /> <button type="button" onclick="getElementById('numNodes').value = Math.max(getElementById('numNodes').value - -10, 1)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-e-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[7px] pl-[12px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/> </svg> </button> </div> </label> </div> </div> <div class="row"> <!--Min Side Length--> <div id= "nodeWidthText" class="cell whitespace-nowrap p-1 select-none" style="font-size: large">Minimum Size</div> <div class="cell max-w-xs" id="nodeWidthForm"> <label for="minLinks" class="items-center cursor-pointer"> <div class="relative flex items-center max-w-[6.5rem]"> <button type="button" onclick="changeNodes(false, -5)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-s-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[12px] pl-[7px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 2"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h16"/> </svg> </button> <input type="text" id="nodeMinSide" onclick="changeNodes(false, 0)" aria-describedby="helper-text-explanation" onchange="" class="bg-gray-50 border-x-1 border-gray-300 h-7 text-center text-gray-900 text-sm outline-none w-11 m-[-4.5px] z-10" value="30" required /> <button type="button" onclick="changeNodes(false, 5)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-e-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[7px] pl-[12px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/> </svg> </button> </div> </label> </div> </div> <div class="row"> <!--Max Side Length--> <div id= "nodeHeightText" class="cell whitespace-nowrap p-1 select-none" style="font-size: large">Maximum Size</div> <div class="cell max-w-xs" id="nodeHeightForm"> <label for="minLinks" class="items-center cursor-pointer"> <div class="relative flex items-center max-w-[6.5rem]"> <button type="button" onclick="changeNodes(true, -5)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-s-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[12px] pl-[7px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 2"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h16"/> </svg> </button> <input type="text" id="nodeMaxSide" onclick="changeNodes(true, 0)" aria-describedby="helper-text-explanation" onchange="" class="bg-gray-50 border-x-1 outline-none border-gray-300 h-7 text-center text-gray-900 text-sm block w-11 m-[-4.5px] z-10" value="50" required /> <button type="button" onclick="changeNodes(true, 5)" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-e-lg h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none m-0 pr-[7px] pl-[12px]"> <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/> </svg> </button> </div> </label> </div> </div> </div> <div> <div class="row" id="hasCircularNodesRow"><!--Node Shape--> <svg onclick="" class="cell info shrink-0 inline w-4 h-4 align-middle" style="margin-right: 2px; margin-bottom: 6px;" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/> </svg> <div class="cell whitespace-nowrap tooltip-trigger align-middle select-none p-1" style= "padding-right: 10px;">Node Shape</div> <div class="celldif"> <select id="hasCircularNodes" onchange="layout(true)" class="input align-middle bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-[120px] p-1.5"> <option value="Rectangle" selected="selected">Rectangle</option> <option value="Ellipse">Ellipse</option> <option value="Square">Square</option> <option value="Circle">Circle</option> </select> </div> </div> <button type="button" class="mt-2 ml-[60px]" onclick="rebuildGraph()">Generate Graph</button> </div> </span> </details> <details open class="group py-1 text-lg select-none"> <summary class="flex cursor-pointer flex-row items-center justify-between py-1 font-semibold marker:[font-size:0px]">Packed Layout Settings <svg class="h-6 w-6 rotate-0 transform text-gray-400 group-open:rotate-180" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"></path></svg> </summary> <span class="sampleWrapper"> <div class="table" id="table1"></div> <div class="table mt-[-15px]" id="table2"></div> </span> </details> <details open class="group py-1 text-lg"> <summary class="flex cursor-pointer flex-row items-center justify-between py-1 font-semibold marker:[font-size:0px] select-none">Packed Layout Builder <svg class="h-6 w-6 rotate-0 transform text-gray-400 group-open:rotate-180" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"></path> </svg> </summary> <div class="p-1" style="position: relative;"> <pre style="overflow: auto;"> <code id="layoutBuilder" class="lang-js" style="font-size: large;"></code> </pre> <button onclick="copyCode()" style="position: absolute; top: 14px; right: 8px; width: 35px; height: 35px;" id="copyButton" class="copyButton text-gray-900 m-1 rounded-lg py-2 px-2.5 inline-flex items-center justify-center bg-white border-gray-200 border"> <svg id="default" class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20"> <path d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z"/> </svg> <svg id="clicked" class="w-4 h-4" style="display: none;" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/> </svg> </button> </div> </details> </section> </div> </div> <p> This sample demonstrates a custom Layout, PackedLayout, which attempts to pack nodes as close together as possible without overlap. Each node is assumed to be either rectangular or circular (dictated by the 'hasCircularNodes' property). This layout supports packing nodes into either a rectangle or an ellipse, with the shape determined by the PackShape and the aspect ratio determined by either the aspectRatio property, or the specified width and height (depending on the PackMode). </p> <p> The layout is defined in its own file, as <a href="../extensionsJSM/PackedLayout.js" target="_blank">PackedLayout.js</a>, with an additional dependency on <a href="../extensionsJSM/Quadtree.js" target="_blank">Quadtree.js</a>. </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>Custom Layouts</h4> <p> GoJS allows for the creation of custom layouts to meet specific needs. </p> <p> There are also many layouts that are extensions -- not predefined in the <code>go.js</code> or <code>go-debug.js</code> library, but available as source code in one of the three extension directories, with some documentation and corresponding samples. More information can be found in the <a href="../intro/layouts.html#CustomLayouts">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#customlayout">Related samples</a> </p> <hr> <!-- blacklist tags that do not correspond to a specific GoJS feature --> <h4>GoJS Extensions</h4> <p> <b>GoJS</b> can be extended in a variety of ways. The most common way to change the standard behavior is to set properties on the <a href="../api/symbols/GraphObject.html" target="api">GraphObject</a>, <a href="../api/symbols/Diagram.html" target="api">Diagram</a>, <a href="../api/symbols/CommandHandler.html" target="api">CommandHandler</a>, <a href="../api/symbols/Tool.html" target="api">Tool</a>, or <a href="../api/symbols/Layout.html" target="api">Layout</a>. But when the desired property does not exist, you might need to override methods of CommandHandler, Tool, Layout, Link, or Node. Methods that you can override are documented in the API reference. Various features of GoJS can be overriden, either by replacing a method on an instance (a feature of JavaScript) or by defining a subclass. You should not modify the prototypes of any of the <b>GoJS</b> classes. </p> <p> In addition to our samples, <b>GoJS</b> provides an <strong><a href="../samples/#extensions">extensions gallery</a></strong>, showcasing the creation of custom tools and layouts. Those classes and samples are written in TypeScript, available at <code>../extensionsJSM/</code>, as ECMAScript/JavaScript modules -- these use the <code>../release/go-module.js</code> library. We recommend that you copy the files that you need into your project, so that you can adjust how they refer to the GoJS library that you choose and so that you can include them into your own building and packaging procedures. </p> <p> More information can be found in the <a href="../intro/extensions.html">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#extensions">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>