1 |
|
2 |
|
3 |
|
4 | var __extends = (this && this.__extends) || (function () {
|
5 | var extendStatics = function (d, b) {
|
6 | extendStatics = Object.setPrototypeOf ||
|
7 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
8 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
9 | return extendStatics(d, b);
|
10 | };
|
11 | return function (d, b) {
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | (function (factory) {
|
18 | if (typeof module === "object" && typeof module.exports === "object") {
|
19 | var v = factory(require, exports);
|
20 | if (v !== undefined) module.exports = v;
|
21 | }
|
22 | else if (typeof define === "function" && define.amd) {
|
23 | define(["require", "exports", "../release/go.js", "./TableLayout.js"], factory);
|
24 | }
|
25 | })(function (require, exports) {
|
26 | "use strict";
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.init = void 0;
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | var go = require("../release/go.js");
|
37 | var TableLayout_js_1 = require("./TableLayout.js");
|
38 |
|
39 | var LaneResizingTool = (function (_super) {
|
40 | __extends(LaneResizingTool, _super);
|
41 | function LaneResizingTool() {
|
42 | return _super !== null && _super.apply(this, arguments) || this;
|
43 | }
|
44 | LaneResizingTool.prototype.computeMinSize = function () {
|
45 | var diagram = this.diagram;
|
46 | if (this.adornedObject === null)
|
47 | return new go.Size();
|
48 | var lane = this.adornedObject.part;
|
49 | if (lane === null)
|
50 | return new go.Size();
|
51 | var horiz = (lane.category === 'Column Header');
|
52 | var margin = diagram.nodeTemplate.margin;
|
53 | var bounds = new go.Rect();
|
54 | diagram.findTopLevelGroups().each(function (g) {
|
55 | if (lane === null)
|
56 | return;
|
57 | if (horiz ? (g.column === lane.column) : (g.row === lane.row)) {
|
58 | var b = diagram.computePartsBounds(g.memberParts);
|
59 | if (b.isEmpty())
|
60 | return;
|
61 | b.unionPoint(g.location);
|
62 | b.addMargin(margin);
|
63 | if (bounds.isEmpty()) {
|
64 | bounds = b;
|
65 | }
|
66 | else {
|
67 | bounds.unionRect(b);
|
68 | }
|
69 | }
|
70 | });
|
71 |
|
72 | var msz = _super.prototype.computeMinSize.call(this);
|
73 | if (bounds.isEmpty())
|
74 | return msz;
|
75 | return new go.Size(Math.max(msz.width, bounds.width), Math.max(msz.height, bounds.height));
|
76 | };
|
77 | LaneResizingTool.prototype.resize = function (newr) {
|
78 | var diagram = this.diagram;
|
79 | if (this.adornedObject === null)
|
80 | return;
|
81 | var lane = this.adornedObject.part;
|
82 | if (lane === null)
|
83 | return;
|
84 | var horiz = (lane.category === 'Column Header');
|
85 | var lay = diagram.layout;
|
86 | if (horiz) {
|
87 | var col = lane.column;
|
88 | var coldef = lay.getColumnDefinition(col);
|
89 | coldef.width = newr.width;
|
90 | }
|
91 | else {
|
92 | var row = lane.row;
|
93 | var rowdef = lay.getRowDefinition(row);
|
94 | rowdef.height = newr.height;
|
95 | }
|
96 | lay.invalidateLayout();
|
97 | };
|
98 | return LaneResizingTool;
|
99 | }(go.ResizingTool));
|
100 | function init() {
|
101 | if (window.goSamples)
|
102 | window.goSamples();
|
103 | var $ = go.GraphObject.make;
|
104 | var myDiagram = $(go.Diagram, 'myDiagramDiv', {
|
105 | layout: $(TableLayout_js_1.TableLayout, $(go.RowColumnDefinition, { row: 1, height: 22 }),
|
106 | $(go.RowColumnDefinition, { column: 1, width: 22 })
|
107 | ),
|
108 | 'SelectionMoved': function (e) { e.diagram.layoutDiagram(true); },
|
109 | 'resizingTool': new LaneResizingTool(),
|
110 |
|
111 | mouseDragOver: function (e) { e.diagram.currentCursor = 'not-allowed'; },
|
112 |
|
113 | mouseDrop: function (e) { e.diagram.currentTool.doCancel(); },
|
114 | 'animationManager.isInitial': false,
|
115 | 'undoManager.isEnabled': true
|
116 | });
|
117 | myDiagram.nodeTemplateMap.add('Header',
|
118 | $(go.Part, 'Auto', {
|
119 | row: 0, column: 1, columnSpan: 9999,
|
120 | stretch: go.GraphObject.Horizontal,
|
121 | selectable: false, pickable: false
|
122 | }, $(go.Shape, { fill: 'transparent', strokeWidth: 0 }), $(go.TextBlock, { alignment: go.Spot.Center, font: 'bold 12pt sans-serif' }, new go.Binding('text'))));
|
123 | myDiagram.nodeTemplateMap.add('Sider',
|
124 | $(go.Part, 'Auto', {
|
125 | row: 1, rowSpan: 9999, column: 0,
|
126 | stretch: go.GraphObject.Vertical,
|
127 | selectable: false, pickable: false
|
128 | }, $(go.Shape, { fill: 'transparent', strokeWidth: 0 }), $(go.TextBlock, { alignment: go.Spot.Center, font: 'bold 12pt sans-serif', angle: 270 }, new go.Binding('text'))));
|
129 | myDiagram.nodeTemplateMap.add('Column Header',
|
130 | $(go.Part, 'Spot', {
|
131 | row: 1, rowSpan: 9999, column: 2,
|
132 | minSize: new go.Size(100, NaN),
|
133 | stretch: go.GraphObject.Fill,
|
134 | movable: false,
|
135 | resizable: true,
|
136 | resizeAdornmentTemplate: $(go.Adornment, 'Spot', $(go.Placeholder), $(go.Shape,
|
137 | {
|
138 | alignment: go.Spot.Right,
|
139 | desiredSize: new go.Size(7, 50),
|
140 | fill: 'lightblue', stroke: 'dodgerblue',
|
141 | cursor: 'col-resize'
|
142 | }))
|
143 | }, new go.Binding('column', 'col'), $(go.Shape, { fill: null }, new go.Binding('fill', 'color')), $(go.Panel, 'Auto', {
|
144 | alignment: go.Spot.Top, alignmentFocus: go.Spot.Bottom,
|
145 | stretch: go.GraphObject.Horizontal,
|
146 | height: myDiagram.layout.getRowDefinition(1).height
|
147 | }, $(go.Shape, { fill: 'transparent', strokeWidth: 0 }), $(go.TextBlock, {
|
148 | font: 'bold 10pt sans-serif', isMultiline: false,
|
149 | wrap: go.TextBlock.None, overflow: go.TextBlock.OverflowEllipsis
|
150 | }, new go.Binding('text')))));
|
151 | myDiagram.nodeTemplateMap.add('Row Sider',
|
152 | $(go.Part, 'Spot', {
|
153 | row: 2, column: 1, columnSpan: 9999,
|
154 | minSize: new go.Size(NaN, 100),
|
155 | stretch: go.GraphObject.Fill,
|
156 | movable: false,
|
157 | resizable: true,
|
158 | resizeAdornmentTemplate: $(go.Adornment, 'Spot', $(go.Placeholder), $(go.Shape,
|
159 | {
|
160 | alignment: go.Spot.Bottom,
|
161 | desiredSize: new go.Size(50, 7),
|
162 | fill: 'lightblue', stroke: 'dodgerblue',
|
163 | cursor: 'row-resize'
|
164 | }))
|
165 | }, new go.Binding('row'), $(go.Shape, { fill: null }, new go.Binding('fill', 'color')), $(go.Panel, 'Auto', {
|
166 | alignment: go.Spot.Left, alignmentFocus: go.Spot.Right,
|
167 | stretch: go.GraphObject.Vertical, angle: 270,
|
168 | height: myDiagram.layout.getColumnDefinition(1).width
|
169 | }, $(go.Shape, { fill: 'transparent', strokeWidth: 0 }), $(go.TextBlock, {
|
170 | font: 'bold 10pt sans-serif', isMultiline: false,
|
171 | wrap: go.TextBlock.None, overflow: go.TextBlock.OverflowEllipsis
|
172 | }, new go.Binding('text')))));
|
173 | myDiagram.nodeTemplate =
|
174 | $(go.Node, 'Auto', { width: 100, height: 50, margin: 4 },
|
175 | new go.Binding('row'), new go.Binding('column', 'col'), $(go.Shape, { fill: 'white' }, new go.Binding('fill', 'color')), $(go.TextBlock, new go.Binding('text', 'key')));
|
176 | myDiagram.groupTemplate =
|
177 | $(go.Group, 'Auto', {
|
178 | layerName: 'Background',
|
179 | stretch: go.GraphObject.Fill,
|
180 | selectable: false,
|
181 | computesBoundsAfterDrag: true,
|
182 | computesBoundsIncludingLocation: true,
|
183 | handlesDragDropForMembers: true,
|
184 | mouseDragEnter: function (e, group) { if (group instanceof go.Group)
|
185 | group.isHighlighted = true; },
|
186 | mouseDragLeave: function (e, group) { if (group instanceof go.Group)
|
187 | group.isHighlighted = false; },
|
188 | mouseDrop: function (e, group) {
|
189 | if (!(group instanceof go.Group))
|
190 | return;
|
191 |
|
192 |
|
193 |
|
194 | var anynew = e.diagram.selection.any(function (p) { return p.containingGroup !== group; });
|
195 |
|
196 | var anyHeadersSiders = e.diagram.selection.any(function (p) {
|
197 | return p.category === 'Column Header' || p.category === 'Row Sider';
|
198 | });
|
199 | if (!anyHeadersSiders && group.addMembers(e.diagram.selection, true)) {
|
200 | if (anynew) {
|
201 | e.diagram.layout.getRowDefinition(group.row).height = NaN;
|
202 | e.diagram.layout.getColumnDefinition(group.column).width = NaN;
|
203 | }
|
204 | }
|
205 | else {
|
206 | e.diagram.currentTool.doCancel();
|
207 | }
|
208 | }
|
209 | }, new go.Binding('row'), new go.Binding('column', 'col'),
|
210 |
|
211 | $(go.Shape, {
|
212 | fill: 'transparent', stroke: 'transparent',
|
213 | strokeWidth: myDiagram.nodeTemplate.margin.left,
|
214 | stretch: go.GraphObject.Fill
|
215 | }, new go.Binding('fill', 'color'), new go.Binding('stroke', 'isHighlighted', function (h) { return h ? 'red' : 'transparent'; }).ofObject()), $(go.Placeholder, {
|
216 | alignment: (function (m) { return new go.Spot(0, 0, m.top, m.left); })(myDiagram.nodeTemplate.margin),
|
217 | padding: (function (m) { return new go.Margin(0, m.right, m.bottom, 0); })(myDiagram.nodeTemplate.margin)
|
218 | }));
|
219 | myDiagram.model = new go.GraphLinksModel([
|
220 |
|
221 | { key: 'Header', text: 'Vacation Procedures', category: 'Header' },
|
222 | { key: 'Sider', text: 'Personnel', category: 'Sider' },
|
223 |
|
224 | { key: 'Request', text: 'Request', col: 2, category: 'Column Header' },
|
225 | { key: 'Approval', text: 'Approval', col: 3, category: 'Column Header' },
|
226 | { key: 'Employee', text: 'Employee', row: 2, category: 'Row Sider' },
|
227 | { key: 'Manager', text: 'Manager', row: 3, category: 'Row Sider' },
|
228 | { key: 'Administrator', text: 'Administrator', row: 4, category: 'Row Sider' },
|
229 |
|
230 | { key: 'EmpReq', row: 2, col: 2, isGroup: true, color: 'lightyellow' },
|
231 | { key: 'EmpApp', row: 2, col: 3, isGroup: true, color: 'lightgreen' },
|
232 | { key: 'ManReq', row: 3, col: 2, isGroup: true, color: 'lightgreen' },
|
233 | { key: 'ManApp', row: 3, col: 3, isGroup: true, color: 'lightyellow' },
|
234 | { key: 'AdmReq', row: 4, col: 2, isGroup: true, color: 'lightyellow' },
|
235 | { key: 'AdmApp', row: 4, col: 3, isGroup: true, color: 'lightgreen' },
|
236 |
|
237 | { key: 'Delta', color: 'orange', size: '100 100', group: 'EmpReq' },
|
238 | { key: 'Epsilon', color: 'coral', size: '100 50', group: 'EmpReq' },
|
239 | { key: 'Zeta', color: 'tomato', size: '50 70', group: 'ManReq' },
|
240 | { key: 'Eta', color: 'coral', size: '50 50', group: 'ManApp' },
|
241 | { key: 'Theta', color: 'tomato', size: '100 50', group: 'AdmApp' }
|
242 | ]);
|
243 | var myPalette = $(go.Palette, 'myPaletteDiv', {
|
244 | nodeTemplateMap: myDiagram.nodeTemplateMap,
|
245 | 'model.nodeDataArray': [
|
246 | { key: 'Alpha', color: 'orange' },
|
247 | { key: 'Beta', color: 'tomato' },
|
248 | { key: 'Gamma', color: 'goldenrod' }
|
249 | ]
|
250 | });
|
251 | }
|
252 | exports.init = init;
|
253 | });
|