UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

411 lines (366 loc) 15.8 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="Show the relationships between people using a friend wheel diagram, implemented using circular layout." /> <meta itemprop="description" content="Show the relationships between people using a friend wheel diagram, implemented using circular layout." /> <meta property="og:description" content="Show the relationships between people using a friend wheel diagram, implemented using circular layout." /> <meta name="twitter:description" content="Show the relationships between people using a friend wheel diagram, implemented using circular layout." /> <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="Friend Wheel Diagram for Elliptical Arrangement of Nodes and Curved Links Inside Ellipse" /> <meta property="og:title" content="Friend Wheel Diagram for Elliptical Arrangement of Nodes and Curved Links Inside Ellipse" /> <meta name="twitter:title" content="Friend Wheel Diagram for Elliptical Arrangement of Nodes and Curved Links Inside Ellipse" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/friendwheel.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/friendwheel.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/friendwheel.png" /> <meta property="og:url" content="https://gojs.net/latest/samples/friendWheel.html" /> <meta property="twitter:url" content="https://gojs.net/latest/samples/friendWheel.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Friend Wheel Diagram for Elliptical Arrangement of Nodes and Curved Links Inside Ellipse | 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"> class WheelLayout extends go.CircularLayout { constructor(init) { super(); if (init) Object.assign(this, init); } // override makeNetwork to set the diameter of each node and ignore the TextBlock label makeNetwork(coll) { const net = super.makeNetwork(coll); net.vertexes.each(v => v.diameter = 25); // pretend nodes are 25x25 in size return net; } // override commitNodes to rotate nodes so the text goes away from the center, // and flip text if it would be upside-down commitNodes() { super.commitNodes(); const num = this.network.vertexes.count; if (num < 2) return; this.network.vertexes.each(v => { const node = v.node; if (node === null) return; // get the angle of the node towards the center, and rotate it accordingly const a = v.actualAngle; // make sure the text isn't upside down const textBlock = node.findObject('TEXTBLOCK'); if (textBlock !== null) { textBlock.angle = (a > 90 && a < 270) ? 180 : 0; } node.angle = a; }); } // override commitLinks in order to make sure all of the Bezier links are "inside" the ellipse; // this helps avoid links crossing over any other nodes commitLinks() { super.commitLinks(); this.network.edges.each(e => { const link = e.link; if (link === null) return; let da = e.toVertex.actualAngle; let sa = e.fromVertex.actualAngle; if (da - sa > 180) da -= 360; else if (sa - da > 180) sa -= 360; let c = sa - da; if (c < 0) c = Math.max(-60, Math.min(c, -30)); else c = Math.max(30, Math.min(c, 60)); link.curviness = c; }); } } // end WheelLayout class const highlightColor = 'red'; // color parameterization function init() { myDiagram = new go.Diagram('myDiagramDiv', { 'animationManager.isEnabled': false, initialAutoScale: go.AutoScale.Uniform, padding: 10, contentAlignment: go.Spot.Center, layout: new WheelLayout({ // set up a custom CircularLayout // set some properties appropriate for this sample arrangement: go.CircularArrangement.ConstantDistance, nodeDiameterFormula: go.CircularNodeDiameterFormula.Circular, spacing: 10, aspectRatio: 0.7, sorting: go.CircularSorting.Optimized }), isReadOnly: true, click: e => { // background click clears any remaining highlighteds e.diagram.commit(d => d.clearHighlighteds()); } }); // define the Node template myDiagram.nodeTemplate = new go.Node('Horizontal', { selectionAdorned: false, locationSpot: go.Spot.Center, // Node.location is the center of the Shape locationObjectName: 'SHAPE', mouseEnter: (e, node) => { e.diagram.clearHighlighteds(); node.linksConnected.each(l => highlightLink(l, true)); node.isHighlighted = true; const tb = node.findObject('TEXTBLOCK'); if (tb !== null) tb.stroke = highlightColor; }, mouseLeave: (e, node) => { e.diagram.clearHighlighteds(); const tb = node.findObject('TEXTBLOCK'); if (tb !== null) tb.stroke = 'black'; } }) .bind('text', 'text') // for sorting the nodes .add( new go.Shape('Circle', { name: 'SHAPE', fill: 'lightgray', // default value, but also data-bound stroke: 'transparent', // modified by highlighting strokeWidth: 2, desiredSize: new go.Size(25, 25), portId: '' }) // so links will go to the shape, not the whole node .bind('fill', 'color') .bindObject('stroke', 'isHighlighted', h => h ? highlightColor : 'transparent'), new go.TextBlock({ name: 'TEXTBLOCK' }) // for search .bind('text', 'text') ); function highlightLink(link, show) { link.isHighlighted = show; link.fromNode.isHighlighted = show; link.toNode.isHighlighted = show; } // define the Link template myDiagram.linkTemplate = new go.Link({ // routing: go.Routing.Orthogonal, curve: go.Curve.Bezier, selectionAdorned: false, mouseEnter: (e, link) => highlightLink(link, true), mouseLeave: (e, link) => highlightLink(link, false) }) .add( new go.Shape() .bindObject('stroke', 'isHighlighted', (h, shape) => h ? highlightColor : go.Brush.darken(shape.part.data.color)) .bindObject('strokeWidth', 'isHighlighted', h => h ? 3 : 1.5) // no arrowhead -- assume directionality of relationship need not be shown ); generateGraph(); } function generateGraph() { const names = [ 'Joshua', 'Daniel', 'Robert', 'Noah', 'Anthony', 'Elizabeth', 'Addison', 'Alexis', 'Ella', 'Samantha', 'Joseph', 'Scott', 'James', 'Ryan', 'Benjamin', 'Walter', 'Gabriel', 'Christian', 'Nathan', 'Simon', 'Isabella', 'Emma', 'Olivia', 'Sophia', 'Ava', 'Emily', 'Madison', 'Tina', 'Elena', 'Mia', 'Jacob', 'Ethan', 'Michael', 'Alexander', 'William', 'Natalie', 'Grace', 'Lily', 'Alyssa', 'Ashley', 'Sarah', 'Taylor', 'Hannah', 'Brianna', 'Hailey', 'Christopher', 'Aiden', 'Matthew', 'David', 'Andrew', 'Kaylee', 'Juliana', 'Leah', 'Anna', 'Allison', 'John', 'Samuel', 'Tyler', 'Dylan', 'Jonathan' ]; const colors = ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061']; const nodeDataArray = []; for (let i = 0; i < names.length; i++) { nodeDataArray.push({ key: i, text: names[i], color: colors[i % colors.length] }); } const linkDataArray = []; const num = nodeDataArray.length; for (let i = 0; i < num * 2; i++) { const a = Math.floor(Math.random() * num); const b = Math.floor((Math.random() * num) / 4) + 1; linkDataArray.push({ from: a, to: (a + b) % num, color: colors[i % colors.length] }); } myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray); } window.addEventListener('DOMContentLoaded', init); </script> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; background: white; width: 100%; height: 600px"></div> <p> This "friend wheel" demonstrates the use of <a>CircularLayout</a>. The layout has been customized to make sure each node is considered to have a fixed diameter, ignoring the size of any <a>TextBlock</a>. </p> <p> The custom layout also rotates each <a>Node</a> according to the actual angle at which the node was positioned. This information is available on the <a>CircularVertex</a> used by the <a>LayoutNetwork</a> that the <a>CircularLayout</a> constructs from the nodes and links of the diagram. Furthermore, when laying out the nodes it also flips the angle of the <a>TextBlock</a> so that the text is not upside-down. </p> <p> <a>GraphObject.mouseEnter</a> and <a>GraphObject.mouseLeave</a> event handlers on the <a>Node</a> template highlight both the Node and all of the Links that connect with the Node. The same event handlers on the <a>Link</a>s highlight that Link and both connected Nodes. Changes made in these event handlers automatically are not recorded in the <a>UndoManager</a>, although this sample does not enable the UndoManager anyway. </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>Circular Layout</h4> <p> This predefined layout is used for placing Nodes in a cirular or elliptical arrangement. More information can be found in the <a href="../intro/layouts.html#CircularLayout">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#circularlayout">Related samples</a> </p> <hr> <!-- 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 --> </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>