UNPKG

5.92 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "../release/go.js"], factory);
8 }
9})(function (require, exports) {
10 'use strict';
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.showArrowInfo = exports.infoString = exports.init = void 0;
13 /*
14 * Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
15 */
16 var go = require("../release/go.js");
17 function init() {
18 if (window.goSamples)
19 window.goSamples(); // init for these samples -- you don't need to call this
20 var $ = go.GraphObject.make; // for conciseness in defining templates
21 var myDiagram = $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
22 {
23 isReadOnly: true,
24 layout: $(go.CircularLayout, {
25 radius: 100,
26 spacing: 0,
27 nodeDiameterFormula: go.CircularLayout.Circular,
28 startAngle: 270 // first node will be at top
29 }),
30 // define a DiagramEvent listener
31 'LayoutCompleted': function (e) {
32 // now that the CircularLayout has finished, we know where its center is
33 var cntr = myDiagram.findNodeForKey('Center');
34 if (cntr !== null)
35 cntr.location = myDiagram.layout.actualCenter;
36 }
37 });
38 // construct a shared radial gradient brush
39 var radBrush = $(go.Brush, 'Radial', { 0: '#550266', 1: '#80418C' });
40 // these are the nodes that are in a circle
41 myDiagram.nodeTemplate =
42 $(go.Node, $(go.Shape, 'Circle', {
43 desiredSize: new go.Size(28, 28),
44 fill: radBrush, strokeWidth: 0, stroke: null
45 }), // no outline
46 {
47 locationSpot: go.Spot.Center,
48 click: showArrowInfo,
49 toolTip: // define a tooltip for each link that displays its information
50 $('ToolTip', $(go.TextBlock, { margin: 4 }, new go.Binding('text', '', infoString).ofObject()))
51 });
52 // use a special template for the center node
53 myDiagram.nodeTemplateMap.add('Center', $(go.Node, 'Spot', {
54 selectable: false,
55 isLayoutPositioned: false,
56 locationSpot: go.Spot.Center
57 }, $(go.Shape, 'Circle', { fill: radBrush, strokeWidth: 0, stroke: null, desiredSize: new go.Size(200, 200) }), // no outline
58 $(go.TextBlock, 'Arrowheads', { margin: 1, stroke: 'white', font: 'bold 14px sans-serif' })));
59 // all Links have both "toArrow" and "fromArrow" Shapes,
60 // where both arrow properties are data bound
61 myDiagram.linkTemplate =
62 $(go.Link, // the whole link panel
63 { routing: go.Link.Normal }, $(go.Shape, // the link shape
64 // the first element is assumed to be main element: as if isPanelMain were true
65 { stroke: 'gray', strokeWidth: 2 }), $(go.Shape, // the "from" arrowhead
66 new go.Binding('fromArrow', 'fromArrow'), { scale: 2, fill: '#D4B52C' }), $(go.Shape, // the "to" arrowhead
67 new go.Binding('toArrow', 'toArrow'), { scale: 2, fill: '#D4B52C' }), {
68 click: showArrowInfo,
69 toolTip: // define a tooltip for each link that displays its information
70 $('ToolTip', $(go.TextBlock, { margin: 4 }, new go.Binding('text', '', infoString).ofObject()))
71 });
72 // collect all of the predefined arrowhead names
73 var arrowheads = go.Shape.getArrowheadGeometries().toKeySet().toArray();
74 if (arrowheads.length % 2 === 1)
75 arrowheads.push(''); // make sure there's an even number
76 // create all of the link data, two arrowheads per link
77 var linkdata = [];
78 var i = 0;
79 for (var j = 0; j < arrowheads.length; j = j + 2) {
80 linkdata.push({ from: 'Center', to: i++, toArrow: arrowheads[j], fromArrow: arrowheads[j + 1] });
81 }
82 myDiagram.model =
83 $(go.GraphLinksModel, {
84 // and is then added to the nodeDataArray
85 archetypeNodeData: {},
86 // the node array starts with just the special Center node
87 nodeDataArray: [{ category: 'Center', key: 'Center' }],
88 // the link array was created above
89 linkDataArray: linkdata
90 });
91 }
92 exports.init = init;
93 // a conversion function used to get arrowhead information for a Part
94 function infoString(obj) {
95 var part = obj.part;
96 if (part instanceof go.Adornment)
97 part = part.adornedPart;
98 var msg = '';
99 if (part instanceof go.Link) {
100 var link = part;
101 msg = 'toArrow: ' + link.data.toArrow + ';\nfromArrow: ' + link.data.fromArrow;
102 }
103 else if (part instanceof go.Node) {
104 var node = part;
105 var link = node.linksConnected.first();
106 if (link)
107 msg = 'toArrow: ' + link.data.toArrow + ';\nfromArrow: ' + link.data.fromArrow;
108 }
109 return msg;
110 }
111 exports.infoString = infoString;
112 // a GraphObject.click event handler to show arrowhead information
113 function showArrowInfo(e, obj) {
114 var msg = infoString(obj);
115 if (msg) {
116 var status_1 = document.getElementById('myArrowheadInfo');
117 if (status_1)
118 status_1.textContent = msg;
119 }
120 }
121 exports.showArrowInfo = showArrowInfo;
122});