forked from sgratzl/cytoscape.js-layers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_esm.html
60 lines (58 loc) · 1.63 KB
/
default_esm.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
<!doctype html>
<html>
<head>
<title>ESM Sample</title>
<style>
#app {
width: 600px;
height: 400px;
display: block;
}
</style>
</head>
<body>
<div id="app"></div>
<script defer src="https://cdn.jsdelivr.net/npm/es-module-shims"></script>
<script type="importmap-shim">
{
"imports": {
"cytoscape": "https://cdn.jsdelivr.net/npm/[email protected]/dist/cytoscape.esm.min.js",
"cytoscape-layers": "../build/index.esm.js"
}
}
</script>
<script type="module-shim">
import cytoscape from 'cytoscape';
import Layers from 'cytoscape-layers';
cytoscape.use(Layers);
const cy = cytoscape({
container: document.getElementById('app'),
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{
data: {
id: 'ab',
source: 'a',
target: 'b',
},
},
],
});
const layers = cy.layers();
// layers.append('svg-static').node.innerHTML = `<text>TEST</text>`;
layers.nodeLayer.insertAfter('html-static').node.innerHTML = 'Static Test Label';
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();
});
layers.renderPerEdge(layers.append('canvas'), (ctx, edge, path) => {
ctx.strokeStyle = 'red';
ctx.stroke(path);
});
</script>
</body>
</html>