forked from syncfusion/ej2-aspnetcore-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawingTools.cshtml
252 lines (228 loc) · 12.1 KB
/
DrawingTools.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
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
@using Syncfusion.EJ2;
@section ControlsSection{
<div class="col-lg-8 control-section">
<ejs-diagram created="diagramCreated" id="diagram" width="100%" height="540px">
<e-diagram-rulersettings showRulers="true" dynamicGrid="true"></e-diagram-rulersettings>
</ejs-diagram>
</div>
<div class="col-lg-4 property-section">
<div class="property-panel-header">
Properties
</div>
<div class="row property-panel-content" id="appearance">
<div class="row row-header" style="padding-top: 10px">
Shapes
</div>
<div class="row" style="padding-top: 8px">
<div title="Retangle" class="image-pattern-style e-selected-style" id="shape1" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/basicshape/DrawingTool_1.png")'); margin-right: 3px">
</div>
<div title="Ellipse" class="image-pattern-style" id="shape2" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/basicshape/DrawingTool_2.png")'); margin: 0px 3px">
</div>
<div title="Hexagon" class="image-pattern-style" id="shape3" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/basicshape/DrawingTool_3.png")');">
</div>
</div>
<div class="row" style="padding-top: 8px">
<div title="Pentagon" class="image-pattern-style" id="shape4" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/basicshape/DrawingTool_4.png")'); margin-right: 3px">
</div>
<div title="Polygon" class="image-pattern-style" id="shape5" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/basicshape/DrawingTool_5.png")'); margin: 0px 3px">
</div>
<div title="Path" class="image-pattern-style" id="path" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/DrawingTool_6.png")');">
</div>
</div>
<div class="row" style="padding-top: 8px">
<div title="Image" class="image-pattern-style" id="image" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/DrawingTool_7.png")'); margin-right: 3px">
</div>
<div title="SVG" class="image-pattern-style" id="svg" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/DrawingTool_8.png")'); margin-right: 3px">
</div>
<div title="Text" class="image-pattern-style" id="text" style="background-image: url('@Url.Content("~/images/Diagram/drawingTool/DrawingTool_9.png")'); margin-right: 3px">
</div>
</div>
<div class="row row-header" style="padding-top: 10px">
Connector
</div>
<div class="row" style="padding-top: 8px">
<div class="image-pattern-style" id="straight" style="background-image: url('@Url.Content("~/images/diagram/drawingTool/connector/Connectors_1.png")'); margin-right: 3px">
</div>
<div class="image-pattern-style" id="ortho" style="background-image: url('@Url.Content("~/images/diagram/drawingTool/connector/Connectors_2.png")'); margin: 0px 3px">
</div>
<div class="image-pattern-style" id="cubic" style="background-image: url('@Url.Content("~/images/diagram/drawingTool/connector/Connectors_3.png")'); ">
</div>
</div>
<div class="row" style="padding-top: 10px">
<ejs-checkbox id="checked" checked="true" label="Continuous Draw" change="onChangeData"></ejs-checkbox>
</div>
</div>
</div>
<style>
#diagram {
display: block;
}
.row {
display: block;
}
.image-pattern-style {
background-color: white;
background-size: contain;
background-repeat: no-repeat;
height: 45px;
width: calc((100% - 12px) / 3);
cursor: pointer;
border: 1px solid #D5D5D5;
background-position: center;
float: left;
}
.row {
margin-left: 0px;
margin-right: 0px;
}
.row-header {
font-size: 12px;
font-weight: 500;
}
.e-checkbox-wrapper .e-label {
font-size: 12px;
}
.property-panel-header {
padding-top: 15px;
padding-bottom: 5px;
}
.e-selected-style {
border-color: #006CE6;
border-width: 2px;
}
.control-section {
padding-top: 0px;
padding-bottom: 0px;
padding-right: 0px;
}
.container-fluid {
padding-left: 0px;
}
.col-xs-6 {
padding-left: 0px;
padding-right: 0px;
}
</style>
<script type="text/javascript">
var diagram;
function diagramCreated() {
diagram = document.getElementById("diagram").ej2_instances[0];
diagram.drawingObject = { shape: { type: 'Basic', shape: 'Rectangle' } };
diagram.tool = ej.diagrams.DiagramTools.ContinuousDraw;
diagram.dataBind();
}
function onChangeData(args) {
diagram.tool = args.checked ? ej.diagrams.DiagramTools.ContinuousDraw : ej.diagrams.DiagramTools.DrawOnce;
}
document.getElementById('appearance').onclick = function (args) {
var target = args.target;
@*custom code start*@
var selectedElement = document.getElementsByClassName('e-selected-style');
if (selectedElement.length && target.id !== '' && target.id !== 'checked') {
selectedElement[0].classList.remove('e-selected-style');
}
@*custom code end*@
if (target.className === 'image-pattern-style') {
switch (target.id) {
case 'shape1':
drawingObject = { shape: { type: 'Basic', shape: 'Rectangle' } };
break;
case 'shape2':
drawingObject = { shape: { type: 'Basic', shape: 'Ellipse' } };
break;
case 'shape3':
drawingObject = { shape: { type: 'Basic', shape: 'Hexagon' } };
break;
case 'shape4':
drawingObject = { shape: { type: 'Basic', shape: 'Pentagon' } };
break;
case 'shape5':
drawingObject = { shape: { type: 'Basic', shape: 'Triangle' } };
break;
case 'straight':
drawingObject = { type: 'Straight' };
break;
case 'ortho':
drawingObject = { type: 'Orthogonal' };
break;
case 'cubic':
drawingObject = { type: 'Bezier' };
break;
case 'path':
drawingObject = {
shape: {
type: 'Path',
data: 'M540.3643,137.9336L546.7973,159.7016L570.3633,159.7296L550.7723,171.9366L558.9053,194.9966L540.3643,' +
'179.4996L521.8223,194.9966L529.9553,171.9366L510.3633,159.7296L533.9313,159.7016L540.3643,137.9336z'
}
};
break;
case 'image':
drawingObject = { shape: { type: 'Image', source: '../images/diagram/employees/Clayton.png' } };
break;
case 'svg':
drawingObject = { shape: { type: 'Native', content: getNativeContent() } };
break;
case 'text':
drawingObject = { shape: { type: 'Text' } };
break;
}
if (drawingObject) {
diagram.drawingObject = drawingObject;
var checkBoxObj = document.getElementById("checked").ej2_instances[0];
diagram.tool = checkBoxObj.checked ? ej.diagrams.DiagramTools.ContinuousDraw : ej.diagrams.DiagramTools.DrawOnce;
diagram.dataBind();
@*custom code start*@
target.classList.add('e-selected-style');
@*custom code end*@
}
}
};
@*custom code start*@
function getNativeContent() {
var str = '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="350.000000pt" ' +
'height="229.000000pt" viewBox="0 0 350.000000 229.000000" ' +
'preserveAspectRatio="xMidYMid meet"> <metadata>' +
' Created by potrace 1.11, written by Peter Selinger 2001-2013' +
' </metadata> <g transform="translate(0.000000,229.000000) scale(0.100000,-0.100000)"' +
' fill="#de6ca9" stroke="none"><path d="M0 1145 l0 -1145 1750 0 1750 0 0 1145 0 1145' +
' -1750 0 -1750 0 0 -1145z m1434 186 c19 -8 26 -18 26 -37 0 -24 -3 -26' +
' -27 -19 -16 3 -58 9 -94 12 -63 5 -67 4 -88 -23 -23 -29 -21 -60 6 -81 8' +
' -6 47 -19 86 -29 55 -13 80 -25 106 -51 31 -31 33 -37 29 -88 -8 -94 -69' +
' -133 -193 -122 -90 7 -115 20 -115 58 0 26 3 30 18 24 91 -38 168 -41 204' +
' -8 23 21 23 75 1 96 -10 8 -49 23 -88 33 -88 22 -135 63 -135 118 0 92 67 140' +
' 181 131 31 -2 68 -9 83 -14z m854 -6 c38 -15 42 -21 42 -51 l0 -33 -47 25' +
' c-41 22 -58 25 -115 22 -58 -3 -72 -8 -97 -32 -79 -75 -59 -259 32 -297 35' +
' -15 106 -18 150 -6 26 7 27 10 27 67 l0 60 -50 0 c-47 0 -50 2 -50 25 0 25' +
' 1 25 80 25 l81 0 -3 -97 -3 -98 -40 -20 c-22 -10 -65 -21 -95 -23 -153 -11' +
' -242 74 -243 230 0 145 93 235 233 224 30 -2 74 -12 98 -21z m-638 -169 l67' +
' -178 40 103 c22 57 53 139 69 182 28 75 29 77 62 77 19 0 32 -4 30 -9 -1 -5' +
' -39 -104 -83 -220 l-80 -211 -37 0 c-35 0 -37 2 -56 53 -11 28 -48 124 -81 ' +
'211 -34 87 -61 163 -61 168 0 5 14 8 32 6 31 -3 32 -5 98 -182z" />' +
'</g> </svg>';
return str;
}
@*custom code end*@
</script>
}
@section ActionDescription{
<p>
This sample visualizes how to build a diagram interactively using drawing tools. Continuous draw option, snapping, and undo/redo support are enabled to easily draw diagrams.
Rulers, gridlines, and snapping options are enabled to easily align objects.
</p>
}
@section Meta{
<meta name="description" content="This demo for EJ2 ASP.NET Core Diagram control shows how to build a diagram interactively using drawing tools. Options are enabled to align the diagram easily." />
}
@section Description{
<p>
This example shows how to draw shapes and connections interactively. In addition to that, rulers, gridlines, and snapping options are enabled to assist drawing.
The <code>tool</code> property can be used to enable drawing. Add <code>DrawOnce</code> or <code>ContinousDraw</code> option to the
<code>tool</code> property of the diagram. The <code>drawingObject</code> property can be used to define a shape/connector to be drawn.
</p>
<p>
Few shape and connector templates are added in the palette. To draw basic shapes and connectors, click the templates in the palette.
For polygon shapes, a corner/point will be added to the polygon for each mouse left button click. Drawing will be completed either on mouse right button click or double click.
</p>
<p>The diagram component’s features are segregated into individual feature-wise modules. To enable undo and redo support, inject <code>UndoRedo</code> module using <code>Diagram.Inject(UndoRedo)</code> method.</p>
}