forked from BasicPrimitives/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestConnector.html
More file actions
255 lines (231 loc) · 11 KB
/
TestConnector.html
File metadata and controls
255 lines (231 loc) · 11 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
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Control Patents Inheritance Diagram Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="../../css/primitives.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../primitives.js"></script>
<script type="text/javascript" src="../../javascriptsamples.js"></script>
<script type="text/javascript" src="../../interactivetests.js"></script>
<link href="./css/styles.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var control;
var parents = {};
var children = {};
var timer = null;
var { Point, Rect, Size, Layers } = primitives;
var { ValueType, Render, PanelConfig, SizeConfig, ColorConfig, RadioBoxConfig, RangeConfig, DropDownBoxConfig, CaptionConfig, DropDownBoxConfig } = javascriptsamples;
var { RenderEventArgs, Callout, createGraphics, PaletteItem, PlacementType, Colors, LineType, PolylinesBuffer, ConnectorOffbeat, ConnectorStraight, ConnectorAnnotationOffsetResolver } = interactivetests;
var optionsRender = new Render([
new PanelConfig("Layout & Shape Options", [
new RadioBoxConfig("connectorPlacementType", primitives.ConnectorPlacementType.Offbeat, "Placement type", primitives.ConnectorPlacementType, ValueType.Integer, onUpdate),
new RadioBoxConfig("connectorShapeType", primitives.ConnectorShapeType.OneWay, "Connector shape type", primitives.ConnectorShapeType, ValueType.Integer, onUpdate),
new RangeConfig("labelOffset", 6, "Label Offset", 0, 20, 1, onUpdate),
new RangeConfig("linesOffset", 3, "Lines Offset", 0, 20, 1, onUpdate),
new SizeConfig("labelSize", new Size(30, 14), "Label size", 1, 100, 1, onUpdate),
new RadioBoxConfig("labelPlacementType", primitives.ConnectorLabelPlacementType.Between, "Label Placement", primitives.ConnectorLabelPlacementType, ValueType.Integer, onUpdate),
]),
new PanelConfig("Style Options", [
new RadioBoxConfig("lineType", primitives.LineType.Solid, "Line Type", primitives.LineType, ValueType.Integer, onUpdate),
new ColorConfig("lineColor", primitives.Colors.Black, "Color", false, onUpdate),
new RangeConfig("lineWidth",2, "Line width", 0, 10, 1, onUpdate)
])
], {
connectorPlacementType: primitives.ConnectorPlacementType.Offbeat,
connectorShapeType: primitives.ConnectorShapeType.OneWay,
labelOffset: 4,
linesOffset: 3,
labelSize: new Size(40, 30),
labelPlacementType: primitives.ConnectorLabelPlacementType.Between,
lineType: primitives.LineType.Solid,
lineColor: primitives.Colors.Black,
lineWidth: 2
});
var graphics;
var callout;
document.addEventListener('DOMContentLoaded', function () {
optionsRender.render(document.getElementById("westpanel"));
graphics = createGraphics(document.getElementById("placeholder"));
onUpdate();
window.addEventListener('resize', function (event) {
onWindowResize();
});
});
var fromPosition = new Rect(100, 100, 200, 100);
var toPosition = new Rect(400, 400, 200, 100);
var dragStartPoint;
var resizeStartPoint;
var topLeftStartPoint;
var bottomRightStartPoint;
function allowDrop(event) {
event.preventDefault();
}
function drag(event) {
dragStartPoint = { x: event.clientX, y: event.clientY };
var name = event.target.id;
switch(name) {
case "fromrect":
topLeftStartPoint = new Point(fromPosition);
break;
case "torect":
topLeftStartPoint = new Point(toPosition);
break;
}
event.dataTransfer.setData("name", name);
}
function dragresize(event) {
resizeStartPoint = { x: event.clientX, y: event.clientY };
var name = event.target.id;
switch(name) {
case "fromresizer":
bottomRightStartPoint = new Point(fromPosition.right(), fromPosition.bottom());
break;
case "toresizer":
bottomRightStartPoint = new Point(toPosition.right(), toPosition.bottom());
break;
}
event.dataTransfer.setData("name", name);
}
function drop(event) {
event.preventDefault();
var endPoint = new Point(event.clientX, event.clientY);
var name = event.dataTransfer.getData("name");
switch(name) {
case "fromrect":
fromPosition.x = topLeftStartPoint.x + endPoint.x - dragStartPoint.x;
fromPosition.y = topLeftStartPoint.y + endPoint.y - dragStartPoint.y;
break;
case "fromresizer":
var bottomRight = new Point(bottomRightStartPoint.x + endPoint.x - resizeStartPoint.x, bottomRightStartPoint.y + endPoint.y - resizeStartPoint.y);
var topLeft = new Point(fromPosition);
fromPosition = new Rect(topLeft, bottomRight);
break;
case "torect":
toPosition.x = topLeftStartPoint.x + endPoint.x - dragStartPoint.x;
toPosition.y = topLeftStartPoint.y + endPoint.y - dragStartPoint.y;
break;
case "toresizer":
var bottomRight = new Point(bottomRightStartPoint.x + endPoint.x - resizeStartPoint.x, bottomRightStartPoint.y + endPoint.y - resizeStartPoint.y);
var topLeft = new Point(toPosition);
toPosition = new Rect(topLeft, bottomRight);
break;
}
onUpdate()
}
function onUpdate() {
var fromRect = document.getElementById("fromrect");
fromRect.style.left = fromPosition.x + "px";
fromRect.style.top = fromPosition.y + "px";
fromRect.style.width = fromPosition.width + "px";
fromRect.style.height = fromPosition.height + "px";
var toRect = document.getElementById("torect");
toRect.style.left = toPosition.x + "px";
toRect.style.top = toPosition.y + "px";
toRect.style.width = toPosition.width + "px";
toRect.style.height = toPosition.height + "px";
var rect = document.getElementById("centerpanel");
var width = rect.offsetWidth;
var height = rect.offsetHeight;
var options = optionsRender.getValues();
options.label = "100";
var connector;
switch(options.connectorPlacementType) {
case primitives.ConnectorPlacementType.Offbeat:
connector = new ConnectorOffbeat(graphics);
break;
case primitives.ConnectorPlacementType.Straight:
connector = new ConnectorStraight(graphics);
break;
}
graphics.begin();
graphics.resize("placeholder", width, height);
graphics.activate("placeholder", Layers.BackgroundConnectorAnnotation);
var buffer = new PolylinesBuffer();
var connectorAnnotationOffsetResolver = ConnectorAnnotationOffsetResolver();
connector.draw(buffer, new PaletteItem({
lineColor: options.lineColor,
lineWidth: options.lineWidth,
lineType: options.lineType
}), fromPosition, toPosition,
options.linesOffset, 0,
options.labelSize,
new Size(width, height),
options.connectorShapeType, options.labelOffset, options.labelPlacementType, true,
connectorAnnotationOffsetResolver,
function (labelPlacement, labelConfig) {
uiHash = new RenderEventArgs();
uiHash.context = labelConfig;
/* draw label */
graphics.template(
labelPlacement.x
, labelPlacement.y
, 0
, 0
, 0
, 0
, labelPlacement.width
, labelPlacement.height
, ["div", {"border-style": "solid", "border-color": "black", "border-width": "1px"}]
, "AnnotationTemplate"
, (function (event, data) {
data.element.innerHTML = "";
var div = document.createElement("div");
div.style.borderWidth = "1px";
div.style.borderColor = "black";
div.style.borderStyle = "dotted";
div.style.width = "100%";
div.style.height = "100%";
div.appendChild(document.createTextNode(data.context.label));
data.element.appendChild(div);
})
, uiHash
, null
);
}, options);
connectorAnnotationOffsetResolver.resolve();
/* draw background polylines */
graphics.polylinesBuffer(buffer);
graphics.end();
}
function onWindowResize() {
if (timer == null) {
timer = window.setTimeout(function () {
onUpdate();
window.clearTimeout(timer);
timer = null;
}, 300);
}
}
</script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-md-4 col-lg-2 d-md-block bg-light sidebar collapse" style="position: fixed; top: 0; bottom: 0px; overflow-y: auto; float: none;">
<div class="position-sticky pt-3">
<div id="westpanel" class="flex-column">
</div>
</div>
</nav>
<main class="col-md-8 ms-sm-auto col-lg-10 px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Connector Shape Test</h1>
</div>
<div id="centerpanel" class="mediaPlaceholder my-2 w-100" ondrop="drop(event)" ondragover="allowDrop(event)" style="border-style: dotted; border-width: 1px;">
<div id="placeholder" style="overflow: hidden; position: relative; width: 100%; height: 100%;">
<div id="fromrect" style="position: absolute; top: 100px; left: 100px; width: 200px; height: 100px; border-width: 1px; border-style: dotted;" draggable="true" ondragstart="drag(event)">Drag & Resize Rect
<div id="fromresizer" style="position: absolute; right: 0px; bottom: 0px; width: 16px; height: 8px; border-width: 1px; border-style: dotted;" draggable="true" ondragstart="dragresize(event)"></div>
</div>
<div id="torect" style="position: absolute; top: 400px; left: 400px; width: 200px; height: 100px; border-width: 1px; border-style: dotted;" draggable="true" ondragstart="drag(event)">Drag & Resize Rect
<div id="toresizer" style="position: absolute; right: 0px; bottom: 0px; width: 16px; height: 8px; border-width: 1px; border-style: dotted;" draggable="true" ondragstart="dragresize(event)"></div>
</div>
</div>
</div>
<div id="southpanel" class="alert alert-primary" style="min-height: 60px;" role="alert">
</div>
</main>
</div>
</div>
</body>
</html>