cytoscape-js-node-resizer 1.0.0 → 1.0.1
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.
- package/README.md +30 -2
- package/package.json +2 -2
- package/resizeHandler.js +22 -14
package/README.md
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
## Zero dependency extension for Cytoscape.js that adds node resizing functionality.
|
|
3
|
+
|
|
4
|
+
A replacement for [cytoscape.js-noderesize](https://github.com/jhonatandarosa/cytoscape.js-noderesize)
|
|
5
|
+
and [cytoscape.js-node-editing](https://github.com/iVis-at-Bilkent/cytoscape.js-node-editing) that requires neither jQuery nor Konva
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
```
|
|
12
|
+
npm install cytoscape-js-node-resizer
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
```js
|
|
17
|
+
import Cytoscape from "cytoscape";
|
|
18
|
+
import resizeHandler from "cytoscape-js-node-resizer";
|
|
19
|
+
|
|
20
|
+
Cytoscape.use(resizeHandler);
|
|
21
|
+
|
|
22
|
+
...
|
|
23
|
+
|
|
24
|
+
cy.resizeHandler({
|
|
25
|
+
grapperColor: "#7711C0", // default color
|
|
26
|
+
grapperRadius: "50%", // default radius
|
|
27
|
+
grapperSize: "8px", // default size
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cytoscape-js-node-resizer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A zero dependency extension for Cytoscape.js that adds node resizing functionality.",
|
|
5
5
|
"main": "resizeHandler.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
"url": "https://github.com/gxara/cytoscape-js-node-resizer/issues"
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/gxara/cytoscape-js-node-resizer#readme"
|
|
19
|
-
}
|
|
19
|
+
}
|
package/resizeHandler.js
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
let activeNode = null;
|
|
5
5
|
|
|
6
|
-
const createResizeHandle = (node, cy) => {
|
|
6
|
+
const createResizeHandle = (node, cy, customStyle) => {
|
|
7
7
|
let resizeBox = document.getElementById("resize-box");
|
|
8
8
|
|
|
9
9
|
activeNode = node;
|
|
10
10
|
|
|
11
11
|
const styles = {
|
|
12
12
|
grapperColor: "#7711C0",
|
|
13
|
+
grapperRadius: "50%",
|
|
14
|
+
grapperSize: "8px",
|
|
15
|
+
...customStyle,
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
if (!resizeBox) {
|
|
@@ -27,9 +30,10 @@
|
|
|
27
30
|
// Grapper Handle - Bottom Right
|
|
28
31
|
let resizeHandleBottomRight = document.createElement("div");
|
|
29
32
|
resizeHandleBottomRight.id = "resize-handle-bottom-right";
|
|
30
|
-
resizeHandleBottomRight.style.width =
|
|
31
|
-
resizeHandleBottomRight.style.height =
|
|
32
|
-
resizeHandleBottomRight.style.
|
|
33
|
+
resizeHandleBottomRight.style.width = styles.grapperSize;
|
|
34
|
+
resizeHandleBottomRight.style.height = styles.grapperSize;
|
|
35
|
+
resizeHandleBottomRight.style.backgroundColor = styles.grapperColor;
|
|
36
|
+
resizeHandleBottomRight.style.borderRadius = styles.grapperRadius;
|
|
33
37
|
resizeHandleBottomRight.style.position = "absolute";
|
|
34
38
|
resizeHandleBottomRight.style.cursor = "nwse-resize";
|
|
35
39
|
parentDiv.appendChild(resizeHandleBottomRight);
|
|
@@ -37,9 +41,10 @@
|
|
|
37
41
|
// Grapper Handle - Bottom Left
|
|
38
42
|
let resizeHandleBottomLeft = document.createElement("div");
|
|
39
43
|
resizeHandleBottomLeft.id = "resize-handle-bottom-left";
|
|
40
|
-
resizeHandleBottomLeft.style.width =
|
|
41
|
-
resizeHandleBottomLeft.style.height =
|
|
42
|
-
resizeHandleBottomLeft.style.
|
|
44
|
+
resizeHandleBottomLeft.style.width = styles.grapperSize;
|
|
45
|
+
resizeHandleBottomLeft.style.height = styles.grapperSize;
|
|
46
|
+
resizeHandleBottomLeft.style.backgroundColor = styles.grapperColor;
|
|
47
|
+
resizeHandleBottomLeft.style.borderRadius = styles.grapperRadius;
|
|
43
48
|
resizeHandleBottomLeft.style.position = "absolute";
|
|
44
49
|
resizeHandleBottomLeft.style.cursor = "nesw-resize";
|
|
45
50
|
parentDiv.appendChild(resizeHandleBottomLeft);
|
|
@@ -47,9 +52,10 @@
|
|
|
47
52
|
// Grapper Handle - Top Right
|
|
48
53
|
let resizeHandleTopRight = document.createElement("div");
|
|
49
54
|
resizeHandleTopRight.id = "resize-handle-top-right";
|
|
50
|
-
resizeHandleTopRight.style.width =
|
|
51
|
-
resizeHandleTopRight.style.height =
|
|
52
|
-
resizeHandleTopRight.style.
|
|
55
|
+
resizeHandleTopRight.style.width = styles.grapperSize;
|
|
56
|
+
resizeHandleTopRight.style.height = styles.grapperSize;
|
|
57
|
+
resizeHandleTopRight.style.backgroundColor = styles.grapperColor;
|
|
58
|
+
resizeHandleTopRight.style.borderRadius = styles.grapperRadius;
|
|
53
59
|
resizeHandleTopRight.style.position = "absolute";
|
|
54
60
|
resizeHandleTopRight.style.cursor = "nesw-resize";
|
|
55
61
|
parentDiv.appendChild(resizeHandleTopRight);
|
|
@@ -57,14 +63,16 @@
|
|
|
57
63
|
// Grapper Handle - Top Left
|
|
58
64
|
let resizeHandleTopLeft = document.createElement("div");
|
|
59
65
|
resizeHandleTopLeft.id = "resize-handle-top-left";
|
|
60
|
-
resizeHandleTopLeft.style.width =
|
|
61
|
-
resizeHandleTopLeft.style.height =
|
|
62
|
-
resizeHandleTopLeft.style.
|
|
66
|
+
resizeHandleTopLeft.style.width = styles.grapperSize;
|
|
67
|
+
resizeHandleTopLeft.style.height = styles.grapperSize;
|
|
68
|
+
resizeHandleTopLeft.style.backgroundColor = styles.grapperColor;
|
|
69
|
+
resizeHandleTopLeft.style.borderRadius = styles.grapperRadius;
|
|
63
70
|
resizeHandleTopLeft.style.position = "absolute";
|
|
64
71
|
resizeHandleTopLeft.style.cursor = "nwse-resize";
|
|
65
72
|
parentDiv.appendChild(resizeHandleTopLeft);
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
// Handle dragging to resize
|
|
68
76
|
let isResizing = false;
|
|
69
77
|
let initialX = 0;
|
|
70
78
|
let initialY = 0;
|
|
@@ -241,7 +249,7 @@
|
|
|
241
249
|
cy.on("tap", "node", function (evt) {
|
|
242
250
|
const node = evt.target;
|
|
243
251
|
|
|
244
|
-
createResizeHandle(node, cy);
|
|
252
|
+
createResizeHandle(node, cy, opts);
|
|
245
253
|
positionHandle(node);
|
|
246
254
|
});
|
|
247
255
|
|