gojs
Version:
Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams
192 lines (183 loc) • 9.73 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="TypeScript: An implementation of CheckBoxes as GoJS objects to show and edit a boolean data property."/>
<link rel="stylesheet" href="../assets/css/style.css"/>
<!-- Copyright 1998-2023 by Northwoods Software Corporation. -->
<title>CheckBoxes</title>
</head>
<body>
<!-- This top nav is not part of the sample code -->
<nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
<div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
<div class="md:pl-4">
<a class="text-white hover:text-white no-underline hover:no-underline
font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
<h1 class="my-0 p-1 ">GoJS</h1>
</a>
</div>
<button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
<svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
<path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
<path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
</svg>
</button>
<div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
<ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
<li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
<li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
</ul>
</div>
</div>
<hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
</nav>
<div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
<div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
<!-- * * * * * * * * * * * * * -->
<!-- Start of GoJS sample code -->
<div id="allSampleContent" class="p-4 w-full">
<div id="sample">
<div id="myDiagramDiv" style="border: solid 1px black; width:500px; height:500px"></div>
<p>
Various uses of CheckBoxes. These are predefined in the library.
You can see how they are defined in <a href="Buttons.js" target="_blank">Buttons.js</a>.
</p>
<textarea id="mySavedModel" style="width:100%;height:300px"></textarea>
</div>
<script type="module" id="code">
import * as go from '../release/go-module.js';
// don't need to import any extension -- CheckBox is already defined in GoJS
if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
const $ = go.GraphObject.make; // for conciseness in defining templates
const myDiagram =
new go.Diagram('myDiagramDiv', // create a Diagram for the DIV HTML element
{
"ModelChanged": e => {
if (e.isTransactionFinished) document.getElementById("mySavedModel").textContent = myDiagram.model.toJson();
},
'undoManager.isEnabled': true // enable undo & redo
});
// this template includes a lot of CheckBoxes, each configured in different manners
myDiagram.nodeTemplate =
$(go.Node, 'Auto', // the Shape will go around the whole table
$(go.Shape, { strokeWidth: 0 }, // no border
new go.Binding('fill', 'color')),
$(go.Panel, 'Table', { padding: 3 },
$(go.TextBlock,
{ row: 0, column: 0, columnSpan: 2 },
{ margin: 3, font: 'bold 10pt sans-serif' }, // some room around the bold text
new go.Binding('text', 'key')),
// the first column has an assortment of CheckBoxes
$(go.Panel, 'Vertical',
{ row: 1, column: 0, defaultAlignment: go.Spot.Left },
$('CheckBox', 'choice1',
$(go.TextBlock, 'default')),
$('CheckBox', 'choice2',
{ 'ButtonIcon.stroke': 'green' },
$(go.TextBlock, 'green')),
$('CheckBox', 'choice3',
{ 'ButtonIcon.stroke': 'red', 'ButtonIcon.figure': 'XLine' },
$(go.TextBlock, 'red X')),
$('CheckBox', 'choice4',
{ '_buttonFillOver': 'pink', '_buttonStrokeOver': 'red' },
$(go.TextBlock, 'pink over')),
$('CheckBox', 'choice5',
{ 'Button.width': 32, 'Button.height': 32 },
$(go.TextBlock, 'BIG',
{ font: 'bold 12pt sans-serif' })),
$('CheckBox', 'choice6',
{
'Button.width': 20, 'Button.height': 20,
'ButtonBorder.figure': 'Circle', 'ButtonBorder.stroke': 'blue',
'ButtonIcon.figure': 'Circle', 'ButtonIcon.fill': 'blue',
'ButtonIcon.strokeWidth': 0, 'ButtonIcon.desiredSize': new go.Size(10, 10)
},
$(go.TextBlock, 'blue circle')),
$('CheckBox', 'choice7', go.Panel.Vertical,
$(go.TextBlock, 'vertical'))
),
// the second column is a list of CheckBoxes
$(go.Panel, 'Table',
{
row: 1, column: 1,
alignment: go.Spot.Top,
minSize: new go.Size(50, NaN),
itemTemplate:
$('CheckBox', 'checked', go.Panel.TableRow,
$(go.TextBlock, // align text towards the right, next to the Button
{ column: 0, alignment: go.Spot.Right },
new go.Binding('text', 'name')),
{ 'Button.column': 1 } // put Button in second column, to the right of text
)
},
new go.Binding('itemArray', 'items')),
// now a checkbox at the bottom of the whole table
$('CheckBox', '', // not data bound
{ row: 3, columnSpan: 2, alignment: go.Spot.Left },
// this checkbox is not bound to model data, but it does toggle the Part.movable
// property of the Node that this is in
$(go.TextBlock, 'Node is not movable'),
{
'_doClick': (e, obj) => {
if (obj.part !== null) obj.part.movable = !obj.part.movable; // toggle the Part.movable flag
}
})
)
);
// but use the default Link template, by not setting Diagram.linkTemplate
// create the model data that will be represented by Nodes and Links
myDiagram.model =
new go.GraphLinksModel( {
copiesArrays: true,
copiesArrayObjects: true,
nodeDataArray: [
{
key: 'Alpha', color: 'lightblue', choice1: true, choice2: true, choice3: true, choice4: true, choice5: true, choice6: true, choice7: true,
items: [{ name: 'item 0' },
{ name: 'item 1' },
{ name: 'item 2' }]
},
{
key: 'Beta', color: 'orange',
items: [{ name: 'B1', checked: false },
{ name: 'Bee2', checked: true }]
},
{
key: 'Gamma', color: 'lightgreen',
items: [{ name: 'C-one', checked: true },
{ name: 'C-two', checked: true },
{ name: 'C-three' }]
},
{
key: 'Delta', color: 'pink', choice1: true, choice2: false,
items: []
}
],
linkDataArray: [
{ from: 'Alpha', to: 'Beta' },
{ from: 'Alpha', to: 'Gamma' },
{ from: 'Gamma', to: 'Delta' },
{ from: 'Delta', to: 'Alpha' }
]
});
window.myDiagram = myDiagram; // Attach to the window for console debugging
</script>
</div>
<!-- * * * * * * * * * * * * * -->
<!-- End of GoJS sample code -->
</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>