-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
node-html-label.ts
33 lines (32 loc) · 990 Bytes
/
node-html-label.ts
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
/* eslint-disable @typescript-eslint/no-namespace */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace NodeHTMLLabels {
declare const cytoscape: typeof import('cytoscape');
declare const CytoscapeLayers: typeof import('../build');
const cy = cytoscape({
container: document.getElementById('app'),
layout: {
name: 'grid',
},
elements: [
...Array(100)
.fill(0)
.map((_, i) => ({ data: { id: `i${i}`, label: `L${i}` } })),
],
});
const layers = CytoscapeLayers.layers(cy);
// render centered labels on each node
layers.renderPerNode(layers.append('html'), () => {}, {
init: (elem, node) => {
elem.style.textAlign = 'center';
elem.textContent = node.data('label') || node.id();
elem.addEventListener('click', () => {
console.log(node.id());
});
},
transform: 'translate(-50%,-50%)',
position: 'center',
uniqueElements: true,
checkBounds: false,
});
}