This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathorganization-model.tsx
More file actions
623 lines (601 loc) · 20.6 KB
/
organization-model.tsx
File metadata and controls
623 lines (601 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
import * as ReactDOM from "react-dom";
import * as React from "react";
import {
TreeInfo,
Node,
SubTreeOrientation,
LayoutOrientation,
SubTreeAlignments,
LayoutAnimation,
HierarchicalTree,
DataBinding,
DiagramComponent,
Diagram,
NodeModel,
ConnectorModel,
SnapConstraints,
Inject,
DiagramTools
} from "@syncfusion/ej2-react-diagrams";
import { SampleBase } from "../common/sample-base";
import { DataManager } from "@syncfusion/ej2-data";
import { Point } from "@syncfusion/ej2-diagrams/src/diagram/primitives/point";
import { NumericTextBoxComponent } from "@syncfusion/ej2-react-inputs";
export interface EmployeeInfo {
Role: string;
color: string;
}
export let localBindData: object[] = [
{ Id: "parent", Role: "Board", color: "#71AF17" },
{
Id: "1",
Role: "General Manager",
Manager: "parent",
ChartType: "right",
color: "#71AF17"
},
{
Id: "11",
Role: "Assistant General Manager",
Manager: "1",
color: "#71AF17"
},
{
Id: "2",
Role: "Human Resource Manager",
Manager: "1",
ChartType: "right",
color: "#1859B7"
},
{ Id: "3", Role: "Trainers", Manager: "2", color: "#2E95D8" },
{ Id: "4", Role: "Recruiting Team", Manager: "2", color: "#2E95D8" },
{ Id: "5", Role: "Finance Asst. Manager", Manager: "2", color: "#2E95D8" },
{
Id: "6",
Role: "Design Manager",
Manager: "1",
ChartType: "right",
color: "#1859B7"
},
{ Id: "7", Role: "Design Supervisor", Manager: "6", color: "#2E95D8" },
{ Id: "8", Role: "Development Supervisor", Manager: "6", color: "#2E95D8" },
{ Id: "9", Role: "Drafting Supervisor", Manager: "6", color: "#2E95D8" },
{
Id: "10",
Role: "Operations Manager",
Manager: "1",
ChartType: "right",
color: "#1859B7"
},
{ Id: "11", Role: "Statistics Department", Manager: "10", color: "#2E95D8" },
{ Id: "12", Role: "Logistics Department", Manager: "10", color: "#2E95D8" },
{
Id: "16",
Role: "Marketing Manager",
Manager: "1",
ChartType: "right",
color: "#1859B7"
},
{ Id: "17", Role: "Overseas Sales Manager", Manager: "16", color: "#2E95D8" },
{ Id: "18", Role: "Petroleum Manager", Manager: "16", color: "#2E95D8" },
{
Id: "20",
Role: "Service Department Manager",
Manager: "16",
color: "#2E95D8"
},
{
Id: "21",
Role: "Quality Control Department",
Manager: "16",
color: "#2E95D8"
}
];
export interface EmployeeInfo {
Name: string;
}
const SAMPLE_CSS = `.image-pattern-style {
background-color: white;
background-size: contain;
background-repeat: no-repeat;
height: 75px;
width: calc((100% - 18px) / 3);
cursor: pointer;
border: 1px solid #D5D5D5;
background-position: center;
float: left;
}
.image-pattern-style:hover {
border-color: gray;
border-width: 2px;
}
.row {
margin-left: 0px;
margin-right: 0px;
}
.row-header {
font-size: 13px;
font-weight: 500;
}
.row-header1 {
font-size: 12px;
padding-left: 2px;
font-weight: 400;
}
.property-panel-header {
padding-top: 15px;
padding-bottom: 15px;
}
.e-selected-orientation-style {
border-color: #006CE6;
border-width: 2px;
}
.e-selected-pattern-style {
border-color: #006CE6;
border-width: 2px;
}
.e-checkbox-wrapper .e-label {
font-size: 12px;
}
.diagram-control-pane .col-xs-6 {
padding-left: 0px;
padding-right: 0px;
}`;
let diagramInstance: DiagramComponent;
let hSpacing: NumericTextBoxComponent;
let vSpacing: NumericTextBoxComponent;
let orien: LayoutOrientation;
let typ: SubTreeAlignments;
export class OrganizationModel extends SampleBase<{}, {}> {
rendereComplete() {
//Click Event for orientation of the PropertyPanel.
document.getElementById("orientation").onclick = (args: MouseEvent) => {
let target: HTMLElement = args.target as HTMLElement;
let selectedElement: HTMLCollection = document.getElementsByClassName(
"e-selected-orientation-style"
);
if (selectedElement.length) {
selectedElement[0].classList.remove("e-selected-orientation-style");
}
if (!target.classList.contains("e-selected-orientation-style")) {
target.classList.add("e-selected-orientation-style");
}
if (
target.className === "image-pattern-style e-selected-orientation-style"
) {
switch (target.id) {
case "toptobottom":
diagramInstance.layout.orientation = "TopToBottom";
break;
case "bottomtotop":
diagramInstance.layout.orientation = "BottomToTop";
break;
case "lefttoright":
diagramInstance.layout.orientation = "LeftToRight";
break;
case "righttoleft":
diagramInstance.layout.orientation = "RightToLeft";
break;
default:
if (selectedElement.length) {
selectedElement[0].classList.remove(
"e-selected-orientation-style"
);
}
}
diagramInstance.dataBind();
diagramInstance.doLayout();
}
};
//Click Event for pattern of the PropertyPanel.
document.getElementById("pattern").onclick = (args: MouseEvent) => {
let target: HTMLElement = args.target as HTMLElement;
let selectedpatternElement: HTMLCollection = document.getElementsByClassName(
"e-selected-pattern-style"
);
if (selectedpatternElement.length) {
selectedpatternElement[0].classList.remove("e-selected-pattern-style");
}
if (!target.classList.contains("e-selected-pattern-style")) {
target.classList.add("e-selected-pattern-style");
}
if (target.className === "image-pattern-style e-selected-pattern-style") {
switch (target.id) {
case "pattern1":
orien = "Vertical".toString() as LayoutOrientation;
typ = "Alternate" as SubTreeAlignments;
break;
case "pattern2":
orien = "Vertical".toString() as LayoutOrientation;
typ = "Left" as SubTreeAlignments;
break;
case "pattern3":
orien = "Vertical".toString() as LayoutOrientation;
typ = "Left" as SubTreeAlignments;
break;
case "pattern4":
orien = "Vertical".toString() as LayoutOrientation;
typ = "Right" as SubTreeAlignments;
break;
case "pattern5":
orien = "Vertical".toString() as LayoutOrientation;
typ = "Right" as SubTreeAlignments;
break;
case "pattern6":
orien = "Horizontal".toString() as LayoutOrientation;
typ = "Balanced" as SubTreeAlignments;
break;
case "pattern7":
orien = "Horizontal".toString() as LayoutOrientation;
typ = "Center" as SubTreeAlignments;
break;
case "pattern8":
orien = "Horizontal".toString() as LayoutOrientation;
typ = "Left" as SubTreeAlignments;
break;
case "pattern9":
orien = "Horizontal".toString() as LayoutOrientation;
typ = "Right" as SubTreeAlignments;
break;
default:
if (selectedpatternElement.length) {
selectedpatternElement[0].classList.remove(
"e-selected-pattern-style"
);
}
}
diagramInstance.layout.getLayoutInfo = (
node: Node,
options: TreeInfo
) => {
if (target.id === "pattern4" || target.id === "pattern3") {
options.offset = -50;
}
if (orien) {
getLayoutInfo(node, options, orien, typ);
}
};
diagramInstance.dataBind();
diagramInstance.doLayout();
}
};
}
render() {
return (
<div className="control-pane diagram-control-pane">
<style>{SAMPLE_CSS}</style>
<div className="col-lg-8 control-section">
<div className="content-wrapper"style={{width : "100%"}}>
<DiagramComponent
id="diagram"
ref={diagram => (diagramInstance = diagram)}
width={"100%"}
height={"700px"}
snapSettings={{ constraints: SnapConstraints.None }}
//configures data source settings
dataSourceSettings={{
id: "Id",
parentId: "Manager",
dataManager: new DataManager(localBindData as JSON[]),
doBinding: (
nodeModel: NodeModel,
data: object,
diagram: Diagram
) => {
nodeModel.shape = {
type: "Text",
content: (data as EmployeeInfo).Role,
margin: { left: 10, right: 10, top: 10, bottom: 10 }
};
}
}}
//Disables all interactions except zoom/pan
tool={DiagramTools.ZoomPan}
//Configures automatic layout
layout={{
type: "OrganizationalChart",
getLayoutInfo: (node: Node, options: TreeInfo) => {
/* tslint:disable:no-string-literal */
if ((node.data as DataInfo)["Role"] === "General Manager") {
options.assistants.push(options.children[0]);
options.children.splice(0, 1);
}
if (!options.hasSubTree) {
options.type = "Right";
}
}
}}
//Defines the default node and connector properties
getNodeDefaults={(obj: Node, diagram: Diagram) => {
/* tslint:disable:no-string-literal */
return nodeDefaults(obj, diagram);
}}
getConnectorDefaults={(
connector: ConnectorModel,
diagram: Diagram
) => {
return connectorDefaults(connector, diagram);
}}
>
<Inject
services={[DataBinding, HierarchicalTree, LayoutAnimation]}
/>
</DiagramComponent>
</div>
</div>
<div
className="col-lg-4 property-section"
style={{ float: "right", height: "80%" }}
>
<div className="property-panel-header">Properties</div>
<div className="row property-panel-content" id="appearance">
<div className="row" style={{ paddingTop: "10px" }}>
<div className="row row-header">Orientation</div>
<div id="orientation">
<div className="row" style={{ paddingTop: "8px" }}>
<div
className="image-pattern-style e-selected-orientation-style"
id="toptobottom"
style={{
backgroundImage:
"url('src/diagram/Images/common-orientation/toptobottom.png')",
marginRight: "3px"
}}
/>
<div
className="image-pattern-style"
id="bottomtotop"
style={{
backgroundImage:
"url('src/diagram/Images/common-orientation/bottomtotop.png')",
margin: "0px 3px"
}}
/>
<div
className="image-pattern-style"
id="lefttoright"
style={{
backgroundImage:
"url('src/diagram/Images/common-orientation/lefttoright.png')",
marginRight: "0px 3px"
}}
/>
</div>
<div className="row" style={{ paddingTop: "8px" }}>
<div
className="image-pattern-style"
id="righttoleft"
style={{
backgroundImage:
"url('src/diagram/Images/common-orientation/righttoleft.png')",
margin: "0px 3px"
}}
/>
</div>
</div>
<div className="row row-header" style={{ paddingTop: "10px" }}>
Subtree Alignment
</div>
<div id="pattern">
<div className="row" style={{ paddingTop: "8px" }}>
<div
className="image-pattern-style"
id="pattern1"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_1.png')",
marginRight: "3px"
}}
/>
<div
className="image-pattern-style e-selected-pattern-style"
id="pattern2"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_2.png')",
marginRight: "3px"
}}
/>
<div
className="image-pattern-style"
id="pattern5"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_5.png')",
margin: "0px 3px"
}}
/>
</div>
<div className="row" style={{ paddingTop: "8px" }}>
<div
className="image-pattern-style"
id="pattern6"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_6.png')",
marginRight: "3px"
}}
/>
<div
className="image-pattern-style"
id="pattern7"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_7.png')",
marginRight: "3px"
}}
/>
<div
className="image-pattern-style"
id="pattern8"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_8.png')",
margin: "0px 3px"
}}
/>
</div>
<div className="row" style={{ paddingTop: "8px" }}>
<div
className="image-pattern-style"
id="pattern9"
style={{
backgroundImage:
"url('src/diagram/patternimages/Pattern_9.png')",
margin: "0px 3px"
}}
/>
</div>
</div>
</div>
</div>
<div className="row property-panel-content" style={{ paddingTop: "10px" }}>
<div className="row row-header">Behavior</div>
<div className="row" style={{ paddingTop: "8px" }}>
<div
style={{ display: "table", height: "35px" }}
className="col-xs-6"
>
<div style={{ display: "table-cell", verticalAlign: "middle" }}>
Horizontal Spacing
</div>
</div>
<div className="col-xs-6">
<NumericTextBoxComponent
ref={hSpacingRef => (hSpacing = hSpacingRef)}
id="hSpacing"
style={{ width: "100%" }}
min={20}
max={60}
step={2}
value={30}
change={() => {
diagramInstance.layout.horizontalSpacing = Number(
hSpacing.value
);
diagramInstance.dataBind();
}}
/>
</div>
</div>
<div className="row" style={{ paddingTop: "8px" }}>
<div
style={{ display: "table", height: "35px" }}
className="col-xs-6"
>
<div style={{ display: "table-cell", verticalAlign: "middle" }}>
Vertical Spacing
</div>
</div>
<div className="col-xs-6">
<NumericTextBoxComponent
ref={vSpacingRef => (vSpacing = vSpacingRef)}
id="vSpacing"
style={{ width: "100%" }}
min={20}
max={60}
step={2}
value={30}
change={() => {
diagramInstance.layout.verticalSpacing = Number(
vSpacing.value
);
diagramInstance.dataBind();
}}
/>
</div>
</div>
</div>
</div>
<div id="action-description">
<p>
This sample illustrates a simple business management structure that
is built from an external data source. Hierarchical tree layout
algorithm is used to build organizational charts. Customizing the
orientation and structure of the organizational chart is illustrated
in this example.
</p>
</div>
<div id="description">
<p>
This example shows how to generate an organizational chart from an
external data source. The spacing between the objects can also be
customized in the chart. The <code>horizontalSpacing</code> and{" "}
<code>verticalSpacing</code> properties of
<code>layout</code> can be used to customize the space between
objects in a tree. The <code>layoutOrientation</code> property of
<code>layout</code> can be used to change the orientation of the
chart. The <code>getLayoutInfo</code> property of
<code>layout</code> can be used to customize the tree structure. To
change the tree structure, choose any template in the palette.
</p>
<p style={{ fontWeight: 500 }}>Injecting Module</p>
<p>
The diagram component’s features are segregated into individual
feature-wise modules. To generate diagrams from an external data
source, inject
<code>DataBinding</code> module into <code>services</code>. To
automatically arrange the objects in an organizational chart, inject
<code>HierarchicalTree</code> module into <code>services</code>.
</p>
<br />
</div>
</div>
);
}
}
//set orientation and type of the Layout.
function getLayoutInfo(
node: Node,
options: TreeInfo,
orientation: LayoutOrientation,
type: SubTreeAlignments
): void {
/* tslint:disable:no-string-literal */
if ((node.data as DataInfo)["Role"] === "General Manager") {
options.assistants.push(options.children[0]);
options.children.splice(0, 1);
}
if (!options.hasSubTree) {
options.orientation = orientation as SubTreeOrientation;
options.type = type;
}
}
//sets default value for Node.
function nodeDefaults(obj: Node, diagram: Diagram): Node {
obj.backgroundColor = (obj.data as EmployeeInfo).color;
obj.style = { fill: "none", strokeColor: "none", color: "white" };
obj.expandIcon = {
height: 10,
width: 10,
shape: "None",
fill: "lightgray",
offset: { x: 0.5, y: 1 }
};
obj.expandIcon.verticalAlignment = "Center";
obj.expandIcon.margin = { left: 0, right: 0, top: 0, bottom: 0 };
obj.collapseIcon.offset = { x: 0.5, y: 1 };
obj.collapseIcon.verticalAlignment = "Center";
obj.collapseIcon.margin = { left: 0, right: 0, top: 0, bottom: 0 };
obj.collapseIcon.height = 10;
obj.collapseIcon.width = 10;
obj.collapseIcon.shape = "None";
obj.collapseIcon.fill = "lightgray";
obj.width = 120;
obj.height = 30;
return obj;
}
//sets default value for Connector.
function connectorDefaults(
connector: ConnectorModel,
diagram: Diagram
): ConnectorModel {
connector.targetDecorator.shape = "None";
connector.type = "Orthogonal";
connector.constraints = 0;
connector.cornerRadius = 0;
return connector;
}
export interface DataInfo {
[key: string]: string;
}