-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathremove.html
69 lines (67 loc) · 1.78 KB
/
remove.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
<!doctype html>
<html>
<head>
<title>Sample</title>
<style>
#app {
width: 600px;
height: 400px;
display: block;
}
</style>
</head>
<body>
<div id="app"></div>
<button id="btn">Remove</button>
<button id="btn2">Add</button>
<script src="https://cdn.jsdelivr.net/npm/cytoscape"></script>
<script src="../build/index.umd.js"></script>
<script>
let elements = [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{
data: {
id: 'ab',
source: 'a',
target: 'b',
},
},
];
for (let i = 0; i < 500; i++) {
elements.push({ data: { id: i } });
}
const cy = cytoscape({
container: document.getElementById('app'),
elements: elements,
});
const layers = cy.layers();
layers.renderPerNode(layers.append('canvas'), (ctx, node, bb) => {
ctx.strokeStyle = 'red';
ctx.strokeRect(0, 0, bb.w, bb.h);
});
layers.renderPerNode(layers.append('html'), (elem, node) => {
elem.textContent = node.id();
// xx
});
// layers.renderPerEdge(layers.append('canvas'), (ctx, edge, path) => {
// ctx.strokeStyle = 'red';
// ctx.stroke(path);
// });
document.querySelector('#btn').onclick = function () {
console.time('del');
cy.remove('node[id > 50]');
console.timeEnd('del');
};
document.querySelector('#btn2').onclick = function () {
console.time('add');
const newElements = [];
for (let i = 800; i < 900; i++) {
newElements.push({ data: { id: i } });
}
cy.add(newElements);
console.timeEnd('add');
};
</script>
</body>
</html>