1 | /*
|
2 | * Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
|
3 | */
|
4 | (function (factory) {
|
5 | if (typeof module === "object" && typeof module.exports === "object") {
|
6 | var v = factory(require, exports);
|
7 | if (v !== undefined) module.exports = v;
|
8 | }
|
9 | else if (typeof define === "function" && define.amd) {
|
10 | define(["require", "exports", "../release/go.js", "./DataInspector.js"], factory);
|
11 | }
|
12 | })(function (require, exports) {
|
13 | ;
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | exports.init = void 0;
|
16 | /*
|
17 | * This is an extension and not part of the main GoJS library.
|
18 | * Note that the API for this class may change with any version, even point releases.
|
19 | * If you intend to use an extension in production, you should copy the code to your own source directory.
|
20 | * Extensions can be found in the GoJS kit under the extensions or extensionsTS folders.
|
21 | * See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
|
22 | */
|
23 | var go = require("../release/go.js");
|
24 | var DataInspector_js_1 = require("./DataInspector.js");
|
25 | function init() {
|
26 | if (window.goSamples)
|
27 | window.goSamples(); // init for these samples -- you don't need to call this
|
28 | var $ = go.GraphObject.make; // for conciseness in defining templates
|
29 | var myDiagram = $(go.Diagram, 'myDiagramDiv', // create a Diagram for the DIV HTML element
|
30 | {
|
31 | 'animationManager.isEnabled': false,
|
32 | // allow double-click in background to create a new node
|
33 | 'clickCreatingTool.archetypeNodeData': { text: 'Node', color: 'white' },
|
34 | // allow Ctrl-G to call groupSelection()
|
35 | 'commandHandler.archetypeGroupData': { text: 'Group', isGroup: true, color: 'blue' },
|
36 | // enable undo & redo
|
37 | 'undoManager.isEnabled': true,
|
38 | // automatically show the state of the diagram's model on the page
|
39 | 'ModelChanged': function (e) {
|
40 | if (e.isTransactionFinished) {
|
41 | var elt = document.getElementById('savedModel');
|
42 | if (elt !== null)
|
43 | elt.textContent = myDiagram.model.toJson();
|
44 | }
|
45 | }
|
46 | });
|
47 | // These nodes have text surrounded by a rounded rectangle
|
48 | // whose fill color is bound to the node data.
|
49 | // The user can drag a node by dragging its TextBlock label.
|
50 | // Dragging from the Shape will start drawing a new link.
|
51 | myDiagram.nodeTemplate =
|
52 | $(go.Node, 'Auto', { locationSpot: go.Spot.Center }, new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, 'Rectangle', {
|
53 | stroke: null, strokeWidth: 0,
|
54 | fill: 'white',
|
55 | portId: '', cursor: 'pointer',
|
56 | // allow all kinds of links from and to this port
|
57 | fromLinkable: true, fromLinkableSelfNode: true, fromLinkableDuplicates: true,
|
58 | toLinkable: true, toLinkableSelfNode: true, toLinkableDuplicates: true
|
59 | }, new go.Binding('fill', 'color')), $(go.TextBlock, {
|
60 | font: 'bold 18px sans-serif',
|
61 | stroke: '#111',
|
62 | margin: 8,
|
63 | isMultiline: false,
|
64 | editable: true // allow in-place editing by user
|
65 | }, new go.Binding('text', 'text').makeTwoWay()));
|
66 | // The link shape and arrowhead have their stroke brush data bound to the "color" property
|
67 | myDiagram.linkTemplate =
|
68 | $(go.Link, { toShortLength: 3, relinkableFrom: true, relinkableTo: true }, // allow the user to relink existing links
|
69 | $(go.Shape, { strokeWidth: 2 }, new go.Binding('stroke', 'color')), $(go.Shape, { toArrow: 'Standard', stroke: null }, new go.Binding('fill', 'color')));
|
70 | // Groups consist of a title in the color given by the group node data
|
71 | // above a translucent gray rectangle surrounding the member parts
|
72 | myDiagram.groupTemplate =
|
73 | $(go.Group, 'Vertical', {
|
74 | selectionObjectName: 'PANEL',
|
75 | ungroupable: true
|
76 | }, // enable Ctrl-Shift-G to ungroup a selected Group
|
77 | $(go.TextBlock, {
|
78 | font: 'bold 19px sans-serif',
|
79 | isMultiline: false,
|
80 | editable: true // allow in-place editing by user
|
81 | }, new go.Binding('text', 'text').makeTwoWay(), new go.Binding('stroke', 'color')), $(go.Panel, 'Auto', { name: 'PANEL' }, $(go.Shape, 'Rectangle', // the rectangular shape around the members
|
82 | { fill: 'rgba(128,128,128,0.2)', stroke: 'gray', strokeWidth: 3 }), $(go.Placeholder, { padding: 10 }) // represents where the members are
|
83 | ));
|
84 | // Create the Diagram's Model:
|
85 | var nodeDataArray = [
|
86 | { key: 1, text: 'Alpha', color: '#B2DFDB', state: 'one' },
|
87 | { key: 2, text: 'Beta', color: '#B2B2DB', state: 'two', password: '1234' },
|
88 | { key: 3, text: 'Gamma', color: '#1DE9B6', state: 2, group: 5, flag: false, choices: [1, 2, 3, 4, 5] },
|
89 | { key: 4, text: 'Delta', color: '#00BFA5', state: 'three', group: 5, flag: true },
|
90 | { key: 5, text: 'Epsilon', color: '#00BFA5', isGroup: true }
|
91 | ];
|
92 | var linkDataArray = [
|
93 | { from: 1, to: 2, color: '#5E35B1' },
|
94 | { from: 2, to: 2, color: '#5E35B1' },
|
95 | { from: 3, to: 4, color: '#6200EA' },
|
96 | { from: 3, to: 1, color: '#6200EA' }
|
97 | ];
|
98 | myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
99 | // myDiagram.model = go.Model.fromJson((document.getElementById('mySavedModel') as any).value);
|
100 | // some shared model data
|
101 | myDiagram.model.modelData = { test: true, hello: 'world', version: 42 };
|
102 | // select a Node, so that the first Inspector shows something
|
103 | myDiagram.select(myDiagram.nodes.first());
|
104 | // Declare which properties to show and how.
|
105 | // By default, all properties on the model data objects are shown unless the inspector option "includesOwnProperties" is set to false.
|
106 | // Show the primary selection's data, or blanks if no Part is selected:
|
107 | var inspector1 = new DataInspector_js_1.Inspector('myInspectorDiv1', myDiagram, {
|
108 | // allows for multiple nodes to be inspected at once
|
109 | multipleSelection: true,
|
110 | // max number of node properties will be shown when multiple selection is true
|
111 | showLimit: 4,
|
112 | // when multipleSelection is true, when showUnionProperties is true it takes the union of properties
|
113 | // otherwise it takes the intersection of properties
|
114 | showUnionProperties: true,
|
115 | // uncomment this line to only inspect the named properties below instead of all properties on each object:
|
116 | // includesOwnProperties: false,
|
117 | properties: {
|
118 | 'text': {},
|
119 | // key would be automatically added for nodes, but we want to declare it read-only also:
|
120 | 'key': { readOnly: true, show: DataInspector_js_1.Inspector.showIfPresent },
|
121 | // color would be automatically added for nodes, but we want to declare it a color also:
|
122 | 'color': { show: DataInspector_js_1.Inspector.showIfPresent, type: 'color' },
|
123 | // Comments and LinkComments are not in any node or link data (yet), so we add them here:
|
124 | 'Comments': { show: DataInspector_js_1.Inspector.showIfNode },
|
125 | 'LinkComments': { show: DataInspector_js_1.Inspector.showIfLink },
|
126 | 'isGroup': { readOnly: true, show: DataInspector_js_1.Inspector.showIfPresent },
|
127 | 'flag': { show: DataInspector_js_1.Inspector.showIfNode, type: 'checkbox' },
|
128 | 'state': {
|
129 | show: DataInspector_js_1.Inspector.showIfNode,
|
130 | type: 'select',
|
131 | choices: function (node, propName) {
|
132 | if (Array.isArray(node.data.choices))
|
133 | return node.data.choices;
|
134 | return ['one', 'two', 'three', 'four', 'five'];
|
135 | }
|
136 | },
|
137 | 'choices': { show: false },
|
138 | // an example of specifying the <input> type
|
139 | 'password': { show: DataInspector_js_1.Inspector.showIfPresent, type: 'password' }
|
140 | }
|
141 | });
|
142 | // Always show the first Node:
|
143 | var inspector2 = new DataInspector_js_1.Inspector('myInspectorDiv2', myDiagram, {
|
144 | // By default the inspector works on the Diagram selection.
|
145 | // This property lets us inspect a specific object by calling Inspector.inspectObject(object)
|
146 | inspectSelection: false,
|
147 | properties: {
|
148 | 'text': {},
|
149 | // This property we want to declare as a color, to show a color-picker:
|
150 | 'color': { type: 'color' },
|
151 | // key would be automatically added for node data, but we want to declare it read-only also:
|
152 | 'key': { readOnly: true, show: DataInspector_js_1.Inspector.showIfPresent(myDiagram.selection.first(), 'key') }
|
153 | }
|
154 | });
|
155 | // If not inspecting a selection, you can programatically decide what to inspect (a Part, or a JavaScript object)
|
156 | // Here, we inspect the first node, if available
|
157 | var firstnode = myDiagram.nodes.first();
|
158 | if (firstnode !== null)
|
159 | inspector2.inspectObject(firstnode.data);
|
160 | // Always show the model.modelData:
|
161 | var inspector3 = new DataInspector_js_1.Inspector('myInspectorDiv3', myDiagram, {
|
162 | inspectSelection: false
|
163 | });
|
164 | inspector3.inspectObject(myDiagram.model.modelData);
|
165 | // Attach to the window for console manipulation
|
166 | window.myDiagram = myDiagram;
|
167 | window.inspector1 = inspector1;
|
168 | window.inspector2 = inspector2;
|
169 | window.inspector3 = inspector3;
|
170 | }
|
171 | exports.init = init;
|
172 | });
|