create-gojs-kit
Version:
A CLI for downloading GoJS samples, extensions, and docs
409 lines (351 loc) • 16.9 kB
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 a GoJS Palette in a floating window and use an Inspector for changing the appearance of the selected node." />
<meta itemprop="description" content="Show a GoJS Palette in a floating window and use an Inspector for changing the appearance of the selected node." />
<meta property="og:description" content="Show a GoJS Palette in a floating window and use an Inspector for changing the appearance of the selected node." />
<meta name="twitter:description" content="Show a GoJS Palette in a floating window and use an Inspector for changing the appearance of the selected node." />
<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="HTML Interaction Showing Draggable Palette and Draggable Inspector" />
<meta property="og:title" content="HTML Interaction Showing Draggable Palette and Draggable Inspector" />
<meta name="twitter:title" content="HTML Interaction Showing Draggable Palette and Draggable Inspector" />
<meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/htmlinteraction.png" />
<meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/htmlinteraction.png" />
<meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/htmlinteraction.png" />
<meta property="og:url" content="https://gojs.net/latest/samples/htmlInteraction.html" />
<meta property="twitter:url" content="https://gojs.net/latest/samples/htmlInteraction.html" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="og:type" content="website" />
<meta property="twitter:domain" content="gojs.net" />
<title>
HTML Interaction Showing Draggable Palette and Draggable Inspector | 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">
<style type="text/css">
.draggable {
display: inline-block;
vertical-align: top;
border: 4px solid #bbb;
border-radius: 4px;
background-color: #f5f5f5;
position: absolute;
top: 20px;
left: 20px;
z-index: 500;
}
.handle {
background-color: lightblue;
cursor: move;
text-align: center;
font: bold 12px sans-serif;
}
#infoDraggable {
font: 12px helvetica, sans-serif;
min-width: 213px;
}
#myInfo {
width: 100%;
overflow: hidden;
}
#myPaletteDiv {
background-color: #f5f5f5;
width: 100%;
height: 100%;
}
/*
One simple way of making a div fill its space,
with allowances for the title (top) and the resize handle (bottom)
*/
#paletteContainer {
position: absolute;
bottom: 14px;
left: 0px;
right: 0px;
top: 14px;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="../extensions/Figures.js"></script>
<script src="../extensions/DataInspector.js"></script>
<script id="code">
function init() {
myDiagram = new go.Diagram('myDiagramDiv', {
'undoManager.isEnabled': true
});
// define several shared Brushes
const fill1 = 'rgb(105,210,231)';
const brush1 = 'rgb(65,180,181)';
const fill2 = 'rgb(167,219,216)';
const brush2 = 'rgb(127,179,176)';
const fill3 = 'rgb(224,228,204)';
const brush3 = 'rgb(184,188,164)';
const fill4 = 'rgb(243,134,48)';
const brush4 = 'rgb(203,84,08)';
myDiagram.nodeTemplateMap.add('', // default category
new go.Node('Auto', { locationSpot: go.Spot.Center })
.bindTwoWay('location', 'loc', go.Point.parse, go.Point.stringify)
.add(
new go.Shape('Ellipse', { strokeWidth: 2, fill: fill1, name: 'SHAPE' })
.bind('figure', 'figure')
.bind('fill', 'fill')
.bind('stroke', 'stroke'),
new go.TextBlock({
margin: 5,
maxSize: new go.Size(200, NaN),
wrap: go.Wrap.Fit,
textAlign: 'center',
editable: true,
font: 'bold 9pt Helvetica, Arial, sans-serif',
name: 'TEXT'
})
.bindTwoWay('text')
)
);
// On selection changed, make sure infoDraggable will resize as necessary
myDiagram.addDiagramListener('ChangedSelection', diagramEvent => {
var idrag = document.getElementById('infoDraggable');
idrag.style.width = '';
idrag.style.height = '';
});
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: 'Ocean', fill: fill1, stroke: brush1, figure: 'Hexagon' },
{ key: 2, text: 'Lake', fill: fill2, stroke: brush2, figure: 'Diamond' }
],
[{ from: 1, to: 2 }]
);
// initialize the Palette that is in a floating, draggable HTML container
myPalette = new go.Palette('myPaletteDiv');
myPalette.nodeTemplateMap = myDiagram.nodeTemplateMap;
myPalette.model = new go.GraphLinksModel([
{ text: 'Lake', fill: fill1, stroke: brush1, figure: 'Hexagon' },
{ text: 'Ocean', fill: fill2, stroke: brush2, figure: 'Rectangle' },
{ text: 'Sand', fill: fill3, stroke: brush3, figure: 'Diamond' },
{ text: 'Goldfish', fill: fill4, stroke: brush4, figure: 'Octagon' }
]);
myPalette.addDiagramListener('InitialLayoutCompleted', diagramEvent => {
var pdrag = document.getElementById('paletteDraggable');
var palette = diagramEvent.diagram;
pdrag.style.width = palette.documentBounds.width + 28 + 'px'; // account for padding/borders
pdrag.style.height = palette.documentBounds.height + 38 + 'px';
});
$(() => {
$('#paletteDraggable')
.draggable({ handle: '#paletteDraggableHandle' })
.resizable({
// After resizing, perform another layout to fit everything in the palette's viewport
stop: () => myPalette.layoutDiagram(true)
});
$('#infoDraggable').draggable({ handle: '#infoDraggableHandle' });
var inspector = new Inspector('myInfo', myDiagram, {
properties: {
// key would be automatically added for nodes, but we want to declare it read-only also:
key: { readOnly: true, show: Inspector.showIfPresent },
// fill and stroke would be automatically added for nodes, but we want to declare it a color also:
fill: { show: Inspector.showIfPresent, type: 'color' },
stroke: { show: Inspector.showIfPresent, type: 'color' }
}
});
myDiagram.select(myDiagram.nodes.first());
});
}
window.addEventListener('DOMContentLoaded', init);
</script>
<div id="sample">
<div id="paletteDraggable" class="draggable" style="height: 300px">
<div id="paletteDraggableHandle" class="handle">Palette</div>
<div id="paletteContainer">
<div id="myPaletteDiv"></div>
</div>
</div>
<div id="infoDraggable" class="draggable" style="display: inline-block; vertical-align: top; padding: 5px; top: 20px; left: 380px">
<div id="infoDraggableHandle" class="handle">Info</div>
<div>
<div id="myInfo"></div>
</div>
</div>
<div style="display: inline-block; vertical-align: top; width: 400px">
<div id="myDiagramDiv" style="background-color: whitesmoke; border: solid 1px black; height: 400px"></div>
</div>
<p>This sample contains a draggable HTML element (using jQuery UI), which houses a GoJS Palette.</p>
<p>
A DIV to the right of the diagram houses the <a href="../samples/DataInspector.html">GoJS Data inspector extension</a>, which displays some editable
information about each 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>Palette</h4>
<p>
A <a href="../api/symbols/Palette.html" target="api">Palette</a> is a subclass of <a href="../api/symbols/Diagram.html" target="api">Diagram</a> that is used to display a number of <a href="../api/symbols/Part.html" target="api">Part</a>s that
can be dragged into the diagram that is being modified by the user.
The initialization of a <a href="../api/symbols/Palette.html" target="api">Palette</a> is just like the initialization of any <a href="../api/symbols/Diagram.html" target="api">Diagram</a>.
Like Diagrams, you can have more than one Palette on the page at the same time.
</p>
<p>
More information can be found in the <a href="../intro/palette.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#palette">Related samples</a>
</p>
<hr>
<!-- 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>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Data Inspector</h4>
<p>Using a premade GoJS extension, you can create an HTML-based inspector that displays and allows editing of data for the selected Part (if any),
or for a particular JavaScript object, or for the shared <a href="../api/symbols/Model.html#modelData" target="api">Model.modelData</a> object,
which exists even if there are no nodes or links.
</p>
<p>The inspector code lies in <a href="../extensions/DataInspector.js">DataInspector.js</a> and <a href="../extensions/DataInspector.css">DataInspector.css</a>.
This code is meant to be a starting point for making your own model data inspector.
</p>
<p>
A generic demonstration of this extension can be found in the <a href="../samples/DataInspector.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#inspector">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>GoJS on Different Platforms</h4>
<p>
GoJS is intended to run in any environment that executes JavaScript.
This includes on browsers and within browser frameworks, and also in headless contexts such as Node.js.
</p>
<p>
We maintain examples for common frameworks:
</p>
<ul>
<li>
<strong>React:</strong> We provide a <a href="https://github.com/NorthwoodsSoftware/gojs-react" target="_blank" rel="noopener">React Component</a>
as an <a href="https://npmjs.com/gojs-react" target="_blank" rel="noopener">NPM package</a> and
a usage <a href="https://github.com/NorthwoodsSoftware/gojs-react-basic" target="_blank" rel="noopener">sample</a>.
See the intro page <a href="../intro/react.html">Using GoJS with React</a> for more information on React integration.
</li>
<li>
<strong>Angular:</strong> We provide an <a href="https://github.com/NorthwoodsSoftware/gojs-angular" target="_blank" rel="noopener">Angular Component</a>
as an <a href="https://npmjs.com/gojs-angular" target="_blank" rel="noopener">NPM package</a> and
a usage <a href="https://github.com/NorthwoodsSoftware/gojs-angular-basic" target="_blank" rel="noopener">sample</a>.
See the intro page <a href="../intro/angular.html">Using GoJS with Angular</a> for more information on Angular integration.
</li>
<li>
<strong>Vue:</strong> We provide a <a href="../samples/vue.html">Vue.js Sample</a>.
</li>
</ul>
<p>
More information, including usage on frameworks including Electron, Blazor, and node.js, can be found at the <a href="../intro/platforms.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#frameworks">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>