-
Notifications
You must be signed in to change notification settings - Fork 9
/
demo.html
377 lines (326 loc) · 11.4 KB
/
demo.html
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
<!DOCTYPE>
<html>
<head>
<title>cytoscape.js-grid-guide demo</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<!-- for testing with local version of cytoscape.js -->
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
<script src="cytoscape-grid-guide.js"></script>
<style>
body {
font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;
font-size: 14px;
}
.modules div {
margin: 1em;
cursor: pointer;
}
.modules div.enabled b {
color: #00ffff
}
.modules div.disabled b {
color: #ff0000;
}
#config {
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 16em;
background: #17423B;
padding: 0.5em;
color: #fff;
overflow: auto;
}
#cy {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 17em;
z-index: 999;
}
h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
.div1 {
width: 14em;
border: 1px solid black;
padding: 1px;
margin: 1em;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
var cy = cytoscape({
container: document.getElementById('cy'),
layout: {name: 'preset'},
style: [
{
selector: 'node',
style: {
'content': 'data(name)'
}
},
{
selector: 'edge',
style: {
'target-arrow-shape': 'triangle'
}
},
{
selector: '.bigNode',
style: {
"width": 110,
"height": 110
}
},
{
selector: ".mediumNode",
style: {
"width": 90,
"height": 90
}
}
],
elements: {
nodes: [
{data: {id: 'j', name: 'Jerry'}, classes: "bigNode", position: { x: 0, y: 0 }},
{data: {id: 'e', name: 'Elaine'}, position: { x: 100, y: 0 }},
{data: {id: 'k', name: 'Kramer'}, classes: "mediumNode", position: { x: 200, y: 0 }},
{data: {id: 'g', name: 'George', parent: "e"}, position: { x: 80, y: 100 }},
{data: {id: 'n', name: 'Newman', parent: "e"}, position: { x: 120, y: 200 }},
{data: {id: 's', name: 'Soup Nazi', parent: "e"}, position: { x: 40, y: 200 }}
],
edges: [
{data: {source: 'j', target: 'g'}},
{data: {source: 'j', target: 's'}},
{data: {source: 'k', target: 'j'}},
{data: {source: 'k', target: 'n'}},
{data: {source: 'k', target: 'g'}},
]
}
});
// demo your core ext
cy.gridGuide({
guidelinesStyle: {
strokeStyle: "black",
horizontalDistColor: "#ff0000",
verticalDistColor: "green",
initPosAlignmentColor: "#0000ff",
}
});
$(".modules div").click(function () {
var el = $(this);
var opt = {};
if (el.hasClass("enabled")) {
el.children("b").text(" Off");
el.removeClass("enabled");
el.addClass("disabled");
opt[el.attr("id")] = false;
} else {
el.children("b").text(" On");
el.addClass("enabled");
el.removeClass("disabled");
opt[el.attr("id")] = true;
}
cy.gridGuide(opt);
});
$("#gridSpacing").change(function () {
var el = $(this);
var opt = {
gridSpacing: el.val()
};
cy.gridGuide(opt);
});
$("#gridColor").change(function () {
var el = $(this);
var opt = {
gridColor: el.val()}
cy.gridGuide(opt);
});
$("#lineWidth").change(function () {
var el = $(this);
var opt = {
lineWidth: el.val()
};
cy.gridGuide(opt);
});
$("#guidelinesTolerance").change(function () {
var el = $(this);
var opt = {
guidelinesTolerance: el.val()
};
cy.gridGuide(opt);
});
$("#horizontalDistColor").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
horizontalDistColor: el.val()}
};
cy.gridGuide(opt);
});
$("#verticalDistColor").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
verticalDistColor: el.val()}
};
cy.gridGuide(opt);
});
$("#geometricGuidelineColor").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
strokeStyle: el.val()}
};
cy.gridGuide(opt);
});
$("#initPosAlignmentColor").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
initPosAlignmentColor: el.val()}
};
cy.gridGuide(opt);
});
$("#distributionRange").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
range: el.val()}
};
cy.gridGuide(opt);
});
$("#minDistributionRange").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
minDistRange: el.val()}
};
cy.gridGuide(opt);
});
$("#geometricRange").change(function () {
var el = $(this);
var opt = {
guidelinesStyle: {
geometricGuidelineRange: el.val()}
};
cy.gridGuide(opt);
});
});
</script>
</head>
<body>
<h1 style="color: #ff0000; opacity: 1">cytoscape.js-grid-guide demo</h1>
<div id="cy"></div>
<div id="config">
<div class="div1">
<div class="modules">
<h1> Grid Options</h1>
<div id="drawGrid" class="enabled">
Show Grid <b> On </b>
</div>
<div>
<label for="gridSpacing" > Grid Spacing: </label>
<input style="width: 5em" type="number" id="gridSpacing" value="20" min="1">
</div>
<div style="margin: 1em">
<label for="gridColor" >Grid Color: </label>
<input style="width: 5em" type="color" id="gridColor" value="#dedede" >
</div>
<div style="margin: 1em">
<label for="gridColor" >Line Width: </label>
<input style="width: 5em" type="number" id="lineWidth" value="1" min="0.1">
</div>
<div id="panGrid" class="disabled">
Move Grid on Pan <b> Off </b>
</div>
<div id="resize" class="disabled">
Auto Resize <b> Off </b>
</div>
</div>
</div>
<div class="div1">
<div class="modules">
<h1> Snap Policy</h1>
<div id="snapToGridOnRelease" class="enabled">
Snap to Grid On Release <b> On </b>
</div>
<div id="snapToGridDuringDrag" class="disabled">
Snap to Grid During Drag <b> Off </b>
</div>
<div id="snapToAlignmentLocationOnRelease" class="disabled">
Snap to Alignment Location On Release<b> Off </b>
</div>
<div id="snapToAlignmentLocationDuringDrag" class="disabled">
Snap to Alignment Location During Drag<b> Off </b>
</div>
<div id="snapToGridCenter" class="enabled">
Snap to Grid Center <b> On </b>
</div>
<div id="parentPadding" class="disabled">
Parent Padding <b> Off </b>
</div>
</div>
</div>
<div class="div1">
<div class="modules">
<h1>Alignment Options</h1>
<div id="geometricGuideline" class="disabled">
Geometric Guidelines <b> Off </b>
</div>
<div id="distributionGuidelines" class="disabled">
Distribution Guidelines <b> Off </b>
</div>
<div id="initPosAlignment" class="disabled">
Guidelines to Initial Position <b> Off </b>
</div>
<div id="centerToEdgeAlignment" class="disabled">
Center to Edge Alignment <b> Off </b>
</div>
<div>
<label for="guidelinesTolerance" >Guidelines Tolerance: </label>
<input style="width: 5em" type="number" id="guidelinesTolerance" step="0.01" value="4.00" min="0">
</div>
</div>
</div>
<div class="div1">
<h1>Guideline Color Options</h1>
<div style="margin: 1em">
<label for="geometricGuidelineColor" >Geometric Alignment Color: </label>
<input style="width: 5em" type="color" id="geometricGuidelineColor" value="#000000" >
</div>
<div style="margin: 1em">
<label for="horizontalDistColor" >Horizontal Alignment Color: </label>
<input style="width: 5em" type="color" id="horizontalDistColor" value="#ff0000" >
</div>
<div style="margin: 1em">
<label for="verticalDistColor" >Vertical Alignment Color: </label>
<input style="width: 5em" type="color" id="verticalDistColor" value="#00ff00" >
</div>
<div style="margin: 1em">
<label for="initPosAlignmentColor" >Initial Position Alignment Color: </label>
<input style="width: 5em" type="color" id="initPosAlignmentColor" value="#0000ff" >
</div>
<div style="margin: 1em">
<label for="geometricRange" >Geometric Alignment Range: </label>
<input style="width: 5em" type="number" id="geometricRange" step="1" value="450" min="0">
</div>
<div style="margin: 1em">
<label for="distributionRange" >Max Distribution Alignment Range: </label>
<input style="width: 5em" type="number" id="distributionRange" step="1" value="300" min="0">
</div>
<div style="margin: 1em">
<label for="minDistributionRange" >Min Distribution Alignment Range: </label>
<input style="width: 5em" type="number" id="minDistributionRange" step="1" value="10" min="0">
</div>
</div>
</body>
</html>