1 | /*
|
2 | * Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
|
3 | */
|
4 |
|
5 | /*
|
6 | * This is an extension and not part of the main GoJS library.
|
7 | * Note that the API for this class may change with any version, even point releases.
|
8 | * If you intend to use an extension in production, you should copy the code to your own source directory.
|
9 | * Extensions can be found in the GoJS kit under the extensions or extensionsTS folders.
|
10 | * See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
|
11 | */
|
12 |
|
13 | import * as go from '../release/go.js';
|
14 | import { GuidedDraggingTool } from './GuidedDraggingTool.js';
|
15 |
|
16 | export function init() {
|
17 | if ((window as any).goSamples) (window as any).goSamples(); // init for these samples -- you don't need to call this
|
18 |
|
19 | const $ = go.GraphObject.make; // for conciseness in defining templates
|
20 |
|
21 | const myDiagram = $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
|
22 | {
|
23 | draggingTool: new GuidedDraggingTool(), // defined in GuidedDraggingTool.js
|
24 | 'draggingTool.horizontalGuidelineColor': 'blue',
|
25 | 'draggingTool.verticalGuidelineColor': 'blue',
|
26 | 'draggingTool.centerGuidelineColor': 'green',
|
27 | 'draggingTool.guidelineWidth': 1,
|
28 | 'undoManager.isEnabled': true // enable undo & redo
|
29 | });
|
30 |
|
31 | // define a simple Node template
|
32 | myDiagram.nodeTemplate =
|
33 | $(go.Node, 'Auto', // the Shape will go around the TextBlock
|
34 | $(go.Shape, 'RoundedRectangle', { strokeWidth: 0 },
|
35 | // Shape.fill is bound to Node.data.color
|
36 | new go.Binding('fill', 'color')),
|
37 | $(go.TextBlock,
|
38 | { margin: 8 }, // some room around the text
|
39 | // TextBlock.text is bound to Node.data.key
|
40 | new go.Binding('text', 'key'))
|
41 | );
|
42 |
|
43 | // but use the default Link template, by not setting Diagram.linkTemplate
|
44 |
|
45 | // create the model data that will be represented by Nodes and Links
|
46 | myDiagram.model = new go.GraphLinksModel(
|
47 | [
|
48 | { key: 'Alpha', color: 'lightblue' },
|
49 | { key: 'Beta', color: 'orange' },
|
50 | { key: 'Gamma', color: 'lightgreen' },
|
51 | { key: 'Delta', color: 'pink' }
|
52 | ],
|
53 | [
|
54 | { from: 'Alpha', to: 'Beta' },
|
55 | { from: 'Alpha', to: 'Gamma' },
|
56 | { from: 'Beta', to: 'Beta' },
|
57 | { from: 'Gamma', to: 'Delta' },
|
58 | { from: 'Delta', to: 'Alpha' }
|
59 | ]);
|
60 |
|
61 | // Attach to the window for console manipulation
|
62 | (window as any).myDiagram = myDiagram;
|
63 | }
|