UNPKG

9.77 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8"/>
5<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
6<meta name="description" content="TypeScript: An implementation of CheckBoxes as GoJS objects to show and edit a boolean data property."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>CheckBoxes</title>
10</head>
11
12<body>
13 <!-- This top nav is not part of the sample code -->
14 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
15 <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">
16 <div class="md:pl-4">
17 <a class="text-white hover:text-white no-underline hover:no-underline
18 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
19 <h1 class="mb-0 p-1 ">GoJS</h1>
20 </a>
21 </div>
22 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
23 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
24 <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>
25 <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>
26 </svg>
27 </button>
28 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
29 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
30 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
31 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
32 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
33 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
34 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
38 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
40 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
41 </ul>
42 </div>
43 </div>
44 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
45 </nav>
46 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
47 <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
48 <!-- * * * * * * * * * * * * * -->
49 <!-- Start of GoJS sample code -->
50
51
52 <div class="p-4 w-full">
53 <div id="sample">
54 <div id="myDiagramDiv" style="border: solid 1px black; width:500px; height:500px"></div>
55 <p>
56 Various uses of CheckBoxes. These are predefined in the library.
57 You can see how they are defined in <a href="Buttons.ts">Buttons.ts</a>.
58 </p>
59 <textarea id="mySavedModel" style="width:100%;height:300px"></textarea>
60 </div>
61 <script type="module" id="code">
62 import * as go from '../release/go-module.js';
63 // don't need to import any extension -- CheckBox is already defined in GoJS
64
65 if (window.goSamples) goSamples(); // init for the samples -- you don't need to call this
66 const $ = go.GraphObject.make; // for conciseness in defining templates
67
68 const myDiagram =
69 $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
70 {
71 'undoManager.isEnabled': true // enable undo & redo
72 });
73
74 // this template includes a lot of CheckBoxes, each configured in different manners
75 myDiagram.nodeTemplate =
76 $(go.Node, 'Auto', // the Shape will go around the whole table
77 $(go.Shape, { strokeWidth: 0 }, // no border
78 new go.Binding('fill', 'color')),
79 $(go.Panel, 'Table', { padding: 3 },
80 $(go.TextBlock,
81 { row: 0, column: 0, columnSpan: 2 },
82 { margin: 3, font: 'bold 10pt sans-serif' }, // some room around the bold text
83 new go.Binding('text', 'key')),
84 // the first column has an assortment of CheckBoxes
85 $(go.Panel, 'Vertical',
86 { row: 1, column: 0, defaultAlignment: go.Spot.Left },
87 $('CheckBox', 'choice1',
88 $(go.TextBlock, 'default')),
89 $('CheckBox', 'choice2',
90 { 'ButtonIcon.stroke': 'green' },
91 $(go.TextBlock, 'green')),
92 $('CheckBox', 'choice3',
93 { 'ButtonIcon.stroke': 'red', 'ButtonIcon.figure': 'XLine' },
94 $(go.TextBlock, 'red X')),
95 $('CheckBox', 'choice4',
96 { '_buttonFillOver': 'pink', '_buttonStrokeOver': 'red' },
97 $(go.TextBlock, 'pink over')),
98 $('CheckBox', 'choice5',
99 { 'Button.width': 32, 'Button.height': 32 },
100 $(go.TextBlock, 'BIG',
101 { font: 'bold 12pt sans-serif' })),
102 $('CheckBox', 'choice6',
103 {
104 'Button.width': 20, 'Button.height': 20,
105 'ButtonBorder.figure': 'Circle', 'ButtonBorder.stroke': 'blue',
106 'ButtonIcon.figure': 'Circle', 'ButtonIcon.fill': 'blue',
107 'ButtonIcon.strokeWidth': 0, 'ButtonIcon.desiredSize': new go.Size(10, 10)
108 },
109 $(go.TextBlock, 'blue circle')),
110 $('CheckBox', 'choice7', go.Panel.Vertical,
111 $(go.TextBlock, 'vertical'))
112 ),
113 // the second column is a list of CheckBoxes
114 $(go.Panel, 'Table',
115 {
116 row: 1, column: 1,
117 alignment: go.Spot.Top,
118 minSize: new go.Size(50, NaN),
119 itemTemplate:
120 $('CheckBox', 'checked', go.Panel.TableRow,
121 $(go.TextBlock, // align text towards the right, next to the Button
122 { column: 0, alignment: go.Spot.Right },
123 new go.Binding('text', 'name')),
124 { 'Button.column': 1 } // put Button in second column, to the right of text
125 )
126 },
127 new go.Binding('itemArray', 'items')),
128 // now a checkbox at the bottom of the whole table
129 $('CheckBox', '', // not data bound
130 { row: 3, columnSpan: 2, alignment: go.Spot.Left },
131 // this checkbox is not bound to model data, but it does toggle the Part.movable
132 // property of the Node that this is in
133 $(go.TextBlock, 'Node is not movable'),
134 {
135 '_doClick': function (e, obj) {
136 if (obj.part !== null) obj.part.movable = !obj.part.movable; // toggle the Part.movable flag
137 }
138 })
139 )
140 );
141
142 // but use the default Link template, by not setting Diagram.linkTemplate
143 // create the model data that will be represented by Nodes and Links
144 myDiagram.model =
145 $(go.GraphLinksModel, {
146 copiesArrays: true,
147 copiesArrayObjects: true,
148 'Changed': function (e) {
149 if (e.isTransactionFinished) {
150 const elt = document.getElementById('mySavedModel');
151 if (elt !== null) elt.textContent = myDiagram.model.toJson();
152 }
153 },
154 nodeDataArray: [
155 {
156 key: 'Alpha', color: 'lightblue', choice1: true, choice2: true, choice3: true, choice4: true, choice5: true, choice6: true, choice7: true,
157 items: [{ name: 'item 0' },
158 { name: 'item 1' },
159 { name: 'item 2' }]
160 },
161 {
162 key: 'Beta', color: 'orange',
163 items: [{ name: 'B1', checked: false },
164 { name: 'Bee2', checked: true }]
165 },
166 {
167 key: 'Gamma', color: 'lightgreen',
168 items: [{ name: 'C-one', checked: true },
169 { name: 'C-two', checked: true },
170 { name: 'C-three' }]
171 },
172 {
173 key: 'Delta', color: 'pink', choice1: true, choice2: false,
174 items: []
175 }
176 ],
177 linkDataArray: [
178 { from: 'Alpha', to: 'Beta' },
179 { from: 'Alpha', to: 'Gamma' },
180 { from: 'Gamma', to: 'Delta' },
181 { from: 'Delta', to: 'Alpha' }
182 ]
183 });
184
185 window.myDiagram = myDiagram; // Attach to the window for console debugging
186 </script>
187 </div>
188 <!-- * * * * * * * * * * * * * -->
189 <!-- End of GoJS sample code -->
190 </div>
191</body>
192<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
193<script src="../assets/js/goSamples.js"></script>
194</html>