UNPKG

1.99 kBPlain TextView Raw
1/*
2* Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
3*/
4
5import * as go from '../release/go.js';
6import { RotateMultipleTool } from './RotateMultipleTool.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 rotatingTool: new RotateMultipleTool(), // defined in RotateMultipleTool.js
16 'undoManager.isEnabled': true // enable undo & redo
17 });
18
19 // define a simple Node template
20 myDiagram.nodeTemplate =
21 $(go.Node, 'Auto', // the Shape will go around the TextBlock
22 { locationSpot: go.Spot.Center, rotatable: true },
23 new go.Binding('location', 'location', go.Point.parse).makeTwoWay(go.Point.stringify),
24 new go.Binding('angle').makeTwoWay(), // save the modified Node.angle in the model data
25 $(go.Shape, 'RoundedRectangle', { strokeWidth: 0 },
26 // Shape.fill is bound to Node.data.color
27 new go.Binding('fill', 'color')),
28 $(go.TextBlock,
29 { margin: 8 }, // some room around the text
30 // TextBlock.text is bound to Node.data.key
31 new go.Binding('text', 'key'))
32 );
33
34 // but use the default Link template, by not setting Diagram.linkTemplate
35
36 // create the model data that will be represented by Nodes and Links
37 myDiagram.model = new go.GraphLinksModel(
38 [
39 { key: 'Alpha', color: 'lightblue' },
40 { key: 'Beta', color: 'orange' },
41 { key: 'Gamma', color: 'lightgreen' },
42 { key: 'Delta', color: 'pink' }
43 ],
44 [
45 { from: 'Alpha', to: 'Beta' },
46 { from: 'Alpha', to: 'Gamma' },
47 { from: 'Beta', to: 'Beta' },
48 { from: 'Gamma', to: 'Delta' },
49 { from: 'Delta', to: 'Alpha' }
50 ]);
51}