Skip to content

Commit 3b912e1

Browse files
committed
show off new skipsDiagramUpdate
1 parent a5da8d3 commit 3b912e1

File tree

4 files changed

+87
-36
lines changed

4 files changed

+87
-36
lines changed

package-lock.json

Lines changed: 61 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@angular/platform-browser-dynamic": "~9.0.1",
2222
"@angular/router": "~9.0.1",
2323
"core-js": "^3.6.4",
24-
"gojs": "^2.1.8",
25-
"gojs-angular": "1.0.2",
24+
"gojs": "^2.1.10",
25+
"gojs-angular": "^1.0.3",
2626
"rxjs": "~6.5.4",
2727
"tslib": "^1.10.0",
2828
"zone.js": "~0.10.2"

src/app/app.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ <h1>GoJS / Angular - Components Sample</h1>
1111
<div class="left">
1212
Diagram
1313
<gojs-diagram #myDiagram [initDiagram]='initDiagram' [nodeDataArray]='diagramNodeData' [linkDataArray]='diagramLinkData'
14-
[divClassName]='diagramDivClassName' [modelData]='diagramModelData' (modelChange)='diagramModelChange($event)'>
14+
[divClassName]='diagramDivClassName' [modelData]='diagramModelData' [skipsDiagramUpdate]='skipsDiagramUpdate'
15+
(modelChange)='diagramModelChange($event)'>
1516
</gojs-diagram>
1617
</div>
1718

src/app/app.component.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export class AppComponent {
2828
)
2929
});
3030

31+
dia.commandHandler.archetypeGroupData = { key: 'Group', isGroup: true };
32+
33+
3134
const makePort = function(id: string, spot: go.Spot) {
3235
return $(go.Shape, 'Circle',
3336
{
@@ -42,6 +45,17 @@ export class AppComponent {
4245
// define the Node template
4346
dia.nodeTemplate =
4447
$(go.Node, 'Spot',
48+
{
49+
contextMenu:
50+
$('ContextMenu',
51+
$('ContextMenuButton',
52+
$(go.TextBlock, 'Group'),
53+
{ click: function(e, obj) { e.diagram.commandHandler.groupSelection(); } },
54+
new go.Binding('visible', '', function(o) {
55+
return o.diagram.selection.count > 1;
56+
}).ofObject())
57+
)
58+
},
4559
$(go.Panel, 'Auto',
4660
$(go.Shape, 'RoundedRectangle', { stroke: null },
4761
new go.Binding('fill', 'color')
@@ -74,9 +88,15 @@ export class AppComponent {
7488
];
7589
public diagramDivClassName: string = 'myDiagramDiv';
7690
public diagramModelData = { prop: 'value' };
91+
public skipsDiagramUpdate = false;
7792

7893
// When the diagram model changes, update app data to reflect those changes
7994
public diagramModelChange = function(changes: go.IncrementalData) {
95+
// when setting state here, be sure to set skipsDiagramUpdate: true since GoJS already has this update
96+
// (since this is a GoJS model changed listener event function)
97+
// this way, we don't log an unneeded transaction in the Diagram's undoManager history
98+
this.skipsDiagramUpdate = true;
99+
80100
this.diagramNodeData = DataSyncService.syncNodeData(changes, this.diagramNodeData);
81101
this.diagramLinkData = DataSyncService.syncLinkData(changes, this.diagramLinkData);
82102
this.diagramModelData = DataSyncService.syncModelData(changes, this.diagramModelData);
@@ -171,6 +191,8 @@ export class AppComponent {
171191
}
172192

173193
if (index >= 0) {
194+
// here, we set skipsDiagramUpdate to false, since GoJS does not yet have this update
195+
this.skipsDiagramUpdate = false;
174196
this.diagramNodeData[index] = { key: newNodeData.key, color: newNodeData.color };
175197
}
176198
}

0 commit comments

Comments
 (0)