forked from syncfusion/ej2-aspnetcore-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexHierarchicalLayout.cshtml
197 lines (180 loc) · 8.16 KB
/
ComplexHierarchicalLayout.cshtml
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
@using Syncfusion.EJ2;
@using EJ2CoreSampleBrowser.Controllers.Diagram;
@section ControlsSection{
<div class="col-lg-8 control-section">
<ejs-diagram id="diagram" width="100%" height="500px" getNodeDefaults="@ViewBag.getNodeDefaults" getConnectorDefaults="@ViewBag.getConnectorDefaults" created="diagramCreated">
<e-diagram-snapsettings constraints="None"></e-diagram-snapsettings>
<e-diagram-datasourcesettings id="Name" parentId="ReportingPersons" dataSource="new DataManager() { Data = (List<ComplexHierarchicalDataDetails>)ViewBag.Nodes }"></e-diagram-datasourcesettings>
<e-diagram-layout type="ComplexHierarchicalTree" horizontalSpacing="40" verticalSpacing="40" margin="ViewBag.marginValue"></e-diagram-layout>
</ejs-diagram>
</div>
<div class="col-lg-4 property-section">
<div class="property-panel-header">
Layout Settings
</div>
<div class="row property-panel-content" id="appearance" style="padding-top: 10px">
<div class="row row-header">
Orientation
</div>
<div class="row" style="padding-top: 8px">
<div class="image-pattern-style e-selected-style" id="topToBottom" style="background-image: url('@Url.Content("~/images//diagram/common-orientation/toptobottom.png")'); margin-right: 3px">
</div>
<div class="image-pattern-style" id="bottomToTop" style="background-image: url('@Url.Content("~/images//diagram/common-orientation/bottomtotop.png")'); margin: 0px 3px">
</div>
<div class="image-pattern-style" id="leftToRight" style="background-image: url('@Url.Content("~/images//diagram/common-orientation/lefttoright.png")'); margin-right: 3px">
</div>
</div>
<div class="row" style="padding-top: 8px">
<div class="image-pattern-style" id="rightToLeft" style="background-image: url('@Url.Content("~/images//diagram/common-orientation/righttoleft.png")'); margin: 0px 3px">
</div>
</div>
</div>
<div class="row property-panel-content" style="padding-top: 10px">
<div class="row row-header">
Behavior
</div>
<div class="row" style="padding-top: 8px">
<div style="display: table;height: 35px; padding-left: 0px" class="col-xs-5">
<div style="display: table-cell; vertical-align: middle">Margin X</div>
</div>
<div class="col-xs-7">
<ejs-numerictextbox id="marginLeft" format="##.##" change="marginLeftChange" width="120px" min="20" max="60" step="2" value="10"></ejs-numerictextbox>
</div>
</div>
<div class="row" style="padding-top: 8px">
<div style="display: table;height: 35px; padding-left: 0px" class="col-xs-5">
<div style="display: table-cell; vertical-align: middle">Margin Y</div>
</div>
<div class="col-xs-7">
<ejs-numerictextbox id="marginTop" format="##.##" change="marginTopChange" width="120px" min="20" max="60" step="2" value="50"></ejs-numerictextbox>
</div>
</div>
<div class="row" style="padding-top: 8px">
<div style="display: table;height: 35px; padding-left: 0px" class="col-xs-5">
<div style="display: table-cell; vertical-align: middle">Horizontal Spacing</div>
</div>
<div class="col-xs-7">
<ejs-numerictextbox id="hSpacing" format="##.##" change="hSpacingChange" width="120px" min="20" max="60" step="2" value="40"></ejs-numerictextbox>
</div>
</div>
<div class="row" style="padding-top: 8px">
<div style="display: table;height: 35px; padding-left: 0px" class="col-xs-5">
<div style="display: table-cell; vertical-align: middle">Vertical Spacing</div>
</div>
<div class="col-xs-7">
<ejs-numerictextbox id="vSpacing" format="##.##" change="vSpacingChange" width="120px" min="20" max="60" step="2" value="40"></ejs-numerictextbox>
</div>
</div>
</div>
</div>
<style>
#diagram {
display: block;
}
.row {
display: block;
margin-left: 0px;
margin-right: 0px;
}
.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;
}
.row-header {
font-size: 15px;
font-weight: 500;
}
.e-selected-style {
border-color: #006CE6;
border-width: 2px;
}
.e-checkbox-wrapper .e-label {
font-size: 12px;
}
.col-xs-6 {
padding-left: 0px;
padding-right: 0px;
}
</style>
<script>
function diagramCreated() {
var diagram = document.getElementById("diagram").ej2_instances[0];
diagram.tool = ej.diagrams.DiagramTools.ZoomPan;
diagram.dataBind();
}
function hSpacingChange(args) {
updateLayoutSettings("horizontalSpacing", args.value);
}
function vSpacingChange(args) {
updateLayoutSettings("verticalSpacing", args.value);
}
function marginTopChange(args) {
updateLayoutSettings("marginTop", args.value);
}
function marginLeftChange(args) {
updateLayoutSettings("marginLeft", args.value);
}
function updateLayoutSettings(propertyName, propertyValue) {
var diagram = document.getElementById("diagram").ej2_instances[0];
propertyValue = Number(propertyValue);
switch (propertyName) {
case "horizontalSpacing":
diagram.layout.horizontalSpacing = propertyValue;
break;
case "verticalSpacing":
diagram.layout.verticalSpacing = propertyValue;
break;
case "marginLeft":
diagram.layout.margin.left = propertyValue;
break;
case "marginTop":
diagram.layout.margin.top = propertyValue;
break;
}
diagram.dataBind();
}
function connectorDefaults(connector, diagram) {
connector.type = 'Orthogonal';
connector.cornerRadius = 7;
connector.targetDecorator.height = 7;
connector.targetDecorator.width = 7;
connector.style.strokeColor = '#6d6d6d';
return connector;
}
function nodeDefaults(obj, diagram) {
obj.style = { fill: obj.data.Color, strokeColor: 'none', strokeWidth: 2 };
obj.width = 40; obj.height = 40;
//Initialize shape
obj.shape = { type: 'Basic', shape: 'Rectangle', cornerRadius: 7 };
return obj;
}
@*custom code start*@
document.getElementById('appearance').onclick = function (args) {
var target = args.target;
var diagram = document.getElementById("diagram").ej2_instances[0];
var selectedElement = document.getElementsByClassName('e-selected-style');
if (selectedElement.length) {
selectedElement[0].classList.remove('e-selected-style');
}
if (target.className === 'image-pattern-style') {
var id = target.id;
var orientation1 = id.substring(0, 1).toUpperCase() + id.substring(1, id.length);
diagram.layout.orientation = orientation1;
diagram.dataBind();
diagram.doLayout();
target.classList.add('e-selected-style');
}
};
@*custom code end*@
</script>
}
@section Meta{
<meta name="description" content="This demo for Essential JS2 Diagram control demonstrates a complex hierarchical template that is built from an external data source using complex hierarchical tree algorithm."/>
}