tycho-components 0.19.8 → 0.19.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import cytoscape, { Core } from
|
|
2
|
-
import { CytoscapeTree } from
|
|
1
|
+
import cytoscape, { Core } from 'cytoscape';
|
|
2
|
+
import { CytoscapeTree } from '../../configs/types/Tree';
|
|
3
3
|
type Props = {
|
|
4
4
|
selector: string;
|
|
5
5
|
tree: CytoscapeTree;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import cytoscape from
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import cytoscape from 'cytoscape';
|
|
2
|
+
import defaultStylesheet from './CytoscapeStylesheet';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import nodeHtmlLabel from 'cytoscape-node-html-label';
|
|
4
5
|
nodeHtmlLabel(cytoscape);
|
|
5
6
|
const init = ({ selector, tree, dagre = false, stylesheet = defaultStylesheet, wheelSensitivity = 1.5, onReady, autoungrabify = true, }) => {
|
|
6
7
|
destroy(selector);
|
|
7
8
|
const cy = cytoscape({
|
|
8
9
|
container: document.getElementById(selector),
|
|
9
|
-
layout: { name:
|
|
10
|
+
layout: { name: 'preset' },
|
|
10
11
|
elements: { nodes: tree.nodes || [], edges: tree.edges || [] },
|
|
11
12
|
style: stylesheet,
|
|
12
13
|
zoom: 2,
|
|
@@ -17,7 +18,7 @@ const init = ({ selector, tree, dagre = false, stylesheet = defaultStylesheet, w
|
|
|
17
18
|
userZoomingEnabled: true,
|
|
18
19
|
userPanningEnabled: true,
|
|
19
20
|
boxSelectionEnabled: true,
|
|
20
|
-
selectionType:
|
|
21
|
+
selectionType: 'single',
|
|
21
22
|
touchTapThreshold: 8,
|
|
22
23
|
desktopTapThreshold: 4,
|
|
23
24
|
autolock: false,
|
|
@@ -33,37 +34,43 @@ const init = ({ selector, tree, dagre = false, stylesheet = defaultStylesheet, w
|
|
|
33
34
|
wheelSensitivity,
|
|
34
35
|
pixelRatio: 1,
|
|
35
36
|
});
|
|
36
|
-
cy.on(
|
|
37
|
-
cy.container()?.style.setProperty(
|
|
37
|
+
cy.on('mouseover', 'node', () => {
|
|
38
|
+
cy.container()?.style.setProperty('cursor', 'pointer');
|
|
38
39
|
});
|
|
39
|
-
cy.on(
|
|
40
|
-
cy.container()?.style.setProperty(
|
|
40
|
+
cy.on('mouseout', 'node', () => {
|
|
41
|
+
cy.container()?.style.setProperty('cursor', 'default');
|
|
41
42
|
});
|
|
42
43
|
cy.ready(() => {
|
|
43
44
|
if (!cy._htmlLabelsApplied) {
|
|
44
|
-
const nodesToLabel = cy.nodes(".token");
|
|
45
45
|
// @ts-ignore (no types)
|
|
46
46
|
cy.nodeHtmlLabel([
|
|
47
47
|
{
|
|
48
|
-
query:
|
|
49
|
-
halign:
|
|
50
|
-
valign:
|
|
51
|
-
|
|
48
|
+
query: 'node',
|
|
49
|
+
halign: 'center',
|
|
50
|
+
valign: 'center',
|
|
51
|
+
halignBox: 'center',
|
|
52
|
+
valignBox: 'center',
|
|
53
|
+
tpl: (data) => {
|
|
54
|
+
return buildTemplateToken(data);
|
|
55
|
+
},
|
|
52
56
|
},
|
|
53
57
|
]);
|
|
54
|
-
cy._htmlLabelsApplied = true;
|
|
58
|
+
cy._htmlLabelsApplied = true;
|
|
55
59
|
}
|
|
56
60
|
cy.fit();
|
|
57
61
|
cy.center();
|
|
58
|
-
dagre && cy.layout({ name:
|
|
62
|
+
dagre && cy.layout({ name: 'dagre' }).run();
|
|
59
63
|
onReady && onReady(cy);
|
|
60
64
|
});
|
|
61
65
|
return cy;
|
|
62
66
|
};
|
|
67
|
+
const buildTemplateToken = (data) => {
|
|
68
|
+
return `<div class="token-data ${data.classes || ''}">${data.label}</div>`;
|
|
69
|
+
};
|
|
63
70
|
const destroy = (selector) => {
|
|
64
71
|
const el = document.getElementById(selector);
|
|
65
72
|
if (el)
|
|
66
|
-
el.innerHTML =
|
|
73
|
+
el.innerHTML = '';
|
|
67
74
|
};
|
|
68
75
|
const SyntreesCytoscape = {
|
|
69
76
|
init,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tycho-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.9",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"axios": "^1.13.6",
|
|
26
26
|
"classnames": "^2.5.1",
|
|
27
27
|
"cytoscape": "^3.28.1",
|
|
28
|
-
"cytoscape-node-
|
|
28
|
+
"cytoscape-node-html-label": "^1.2.2",
|
|
29
29
|
"file-saver": "^2.0.5",
|
|
30
30
|
"html2canvas": "^1.4.1",
|
|
31
31
|
"js-cookie": "^3.0.5",
|