UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

423 lines (376 loc) 19.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="When a diagram node is selected show a selection Adornment holding buttons on which a click invokes a command or a drag starts a tool" /> <meta itemprop="description" content="When a diagram node is selected show a selection Adornment holding buttons on which a click invokes a command or a drag starts a tool" /> <meta property="og:description" content="When a diagram node is selected show a selection Adornment holding buttons on which a click invokes a command or a drag starts a tool" /> <meta name="twitter:description" content="When a diagram node is selected show a selection Adornment holding buttons on which a click invokes a command or a drag starts a tool" /> <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="Radial Adornment Buttons for Primary Selected Node" /> <meta property="og:title" content="Radial Adornment Buttons for Primary Selected Node" /> <meta name="twitter:title" content="Radial Adornment Buttons for Primary Selected Node" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/radialadornment.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/radialadornment.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/radialadornment.png" /> <meta property="og:url" content="https://gojs.net/latest/samples/radialAdornment.html" /> <meta property="twitter:url" content="https://gojs.net/latest/samples/radialAdornment.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Radial Adornment Buttons for Primary Selected Node | 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"> // Produce a "Button" that is shaped as the intersection of a circular sector and an annular ring. // The first argument is the angle at which the button will be placed relative to the center. // The second argument is the sweep angle over which the button will extend; // by default this is 90 degrees, as if there are exactly four buttons around the whole circle. go.GraphObject.defineBuilder('SectorButton', args => { var angle = go.GraphObject.takeBuilderArgument(args, 0.0, a => typeof a === 'number'); var sweep = go.GraphObject.takeBuilderArgument(args, 90.0, a => typeof a === 'number'); // default brushes for "Button" shape var buttonFillNormal = 'whitesmoke'; var buttonStrokeNormal = 'gray'; var buttonFillOver = 'dodgerblue'; var buttonStrokeOver = 'blue'; var buttonFillDisabled = 'darkgray'; function makeAnnularWedge(angle, sweep, outer, inner) { // the Geometry will be centered about (0,0) var p = new go.Point(outer, 0).rotate(angle - sweep / 2); var q = new go.Point(inner, 0).rotate(angle + sweep / 2); var geo = new go.Geometry() .add(new go.PathFigure(-outer, -outer)) // always make sure the Geometry includes the top left corner .add(new go.PathFigure(outer, outer)) // and the bottom right corner of the whole circular area .add( new go.PathFigure(p.x, p.y) // start at outer corner, go clockwise .add(new go.PathSegment(go.SegmentType.Arc, angle - sweep / 2, sweep, 0, 0, outer, outer)) .add(new go.PathSegment(go.SegmentType.Line, q.x, q.y)) // to opposite inner corner, then anticlockwise .add(new go.PathSegment(go.SegmentType.Arc, angle + sweep / 2, -sweep, 0, 0, inner, inner).close()) ); return geo; } var geo = makeAnnularWedge(angle, sweep, 80, 40); var pt = new go.Point(60, 0).rotate(angle); var align = new go.Spot(0.5, 0.5, pt.x, pt.y); args.forEach(obj => { if (obj instanceof go.GraphObject) obj.alignment = align; }); var button = new go.Panel('Spot', { isActionable: true, // needed so that the ActionTool intercepts mouse events enabledChanged: (button, enabled) => { const shape = button.findObject('ButtonBorder'); if (shape !== null) { shape.fill = enabled ? button['_buttonFillNormal'] : button['_buttonFillDisabled']; } } }) .attach({ // save these values for the mouseEnter and mouseLeave event handlers _buttonFillNormal: buttonFillNormal, _buttonStrokeNormal: buttonStrokeNormal, _buttonFillOver: buttonFillOver, _buttonStrokeOver: buttonStrokeOver, _buttonFillDisabled: buttonFillDisabled }) .add( new go.Shape({ // the border name: 'ButtonBorder', fill: buttonFillNormal, stroke: buttonStrokeNormal, geometry: geo }) ); // There's no GraphObject inside the button shape -- it must be added as part of the button definition. // This way the object could be a TextBlock or a Shape or a Picture or arbitrarily complex Panel. // mouse-over behavior button.mouseEnter = (e, button, prev) => { var shape = button.findObject('ButtonBorder'); // the border Shape if (shape instanceof go.Shape) { shape.fill = button['_buttonFillOver']; shape.stroke = button['_buttonStrokeOver']; } }; button.mouseLeave = (e, button, prev) => { var shape = button.findObject('ButtonBorder'); // the border Shape if (shape instanceof go.Shape) { shape.fill = button['_buttonFillNormal']; shape.stroke = button['_buttonStrokeNormal']; } }; return button; }); function init() { myDiagram = new go.Diagram('myDiagramDiv', { // show the selection Adornment only on the first selection if it is a Node ChangedSelection: e => { var node = e.diagram.selection.first(); if (node === null) { var oldnode = selectionAdornment.adornedPart; if (oldnode) oldnode.removeAdornment('Radial'); selectionAdornment.adornedObject = null; } else if (node instanceof go.Node) { selectionAdornment.adornedObject = node; node.addAdornment('Radial', selectionAdornment); } }, InitialLayoutCompleted: e => { // show the adornment on the "Beta" node e.diagram.select(e.diagram.findNodeForKey(2)); }, 'undoManager.isEnabled': true }); myDiagram.nodeTemplate = new go.Node('Auto', { resizable: true }) .bindTwoWay('desiredSize', 'size', go.Size.parse, go.Size.stringify) .add( new go.Shape({ portId: '', fromLinkable: true, toLinkable: true }) .bind('fill', 'color'), new go.TextBlock({ margin: 8, editable: true }) .bindTwoWay('text') ); // prevent the tool from starting on without radial menu myDiagram.toolManager.linkingTool.canStart = () => false; // Show a radial Adornment holding buttons when a node is selected. // This is not a template, so there is only one instance of it that can be shown at a time. // If you want every selected node to have their own copy of this adornment, // set Node.selectionAdornmentTemplate to this and remove the "ChangedSelection" DiagramEvent listener. var selectionAdornment = new go.Adornment('Spot', { layerName: 'Tool' }) // so that it's in front of other Adornments .add( new go.Panel('Auto') .add( new go.Shape({ fill: null, stroke: 'dodgerblue', strokeWidth: 4, pickable: false }), new go.Placeholder({ margin: 2 }) ), new go.Panel() .add( go.GraphObject.build('SectorButton', { // start drawing a new link from this node click: (e, button) => { var node = button.part.adornedPart; // this Node e.diagram.clearSelection(); // hide all Adornments for clarity var tool = e.diagram.toolManager.linkingTool; // the LinkingTool tool.startObject = node.port; // the default port of the Node e.diagram.currentTool = tool; // start the LinkingTool tool.doActivate(); // and activate it } }, 0, 90) // start angle, sweep angle, .add( new go.TextBlock('New\nLink', { alignment: new go.Spot(0.95, 0.5), alignmentFocus: go.Spot.Right }) ), go.GraphObject.build('SectorButton', { click: (e, button) => { // maybe use a DataInspector? alert('Show Settings for ' + button.part.adornedPart.data.text); } }, 90, 90) .add( new go.Shape({ alignment: new go.Spot(0.5, 0.97), alignmentFocus: go.Spot.Bottom, geometryString: 'F1 M29.181 19.070c-1.679-2.908-0.669-6.634 2.255-8.328l-3.145-5.447c-0.898 0.527-1.943 0.829-3.058 0.829-3.361 0-6.085-2.742-6.085-6.125h-6.289c0.008 1.044-0.252 2.103-0.811 3.070-1.679 2.908-5.411 3.897-8.339 2.211l-3.144 5.447c0.905 0.515 1.689 1.268 2.246 2.234 1.676 2.903 0.672 6.623-2.241 8.319l3.145 5.447c0.895-0.522 1.935-0.82 3.044-0.82 3.35 0 6.067 2.725 6.084 6.092h6.289c-0.003-1.034 0.259-2.080 0.811-3.038 1.676-2.903 5.399-3.894 8.325-2.219l3.145-5.447c-0.899-0.515-1.678-1.266-2.232-2.226zM16 22.479c-3.578 0-6.479-2.901-6.479-6.479s2.901-6.479 6.479-6.479c3.578 0 6.479 2.901 6.479 6.479s-2.901 6.479-6.479 6.479z' }) ), go.GraphObject.build('SectorButton', { click: (e, button) => { // maybe show some info in HTML? alert('Show Information about ' + button.part.adornedPart.data.text); } }, 180, 90) .add( new go.TextBlock('?', { font: 'bold 14pt sans-serif', alignment: new go.Spot(0.1, 0.5), alignmentFocus: go.Spot.Left }) ), go.GraphObject.build('SectorButton', { click: (e, button) => { // this is different from CommandHandler.deleteSelection because this // only deletes the one node, not all selected parts e.diagram.commit(d => d.remove(button.part.adornedPart), 'deleted node'); } }, 270, 90) .add( new go.Shape('XLine', { stroke: 'red', strokeWidth: 4, width: 16, height: 16, alignment: new go.Spot(0.5, 0.07), alignmentFocus: go.Spot.Top }) ) ) ); myDiagram.model = new go.GraphLinksModel( [ { key: 1, text: 'Alpha', color: 'lightblue' }, { key: 2, text: 'Beta', color: 'orange' }, { key: 3, text: 'Gamma', color: 'lightgreen' }, { key: 4, text: 'Delta', color: 'pink' } ], [ { from: 1, to: 2 }, { from: 1, to: 3 }, { from: 2, to: 2 }, { from: 3, to: 4 }, { from: 4, to: 1 } ] ); } window.addEventListener('DOMContentLoaded', init); </script> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; width: 100%; height: 500px"></div> <p> Selecting a Node shows not only a dodgerblue rectangle around the selected node, but also a circular arrangement of Buttons. The red "X" deletes the node. The "?" and cog/gear Shape currently just call `alert`, but they could do anything that you want. The "New Link" starts the <a>LinkingTool</a> drawing a new Link from that Node. </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>Buttons</h4> <p> GoJS defines several <a href="../api/symbols/Panel.html" target="api">Panel</a>s for common uses. These include "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", "ContextMenuButton", and "CheckBoxButton". "ContextMenuButton"s are typically used inside of "ContextMenu" Panels; "CheckBoxButton"s are used in the implementation of "CheckBox" Panels. </p> <p> These predefined panels can be used as if they were <a href="../api/symbols/Panel.html" target="api">Panel</a>-derived classes in calls to <a href="../api/symbols/GraphObject.html#build" target="api">GraphObject.build</a>. They are implemented as simple visual trees of <a href="../api/symbols/GraphObject.html" target="api">GraphObject</a>s in <a href="../api/symbols/Panel.html" target="api">Panel</a>s, with pre-set properties and event handlers. </p> <p> More information can be found in the <a href="../intro/buttons.html">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#buttons">Related samples</a> </p> <hr> <!-- blacklist tags that do not correspond to a specific GoJS feature --> <h4>Geometry Path Strings</h4> <p> The <b>GoJS</b> <a href="../api/symbols/Geometry.html" target="api">Geometry</a> class controls the "shape" of a <a href="../api/symbols/Shape.html" target="api">Shape</a>, whereas the <a href="../api/symbols/Shape.html#fill" target="api">Shape.fill</a> and <a href="../api/symbols/Shape.html#stroke" target="api">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 href="../api/symbols/Shape.html#figure" target="api">Shape.figure</a>. However one can also define custom geometries. </p> <p> One can construct any Geometry by allocating and initializing a <a href="../api/symbols/Geometry.html" target="api">Geometry</a> of at least one <a href="../api/symbols/PathFigure.html" target="api">PathFigure</a> holding some <a href="../api/symbols/PathSegment.html" target="api">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 href="../api/symbols/Geometry.html#parse" target="api">Geometry.parse</a> or the <a href="../api/symbols/Shape.html#geometryString" target="api">Shape.geometryString</a> property to transform a geometry path string into a <a href="../api/symbols/Geometry.html" target="api">Geometry</a> object. </p> <p> More information can be found in the <a href="../intro/geometry.html">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#geometries">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>