-
Notifications
You must be signed in to change notification settings - Fork 24
/
demo.html
145 lines (121 loc) · 3.2 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
<!DOCTYPE>
<html>
<head>
<title>cytoscape-edge-editing.js demo</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<link href="https://unpkg.com/cytoscape-context-menus/cytoscape-context-menus.css" rel="stylesheet" type="text/css" />
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/[email protected]/konva.min.js"></script>
<!-- for testing with local version of cytoscape.js -->
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
<script src="https://unpkg.com/cytoscape-context-menus/cytoscape-context-menus.js"></script>
<script src="https://unpkg.com/cytoscape-undo-redo/cytoscape-undo-redo.js"></script>
<script src="cytoscape-edge-editing.js"></script>
<style>
body {
font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;
font-size: 14px;
}
#cy {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 999;
}
h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
style: [
{
selector: 'node[name]',
style: {
'content': 'data(name)'
}
},
{
selector: 'edge',
style: {
'target-arrow-shape': 'triangle',
'curve-style': 'straight'
}
}
],
layout: { name: 'grid', rows: 2, cols: 2 },
wheelSensitivity: 0.1,
elements: {
nodes: [
{ data: { id: 'j', name: 'Jerry' } },
{ data: { id: 'e', name: 'Elaine' } },
{ data: { id: 'k', name: 'Kramer' } },
{ data: { id: 'g', name: 'George' } }
],
edges: [
{
data: {
source: 'j',
target: 'e',
cyedgebendeditingWeights: [1],
cyedgebendeditingDistances: [175],
round: false
},
classes: 'edgebendediting-hasbendpoints',
},
{
data: {
source: 'k',
target: 'g',
cyedgebendeditingWeights: [0.2],
cyedgebendeditingDistances: [-110],
round: true
},
classes: 'edgebendediting-hasbendpoints',
},
{
data: {
source: 'j',
target: 'k',
cyedgecontroleditingWeights: [0.5],
cyedgecontroleditingDistances: [50]
},
classes: 'edgecontrolediting-hascontrolpoints',
},
{ data: { source: 'j', target: 'g' } }
]
},
});
// demo your ext
cy.edgeEditing({
undoable: true,
bendRemovalSensitivity: 16,
enableMultipleAnchorRemovalOption: true,
initAnchorsAutomatically: false,
useTrailingDividersAfterContextMenuOptions: false,
enableCreateAnchorOnDrag: true,
bendCornersIsRoundFunction(e) { return e.data('round') }
});
cy.style().update();
});
document.addEventListener('keydown', function (e) {
if (e.ctrlKey && e.which == '90') {
cy.undoRedo().undo();
}
else if (e.ctrlKey && e.which == '89') {
cy.undoRedo().redo();
}
}, true);
</script>
</head>
<body>
<h1>cytoscape-edge-editing demo</h1>
<div id="cy"></div>
</body>
</html>