forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.html
More file actions
716 lines (681 loc) · 37 KB
/
Copy pathevents.html
File metadata and controls
716 lines (681 loc) · 37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
<!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"/>
<link rel="stylesheet" href="../assets/css/style.css"/>
<!-- Copyright 1998-2022 by Northwoods Software Corporation. --> <title> GoJS Events -- Northwoods Software </title>
<link rel="stylesheet" href="../assets/css/prism.css" />
</head>
<script>
window.diagrams = [];
window.goCode = function(pre, w, h, parentid, animation) {
window.diagrams.push([pre, w, h, parentid, animation]);
}
</script>
<body>
<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="mb-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-40 lg:w-48 text-gray-700 bg-white flex-shrink-0">
<div class="flex-shrink-0 px-8 py-4">
<button id="navButton" class="rounded-lg md:hidden focus:outline-none focus:ring" aria-label="Navigation">
<svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
<path id="navOpen" 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="navClosed" 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>
<nav id="navList" class="min-h-screen hidden md:block sidebar-nav flex-grow px-1 lg:px-4 pb-4 md:pb-0 md:overflow-y-auto break-words">
<a href="index.html">Basics</a>
<a href="buildingObjects.html">Building Parts</a>
<a href="usingModels.html">Using Models</a>
<a href="dataBinding.html">Data Binding</a>
<a href="react.html">GoJS with React</a>
<a href="angular.html">GoJS with Angular</a>
<a href="textBlocks.html">TextBlocks</a>
<a href="shapes.html">Shapes</a>
<a href="pictures.html">Pictures</a>
<a href="panels.html">Panels</a>
<a href="tablePanels.html">Table Panels</a>
<a href="brush.html">Brushes</a>
<a href="sizing.html">Sizing Objects</a>
<a href="itemArrays.html">Item Arrays</a>
<a href="changedEvents.html">Changed Events</a>
<a href="transactions.html">Transactions</a>
<a href="viewport.html">Coordinates</a>
<a href="initialView.html">Initial View</a>
<a href="collections.html">Collections</a>
<a href="links.html">Links</a>
<a href="linkLabels.html">Link Labels</a>
<a href="connectionPoints.html">Link Points</a>
<a href="ports.html">Ports</a>
<a href="nodes.html">Nodes</a>
<a href="debugging.html">Debugging</a>
<a href="layouts.html">Layouts</a>
<a href="trees.html">Trees</a>
<a href="subtrees.html">SubTrees</a>
<a href="groups.html">Groups</a>
<a href="subgraphs.html">SubGraphs</a>
<a href="sizedGroups.html">Sized Groups</a>
<a href="selection.html">Selection</a>
<a href="highlighting.html">Highlighting</a>
<a href="animation.html">Animation</a>
<a href="toolTips.html">ToolTips</a>
<a href="contextmenus.html">Context Menus</a>
<a href="events.html">Diagram Events</a>
<a href="tools.html">Tools</a>
<a href="commands.html">Commands</a>
<a href="permissions.html">Permissions</a>
<a href="validation.html">Validation</a>
<a href="HTMLInteraction.html">HTML Interaction</a>
<a href="layers.html">Layers & Z-ordering</a>
<a href="palette.html">Palette</a>
<a href="overview.html">Overview</a>
<a href="resizing.html">Resizing Diagrams</a>
<a href="replacingDeleting.html">Replacing and Deleting</a>
<a href="buttons.html">Buttons</a>
<a href="templateMaps.html">Template Maps</a>
<a href="legends.html">Legends and Titles</a>
<a href="extensions.html">Extensions</a>
<a href="geometry.html">Geometry Strings</a>
<a href="grids.html">Grid Patterns</a>
<a href="graduatedPanels.html">Graduated Panels</a>
<a href="makingImages.html">Diagram Images</a>
<a href="makingSVG.html">Diagram SVG</a>
<a href="printing.html">Printing</a>
<a href="serverSideImages.html">Server-side Images</a>
<a href="nodeScript.html">GoJS in Node.js</a>
<a href="testing.html">Testing</a>
<a href="storage.html">Storage</a>
<a href="performance.html">Performance</a>
<a href="source.html">Building from Source</a>
<a href="platforms.html">Platforms</a>
<a href="deployment.html">Deployment</a>
<a href="typings.html">Typings</a>
</nav>
</div>
<div class="pt-4 px-2 md:px-0 lg:px-4 pb-16 w-full overflow-hidden">
<h1>Events</h1>
<p>
There are three basic kinds of events that <b>GoJS</b> deals with:
<a>DiagramEvent</a>s, <a>InputEvent</a>s, and <a>ChangedEvent</a>s.
This page discusses the first two; see <a href="changedEvents.html">Changed Events</a> for the last kind of event.
</p>
<h2 id="DiagramEvents">Diagram Events</h2>
<p>
<a>DiagramEvent</a>s represent general user-initiated changes to a diagram.
You can register one or more diagram event handlers by calling <a>Diagram.addDiagramListener</a>.
You can also register a diagram event handler in <a>Diagram</a> initialization when calling <a>GraphObject,make</a>.
Each kind of diagram event is distinguished by its name.
</p>
<p>
Currently defined diagram event names include:
</p>
<ul>
<li id="InitialAnimationStarting" onclick="window.location.hash = '#AnimationStarting'">
"<b>InitialAnimationStarting</b>", the initial default animation is about to start;
do not modify the diagram or its model in the event listener.
This can be useful for modifying the <a>AnimationManager.defaultAnimation</a> to make a custom initial animation.
See <a>AnimationManager.initialAnimationStyle</a> for details.
</li>
<li id="AnimationStarting" onclick="window.location.hash = '#AnimationStarting'">
"<b>AnimationStarting</b>", a default animation (<a>AnimationManager.defaultAnimation</a>) is about to start;
do not modify the diagram or its model in the event listener.
</li>
<li id="AnimationFinished" onclick="window.location.hash = '#AnimationFinished'">
"<b>AnimationFinished</b>", a default animation (<a>AnimationManager.defaultAnimation</a>) just completed;
do not modify the diagram or its model in the event listener.
</li>
<li id="BackgroundSingleClicked" onclick="window.location.hash = '#BackgroundSingleClicked'">
"<b>BackgroundSingleClicked</b>", when a mouse left-button single-click happened in the background of the Diagram, not on a Part;
if you make any changes, start and commit your own transaction.
</li>
<li id="BackgroundDoubleClicked" onclick="window.location.hash = '#BackgroundDoubleClicked'">
"<b>BackgroundDoubleClicked</b>", when a mouse left-button double-click happened in the background of the Diagram, not on a Part;
if you make any changes, start and commit your own transaction.
</li>
<li id="BackgroundContextClicked" onclick="window.location.hash = '#BackgroundContextClicked'">
"<b>BackgroundContextClicked</b>", when a mouse right-button single-click happened in the background of the Diagram, not on a Part;
if you make any changes, start and commit your own transaction.
</li>
<li id="ChangingSelection" onclick="window.location.hash = '#ChangingSelection'">
"<b>ChangingSelection</b>", an operation is about to change the <a>Diagram.selection</a> collection,
which is also the value of the <a>DiagramEvent.subject</a>;
do not make any changes to the selection or the diagram or the model in the event listener;
note that just setting <a>Part.isSelected</a> will not raise this event, but tools and commands will.
</li>
<li id="ChangedSelection" onclick="window.location.hash = '#ChangedSelection'">
"<b>ChangedSelection</b>", an operation has just changed the <a>Diagram.selection</a> collection,
which is also the value of the <a>DiagramEvent.subject</a>;
do not make any changes to the selection or the diagram or the model in the event listener;
note that just setting <a>Part.isSelected</a> will not raise this event, but tools and commands will.
</li>
<li id="ClipboardChanged" onclick="window.location.hash = '#ClipboardChanged'">
"<b>ClipboardChanged</b>", Parts have been copied to the clipboard by <a>CommandHandler.copySelection</a>;
the <a>DiagramEvent.subject</a> is the collection of Parts;
if you make any changes, start and commit your own transaction.
</li>
<li id="ClipboardPasted" onclick="window.location.hash = '#ClipboardPasted'">
"<b>ClipboardPasted</b>", Parts have been copied from the clipboard into the Diagram by <a>CommandHandler.pasteSelection</a>;
the <a>DiagramEvent.subject</a> is the <a>Diagram.selection</a>,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="DocumentBoundsChanged" onclick="window.location.hash = '#DocumentBoundsChanged'">
"<b>DocumentBoundsChanged</b>", the area of the diagram's Parts, <a>Diagram.documentBounds</a>, has changed;
the <a>DiagramEvent.parameter</a> is the old Rect.
</li>
<li id="ExternalObjectsDropped" onclick="window.location.hash = '#ExternalObjectsDropped'">
"<b>ExternalObjectsDropped</b>", Parts have been copied into the Diagram by drag-and-drop from outside of the Diagram;
the <a>DiagramEvent.subject</a> is the set of Parts that were dropped (which is also the <a>Diagram.selection</a>),
the <a>DiagramEvent.parameter</a> is the source Diagram,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="GainedFocus" onclick="window.location.hash = '#GainedFocus'">
"<b>GainedFocus</b>", the diagram has gained keyboard focus, such as after a call to <a>Diagram.focus</a>.
</li>
<li id="InitialLayoutCompleted" onclick="window.location.hash = '#InitialLayoutCompleted'">
"<b>InitialLayoutCompleted</b>", the whole diagram layout has updated for the first time since a major change to the Diagram,
such as replacing the Model;
if you make any changes, you do not need to start and commit your own transaction.
</li>
<li id="LayoutCompleted" onclick="window.location.hash = '#LayoutCompleted'">
"<b>LayoutCompleted</b>", the whole diagram layout has just been updated;
if you make any changes, you do not need to start and commit your own transaction.
</li>
<li id="LinkDrawn" onclick="window.location.hash = '#LinkDrawn'">
"<b>LinkDrawn</b>", the user has just created a new Link using <a>LinkingTool</a>;
the <a>DiagramEvent.subject</a> is the new Link,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="LinkRelinked" onclick="window.location.hash = '#LinkRelinked'">
"<b>LinkRelinked</b>", the user has just reconnected an existing Link using <a>RelinkingTool</a> or <a>DraggingTool</a>;
the <a>DiagramEvent.subject</a> is the modified Link,
the <a>DiagramEvent.parameter</a> is the GraphObject port that the link was disconnected from,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="LinkReshaped" onclick="window.location.hash = '#LinkReshaped'">
"<b>LinkReshaped</b>", the user has just rerouted an existing Link using <a>LinkReshapingTool</a>;
the <a>DiagramEvent.subject</a> is the modified Link,
the <a>DiagramEvent.parameter</a> is the List of Points of the link's original route,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="LostFocus" onclick="window.location.hash = '#LostFocus'">
"<b>LostFocus</b>", the diagram has lost keyboard focus ("blur").
</li>
<li id="Modified" onclick="window.location.hash = '#Modified'">
"<b>Modified</b>", the <a>Diagram.isModified</a> property has been set to a new value --
useful for marking a window as having been modified since the last save;
do not modify the Diagram or its Model in the event listener.
</li>
<li id="ObjectSingleClicked" onclick="window.location.hash = '#ObjectSingleClicked'">
"<b>ObjectSingleClicked</b>", a click that occurred on a GraphObject;
the <a>DiagramEvent.subject</a> is the GraphObject;
if you make any changes, start and commit your own transaction.
</li>
<li id="ObjectDoubleClicked" onclick="window.location.hash = '#ObjectDoubleClicked'">
"<b>ObjectDoubleClicked</b>", a double-click that occurred on a GraphObject;
the <a>DiagramEvent.subject</a> is the GraphObject;
if you make any changes, start and commit your own transaction.
</li>
<li id="ObjectContextClicked" onclick="window.location.hash = '#ObjectContextClicked'">
"<b>ObjectContextClicked</b>", a context-click that occurred on a GraphObject;
the <a>DiagramEvent.subject</a> is the GraphObject;
if you make any changes, start and commit your own transaction.
</li>
<li id="PartCreated" onclick="window.location.hash = '#PartCreated'">
"<b>PartCreated</b>", the user inserted a new Part by <a>ClickCreatingTool</a>;
the <a>DiagramEvent.subject</a> is the new Part,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="PartResized" onclick="window.location.hash = '#PartResized'">
"<b>PartResized</b>", the user has changed the size of a GraphObject by <a>ResizingTool</a>;
the <a>DiagramEvent.subject</a> is the GraphObject,
the <a>DiagramEvent.parameter</a> is the original Size,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="PartRotated" onclick="window.location.hash = '#PartRotated'">
"<b>PartRotated</b>", the user has changed the angle of a GraphObject by <a>RotatingTool</a>;
the <a>DiagramEvent.subject</a> is the GraphObject,
the <a>DiagramEvent.parameter</a> is the original angle in degrees,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionMoved" onclick="window.location.hash = '#SelectionMoved'">
"<b>SelectionMoved</b>", the user has moved selected Parts by <a>DraggingTool</a>;
the <a>DiagramEvent.subject</a> is a Set of the moved Parts,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionCopied" onclick="window.location.hash = '#SelectionCopied'">
"<b>SelectionCopied</b>", the user has copied selected Parts by <a>DraggingTool</a>;
the <a>DiagramEvent.subject</a> is Set of the newly copied Parts,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionDeleting" onclick="window.location.hash = '#SelectionDeleting'">
"<b>SelectionDeleting</b>", the user is about to delete selected Parts by <a>CommandHandler.deleteSelection</a>;
the <a>DiagramEvent.subject</a> is the <a>Diagram.selection</a> collection of Parts to be deleted,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionDeleted" onclick="window.location.hash = '#SelectionDeleted'">
"<b>SelectionDeleted</b>", the user has deleted selected Parts by <a>CommandHandler.deleteSelection</a>;
the <a>DiagramEvent.subject</a> is the collection of Parts that were deleted,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionGrouped" onclick="window.location.hash = '#SelectionGrouped'">
"<b>SelectionGrouped</b>", the user has made a new Group out of the selected Parts by <a>CommandHandler.groupSelection</a>;
the <a>DiagramEvent.subject</a> is the new Group,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SelectionUngrouped" onclick="window.location.hash = '#SelectionUngrouped'">
"<b>SelectionUngrouped</b>", the user has removed a selected Group but kept its members by <a>CommandHandler.ungroupSelection</a>;
the <a>DiagramEvent.subject</a> is the collection of Groups that were ungrouped,
the <a>DiagramEvent.parameter</a> is the collection of former member Parts that were ungrouped,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SubGraphCollapsed" onclick="window.location.hash = '#SubGraphCollapsed'">
"<b>SubGraphCollapsed</b>", the user has collapsed selected Groups by <a>CommandHandler.collapseSubGraph</a>;
the <a>DiagramEvent.subject</a> is the collection of Groups that were collapsed,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="SubGraphExpanded" onclick="window.location.hash = '#SubGraphExpanded'">
"<b>SubGraphExpanded</b>", the user has expanded selected Groups by <a>CommandHandler.expandSubGraph</a>;
the <a>DiagramEvent.subject</a> is the collection of Groups that were expanded,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="TextEdited" onclick="window.location.hash = '#TextEdited'">
"<b>TextEdited</b>", the user has changed the string value of a TextBlock by <a>TextEditingTool</a>;
the <a>DiagramEvent.subject</a> is the edited TextBlock,
the <a>DiagramEvent.parameter</a> is the original string,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="TreeCollapsed" onclick="window.location.hash = '#TreeCollapsed'">
"<b>TreeCollapsed</b>", the user has collapsed selected Nodes with subtrees by <a>CommandHandler.collapseTree</a>;
the <a>DiagramEvent.subject</a> is the collection of Nodes that were collapsed,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="TreeExpanded" onclick="window.location.hash = '#TreeExpanded'">
"<b>TreeExpanded</b>", the user has expanded selected Nodes with subtrees by <a>CommandHandler.expandTree</a>;
the <a>DiagramEvent.subject</a> is the collection of Nodes that were expanded,
and this is called within a transaction, so that you do not have to start and commit your own transaction.
</li>
<li id="ViewportBoundsChanged" onclick="window.location.hash = '#ViewportBoundsChanged'">
"<b>ViewportBoundsChanged</b>", the visible area of the Diagram, <a>Diagram.viewportBounds</a>, has changed;
the <a>DiagramEvent.subject</a> is an object whose "scale" property is the old <a>Diagram.scale</a> value,
whose "position" property is the old <a>Diagram.position</a> value,
whose "bounds" property is the old <a>Diagram.viewportBounds</a> value,
whose "canvasSize" property is the old size of the <a>Diagram.div</a>, and
whose "newCanvasSize" property is the new size of the <a>Diagram.div</a>;
the <a>DiagramEvent.parameter</a> is also the old viewportBounds Rect.
Do not modify the Diagram position or scale (i.e. the viewport bounds) in the listener.
</li>
</ul>
<p>
DiagramEvents do not necessarily correspond to mouse events or keyboard events or touch events.
Nor do they necessarily correspond to changes to the diagram's model --
for tracking such changes, use <a>Model.addChangedListener</a> or <a>Diagram.addModelChangedListener</a>.
DiagramEvents only occur because the user did something, perhaps indirectly.
</p>
<p>
<p>
In addition to the DiagramEvent listeners there are also circumstances where detecting such changes is common
enough to warrant having properties that are event handlers.
Because these events do not necessarily correspond to any particular input or diagram event,
these event handlers have custom arguments that are specific to the situation.
</p>
<p>
One very common such event property is <a>GraphObject.click</a>, which if non-null is a function that is called
whenever the user clicks on that object.
This is most commonly used to specify behavior for "Button"s, but it and the other "click" event properties,
"doubleClick" and "contextClick", can be useful on any GraphObject.
</p>
<p>
Another common event property is <a>Part.selectionChanged</a>,
which (if non-null) is called whenever <a>Part.isSelected</a> changes.
In this case the event hander function is passed a single argument, the Part.
There is no need for additional arguments because the function can check the current value of <a>Part.isSelected</a> to decide what to do.
</p>
</p>
<p>
Model <a>ChangedEvent</a>s are more complete and reliable than depending on <a>DiagramEvent</a>s.
For example, the "LinkDrawn" DiagramEvent is not raised when code adds a link to a diagram.
That DiagramEvent is only raised when the user draws a new link using the <a>LinkingTool</a>.
Furthermore the link has not yet been routed, so <a>Link.points</a> will not have been computed.
In fact, creating a new link may invalidate a <a>Layout</a>, so all of the nodes may be moved in the near future.
</p>
<p class="box bg-danger">
Sometimes you want to update a database as the user makes changes to a diagram.
Usually you will want to implement a <a>Model</a> <a>ChangedEvent</a> listener,
by calling <a>Model.addChangedListener</a> or <a>Diagram.addModelChangedListener</a>,
that notices the changes to the model and decides what to record in the database.
See the discussion of <a href="changedEvents.html">Changed Events</a> and the <a href="../samples/UpdateDemo.html">Update Demo</a>.
</p>
<p>
This example demonstrates handling several diagram events: <b>"ObjectSingleClicked"</b>,
<b>"BackgroundDoubleClicked"</b>, and <b>"ClipboardPasted"</b>.
</p>
<pre class="lang-js" id="diagramEvents"><code>
function showMessage(s) {
document.getElementById("diagramEventsMsg").textContent = s;
}
diagram.addDiagramListener("ObjectSingleClicked",
function(e) {
var part = e.subject.part;
if (!(part instanceof go.Link)) showMessage("Clicked on " + part.data.key);
});
diagram.addDiagramListener("BackgroundDoubleClicked",
function(e) { showMessage("Double-clicked at " + e.diagram.lastInput.documentPoint); });
diagram.addDiagramListener("ClipboardPasted",
function(e) { showMessage("Pasted " + e.diagram.selection.count + " parts"); });
var nodeDataArray = [
{ key: "Alpha" },
{ key: "Beta", group: "Omega" },
{ key: "Gamma", group: "Omega" },
{ key: "Omega", isGroup: true },
{ key: "Delta" }
];
var linkDataArray = [
{ from: "Alpha", to: "Beta" }, // from outside the Group to inside it
{ from: "Beta", to: "Gamma" }, // this link is a member of the Group
{ from: "Omega", to: "Delta" } // from the Group to a Node
];
diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
</code></pre>
<script>goCode("diagramEvents", 600, 200)</script>
<span id="diagramEventsMsg" style="color: red">(message)</span>
<h2 id="InputEvents">Input Events</h2>
<p>
When a low-level HTML DOM event occurs, <b>GoJS</b> canonicalizes the keyboard/mouse/touch event information
into a new <a>InputEvent</a> that can be passed to various event-handling methods and saved for later examination.
</p>
<p>
An InputEvent keeps the <a>InputEvent.key</a> for keyboard events,
the <a>InputEvent.button</a> for mouse events,
the <a>InputEvent.viewPoint</a> for mouse and touch events,
and <a>InputEvent.modifiers</a> for keyboard and mouse events.
</p>
<p>
The diagram's event handlers also record the <a>InputEvent.documentPoint</a>,
which is the <a>InputEvent.viewPoint</a> in document coordinates at the time of the mouse event,
and the <a>InputEvent.timestamp</a>, which records the time that the event occurred in milliseconds.
</p>
<p>
The InputEvent class also provides many handy properties for particular kinds of events.
Examples include <a>InputEvent.control</a> (if the control key had been pressed) and
<a>InputEvent.left</a> (if the left/primary mouse button was pressed).
</p>
<p>
Some tools find the "current" <a>GraphObject</a> at the mouse point.
This is remembered as the <a>InputEvent.targetObject</a>.
</p>
<h2 id="HigherLevelInputEvents">Higher-level input events</h2>
<p>
Some tools detect a sequence of input events to compose somewhat more abstract user events.
Examples include "click" (mouse-down-and-up very close to each other) and "hover" (motionless mouse for some time).
The tools will call an event handler (if there is any) for the current <a>GraphObject</a> at the mouse point.
The event handler is held as the value of a property on the object.
It then also "bubbles" the event up the chain of <a>GraphObject.panel</a>s until it ends with a <a>Part</a>.
This allows a "click" event handler to be declared on a <a>Panel</a> and have it apply even if the click actually happens on an element deep inside the panel.
If there is no object at the mouse point, the event occurs on the diagram.
</p>
<p>
Click-like event properties include <a>GraphObject.click</a>, <a>GraphObject.doubleClick</a>, and <a>GraphObject.contextClick</a>.
They also occur when there is no GraphObject -- the event happened in the diagram's background:
<a>Diagram.click</a>, <a>Diagram.doubleClick</a>, and <a>Diagram.contextClick</a>.
These are all properties that you can set to a function that is the event handler.
These events are caused by both mouse events and touch events.
</p>
<p>
Mouse-over-like event properties include <a>GraphObject.mouseEnter</a>, <a>GraphObject.mouseOver</a>, and <a>GraphObject.mouseLeave</a>.
But only <a>Diagram.mouseOver</a> applies to the diagram.
</p>
<p>
Hover-like event properties include <a>GraphObject.mouseHover</a> and <a>GraphObject.mouseHold</a>.
The equivalent diagram properties are <a>Diagram.mouseHover</a> and <a>Diagram.mouseHold</a>.
</p>
<p>
There are also event properties for dragging operations: <a>GraphObject.mouseDragEnter</a>, <a>GraphObject.mouseDragLeave</a>, and <a>GraphObject.mouseDrop</a>.
These apply to stationary objects, not the objects being dragged.
And they also occur when dragging by touch events, not just mouse events.
</p>
<p>
This example demonstrates handling three higher-level input events:
clicking on nodes and entering/leaving groups.
</p>
<pre class="lang-js" id="inputEvents"><code>
function showMessage(s) {
document.getElementById("inputEventsMsg").textContent = s;
}
diagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "Ellipse", { fill: "white" }),
$(go.TextBlock,
new go.Binding("text", "key")),
{ click: function(e, obj) { showMessage("Clicked on " + obj.part.data.key); } }
);
diagram.groupTemplate =
$(go.Group, "Vertical",
$(go.TextBlock,
{ alignment: go.Spot.Left, font: "Bold 12pt Sans-Serif" },
new go.Binding("text", "key")),
$(go.Panel, "Auto",
$(go.Shape, "RoundedRectangle",
{ name: "SHAPE",
parameter1: 14,
fill: "rgba(128,128,128,0.33)" }),
$(go.Placeholder, { padding: 5 })
),
{ mouseEnter: function(e, obj, prev) { // change group's background brush
var shape = obj.part.findObject("SHAPE");
if (shape) shape.fill = "red";
},
mouseLeave: function(e, obj, next) { // restore to original brush
var shape = obj.part.findObject("SHAPE");
if (shape) shape.fill = "rgba(128,128,128,0.33)";
} });
var nodeDataArray = [
{ key: "Alpha" },
{ key: "Beta", group: "Omega" },
{ key: "Gamma", group: "Omega" },
{ key: "Omega", isGroup: true },
{ key: "Delta" }
];
var linkDataArray = [
{ from: "Alpha", to: "Beta" }, // from outside the Group to inside it
{ from: "Beta", to: "Gamma" }, // this link is a member of the Group
{ from: "Omega", to: "Delta" } // from the Group to a Node
];
diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
</code></pre>
<script>goCode("inputEvents", 600, 200)</script>
<span id="inputEventsMsg" style="color: red">(message)</span>
<h2 id="ClickingAndSelecting">Clicking and Selecting</h2>
<p>
This example demonstrates both the "click" and the "selectionChanged" events:
</p>
<pre class="lang-js" id="changeMethods"><code>
function showMessage(s) {
document.getElementById("changeMethodsMsg").textContent = s;
}
diagram.nodeTemplate =
$(go.Node, "Auto",
{ selectionAdorned: false },
$(go.Shape, "Ellipse", { fill: "white" }),
$(go.TextBlock,
new go.Binding("text", "key")),
{
click: function(e, obj) { showMessage("Clicked on " + obj.part.data.key); },
selectionChanged: function(part) {
var shape = part.elt(0);
shape.fill = part.isSelected ? "red" : "white";
}
}
);
var nodeDataArray = [
{ key: "Alpha" }, { key: "Beta" }, { key: "Gamma" }
];
var linkDataArray = [
{ from: "Alpha", to: "Beta" },
{ from: "Beta", to: "Gamma" }
];
diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
</code></pre>
<script>goCode("changeMethods", 600, 200)</script>
<span id="changeMethodsMsg" style="color: red">(message)</span>
<p>
Try Ctrl-A to select everything.
Note the distinction between the <a>GraphObject.click</a> event property and the <a>Part.selectionChanged</a> event property.
Both are methods that get called when something has happened to the node.
The <a>GraphObject.click</a> occurs when the user clicks on the node, which happens to select the node.
But the <a>Part.selectionChanged</a> occurs even when there is no click event or even any mouse event --
it was due to a property change to the node.
</p>
</div>
</div>
<div class="bg-nwoods-primary">
<section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
<p id="version" class="leading-none mb-2 my-4">GoJS</p>
</section>
</div><footer class="bg-nwoods-primary text-white">
<div class="container max-w-screen-lg mx-auto px-8">
<div class="w-full py-6">
<div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
<ul class="text-sm font-medium pb-6 grid grid-cols-2 sm:grid-cols-3 gap-y-10">
<li class="list-none row-span-2">
<h2 class="text-base font-semibold tracking-wide">GoJS</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="../samples/index.html">Samples</a>
</li>
<li>
<a href="../learn/index.html">Learn</a>
</li>
<li>
<a href="../intro/index.html">Intro</a>
</li>
<li>
<a href="../api/index.html">API</a>
</li>
<li>
<a href="../changelog.html">Changelog</a>
</li>
<li>
<a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
</li>
</ul>
</li>
<li class="list-none row-span-2">
<h2 class="text-base font-semibold tracking-wide">Support</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="https://www.nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
</li>
<li>
<a href="https://forum.nwoods.com/c/gojs">Forum</a>
</li>
<li>
<a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
</li>
<li>
<a 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>
<li>
<a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
</li>
</ul>
</li>
<li class="list-none row-span-2">
<h2 class="text-base font-semibold tracking-wide">Company</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a target="_blank" href="https://www.nwoods.com">Northwoods</a>
</li>
<li>
<a target="_blank" href="https://www.nwoods.com/about.html">About Us</a>
</li>
<li>
<a target="_blank" href="https://www.nwoods.com/contact.html">Contact Us</a>
</li>
<li>
<a target="_blank" href="https://www.nwoods.com/consulting.html">Consulting</a>
</li>
<li>
<a target="_blank" href="https://twitter.com/northwoodsgo">Twitter</a>
</li>
</ul>
</li>
</ul>
<p class="text-sm text-gray-100 md:mb-6">
Copyright 1998-2022 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
</p>
</div>
</div>
</footer> </body>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('config', 'UA-1506307-5');
var getOutboundLink = function(url, label) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': label,
'transport_type': 'beacon'
});
}
// topnav
var topButton = document.getElementById("topnavButton");
var topnavList = document.getElementById("topnavList");
topButton.addEventListener("click", function() {
this.classList.toggle("active");
topnavList.classList.toggle("hidden");
document.getElementById("topnavOpen").classList.toggle("hidden");
document.getElementById("topnavClosed").classList.toggle("hidden");
});
</script>
<script src="../assets/js/prism.js"></script>
<script src="../release/go.js"></script>
<script src="../assets/js/goDoc.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
if (window.goDoc) window.goDoc();
var d = window.diagrams;
for (var i = 0; i < d.length; i++) {
var dargs = d[i];
goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
}
if (window.extra) window.extra();
});
</script>
</html>