UNPKG

2.02 kBPlain TextView Raw
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
13import * as go from '../release/go.js';
14import { BalloonLink } from './BalloonLink.js';
15
16export 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 'undoManager.isEnabled': true // enable undo & redo
24 });
25
26 // define a simple Node template
27 myDiagram.nodeTemplate =
28 $(go.Node, 'Auto', // the Shape will go around the TextBlock
29 $(go.Shape, 'Rectangle', { strokeWidth: 0 },
30 // Shape.fill is bound to Node.data.color
31 new go.Binding('fill', 'color')),
32 $(go.TextBlock,
33 { margin: 8 }, // some room around the text
34 // TextBlock.text is bound to Node.data.key
35 new go.Binding('text', 'key'))
36 );
37
38 myDiagram.linkTemplate =
39 $(BalloonLink,
40 $(go.Shape,
41 { stroke: 'limegreen', strokeWidth: 3, fill: 'limegreen' })
42 );
43 // create the model data that will be represented by Nodes and Links
44 myDiagram.model = new go.GraphLinksModel(
45 [
46 { key: 'Alpha', color: 'lightblue' },
47 { key: 'Beta', color: 'orange' }
48 ],
49 [
50 { from: 'Alpha', to: 'Beta' }
51 ]);
52
53 // Attach to the window for console manipulation
54 (window as any).myDiagram = myDiagram;
55}