UNPKG

1.66 kBPlain TextView Raw
1'use strict';
2/*
3* Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
4*/
5
6import * as go from '../release/go.js';
7
8export function init() {
9 if ((window as any).goSamples) (window as any).goSamples(); // init for these samples -- you don't need to call this
10
11 const $ = go.GraphObject.make; // for conciseness in defining templates
12
13 const myDiagram = $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
14 {
15 'undoManager.isEnabled': true // enable undo & redo
16 });
17
18 // define a simple Node template
19 myDiagram.nodeTemplate =
20 $(go.Node, 'Auto', // the Shape will go around the TextBlock
21 $(go.Shape, 'RoundedRectangle', { strokeWidth: 0 },
22 // Shape.fill is bound to Node.data.color
23 new go.Binding('fill', 'color')),
24 $(go.TextBlock,
25 { margin: 8 }, // some room around the text
26 // TextBlock.text is bound to Node.data.key
27 new go.Binding('text', 'key'))
28 );
29
30 // but use the default Link template, by not setting Diagram.linkTemplate
31
32 // create the model data that will be represented by Nodes and Links
33 myDiagram.model = new go.GraphLinksModel(
34 [
35 { key: 'Alpha', color: 'lightblue' },
36 { key: 'Beta', color: 'orange' },
37 { key: 'Gamma', color: 'lightgreen' },
38 { key: 'Delta', color: 'pink' }
39 ],
40 [
41 { from: 'Alpha', to: 'Beta' },
42 { from: 'Alpha', to: 'Gamma' },
43 { from: 'Beta', to: 'Beta' },
44 { from: 'Gamma', to: 'Delta' },
45 { from: 'Delta', to: 'Alpha' }
46 ]);
47
48 // Attach to the window for console manipulation
49 (window as any).myDiagram = myDiagram;
50}