Skip to content

Commit 7ea022a

Browse files
committed
Add emitParticles and onBackground events
1 parent 6a8119b commit 7ea022a

File tree

10 files changed

+67
-14
lines changed

10 files changed

+67
-14
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Check out the examples:
3535
* [Click to focus on node](https://vasturiano.github.io/react-force-graph/example/click-to-focus/) ([source](https://github.com/vasturiano/react-force-graph/blob/master/example/click-to-focus/index.html))
3636
* [Camera automatic orbitting](https://vasturiano.github.io/react-force-graph/example/camera-auto-orbit/) ([source](https://github.com/vasturiano/react-force-graph/blob/master/example/camera-auto-orbit/index.html))
3737
* [Node collision detection](https://vasturiano.github.io/react-force-graph/example/collision-detection/) ([source](https://github.com/vasturiano/react-force-graph/blob/master/example/collision-detection/index.html))
38+
* [Emit link particles on demand](https://vasturiano.github.io/react-force-graph/example/emit-particles/) ([source](https://github.com/vasturiano/react-force-graph/blob/master/example/emit-particles/index.html))
3839
* [Force-directed tree (DAG mode)](https://vasturiano.github.io/react-force-graph/example/tree/) ([source](https://github.com/vasturiano/react-force-graph/blob/master/example/tree/index.html))
3940

4041
## Quick start
@@ -134,6 +135,10 @@ Note that not all props listed below apply to all 3 components. The last 3 colum
134135
| <b>linkDirectionalParticleColor</b> | <i>string</i> or <i>func</i> | `color` | Link object accessor function or attribute for the directional particles color. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
135136
| <b>linkDirectionalParticleResolution</b> | <i>number</i> | 4 | Geometric resolution of each 3D directional particle, expressed in how many slice segments to divide the circumference. Higher values yield smoother particles. | | :heavy_check_mark: | :heavy_check_mark: |
136137

138+
| Method | Arguments | Description | 2D | 3D | VR |
139+
| --- | :--: | --- | :--: | :--: | :--: |
140+
| <b>emitParticle</b> | (<i>link</i>) | An alternative mechanism for generating particles, this method emits a non-cyclical single particle within a specific link. The emitted particle shares the styling (speed, width, color) of the regular particle props. A valid `link` object that is included in `graphData` should be passed as a single parameter. | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
141+
137142
### Render control
138143

139144
| Prop | Type | Default | Description |
@@ -185,6 +190,8 @@ Note that not all props listed below apply to all 3 components. The last 3 colum
185190
| <b>onLinkClick</b> | <i>func</i> | *-* | Callback function for link (left-button) clicks. The link object is included as single argument `onLinkClick(link)`. | :heavy_check_mark: | :heavy_check_mark: | |
186191
| <b>onLinkRightClick</b> | <i>func</i> | *-* | Callback function for link right-clicks. The link object is included as single argument `onLinkRightClick(link)`. | :heavy_check_mark: | :heavy_check_mark: | |
187192
| <b>onLinkHover</b> | <i>func</i> | *-* | Callback function for link mouse over events. The link object (or `null` if there's no link under the mouse line of sight) is included as the first argument, and the previous link object (or null) as second argument: `onLinkHover(link, prevLink)`. | :heavy_check_mark: | :heavy_check_mark: | |
193+
| <b>onBackgroundClick</b> | <i>func</i> | *-* | Callback function for click events on the empty space between the nodes and links. | :heavy_check_mark: | :heavy_check_mark: | |
194+
| <b>onBackgroundRightClick</b> | <i>func</i> | *-* | Callback function for right-click events on the empty space between the nodes and links. | :heavy_check_mark: | :heavy_check_mark: | |
188195
| <b>linkHoverPrecision</b> | <i>number</i> | 4 | Whether to display the link label when gazing the link closely (low value) or from far away (high value). | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
189196
| <b>onZoom</b> | <i>func</i> | *-* | Callback function for zoom/pan events. The current zoom transform is included as single argument `onZoom({ k, x, y })`. Note that `onZoom` is triggered by user interaction as well as programmatic zooming/panning with `zoom()` and `centerAt()`. | :heavy_check_mark: | | |
190197
| <b>controlType</b> | <i>string</i> | `trackball` | Which type of control to use to control the camera on 3D mode. Choice between [trackball](https://threejs.org/examples/misc_controls_trackball.html), [orbit](https://threejs.org/examples/#misc_controls_orbit) or [fly](https://threejs.org/examples/misc_controls_fly.html). | | :heavy_check_mark: | |

example/emit-particles/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<head>
2+
<style> body { margin: 0; } </style>
3+
4+
<script src="//unpkg.com/react@16/umd/react.production.min.js"></script>
5+
<script src="//unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
6+
<script src="//unpkg.com/babel-standalone"></script>
7+
8+
<script src="//unpkg.com/react-force-graph-3d"></script>
9+
<!--<script src="../../src/packages/react-force-graph-3d/dist/react-force-graph-3d.js"></script>-->
10+
11+
<script src="../datasets/random-data.js"></script>
12+
</head>
13+
14+
<body>
15+
<div id="graph"></div>
16+
17+
<script type="text/jsx">
18+
const { useEffect, useRef } = React;
19+
20+
const data = genRandomTree();
21+
const distance = 1400;
22+
23+
const CameraOrbit = () => {
24+
const fgRef = useRef();
25+
26+
return <ForceGraph3D
27+
ref={fgRef}
28+
graphData={data}
29+
linkDirectionalParticleColor={() => 'red'}
30+
linkDirectionalParticleWidth={6}
31+
linkHoverPrecision={10}
32+
onLinkClick={link => fgRef.current.emitParticle(link)}
33+
/>;
34+
};
35+
36+
ReactDOM.render(
37+
<CameraOrbit />,
38+
document.getElementById('graph')
39+
);
40+
</script>
41+
</body>

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"dist/**/*"
4141
],
4242
"dependencies": {
43-
"3d-force-graph": "^1.54.0",
44-
"3d-force-graph-vr": "^1.28.0",
45-
"force-graph": "^1.19.0",
43+
"3d-force-graph": "^1.55.1",
44+
"3d-force-graph-vr": "^1.29.0",
45+
"force-graph": "^1.21.2",
4646
"prop-types": "^15.7.2",
4747
"react-kapsule": "^1.4.3"
4848
},
@@ -56,11 +56,11 @@
5656
"@babel/preset-env": "^7.6.2",
5757
"@babel/preset-react": "^7.0.0",
5858
"rimraf": "^3.0.0",
59-
"rollup": "^1.21.4",
59+
"rollup": "^1.22.0",
6060
"rollup-plugin-babel": "^4.3.3",
6161
"rollup-plugin-commonjs": "^10.1.0",
6262
"rollup-plugin-node-resolve": "^5.2.0",
6363
"rollup-plugin-replace": "^2.2.0",
64-
"terser": "^4.3.1"
64+
"terser": "^4.3.4"
6565
}
6666
}

src/forcegraph-proptypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const pointerBasedPropTypes = {
5151
onLinkClick: PropTypes.func,
5252
onLinkRightClick: PropTypes.func,
5353
onLinkHover: PropTypes.func,
54+
onBackgroundClick: PropTypes.func,
55+
onBackgroundRightClick: PropTypes.func,
5456
enablePointerInteraction: PropTypes.bool,
5557
enableNodeDrag: PropTypes.bool
5658
};

src/packages/react-force-graph-2d/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ForceGraph2D = fromKapsule(
66
ForceGraph2DKapsule,
77
undefined,
88
[ // bind methods
9+
'emitParticle',
910
'd3Force',
1011
'd3ReheatSimulation',
1112
'stopAnimation',

src/packages/react-force-graph-2d/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"dist/**/*"
3737
],
3838
"dependencies": {
39-
"force-graph": "^1.19.0",
39+
"force-graph": "^1.21.2",
4040
"prop-types": "^15.7.2",
4141
"react-kapsule": "^1.4.3"
4242
},
@@ -45,7 +45,7 @@
4545
},
4646
"devDependencies": {
4747
"rimraf": "^3.0.0",
48-
"rollup": "^1.21.4",
49-
"terser": "^4.3.1"
48+
"rollup": "^1.22.0",
49+
"terser": "^4.3.4"
5050
}
5151
}

src/packages/react-force-graph-3d/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ForceGraph3D = fromKapsule(
66
ForceGraph3DKapsule,
77
undefined,
88
[ // bind methods
9+
'emitParticle',
910
'd3Force',
1011
'd3ReheatSimulation',
1112
'stopAnimation',

src/packages/react-force-graph-3d/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dist/**/*"
3838
],
3939
"dependencies": {
40-
"3d-force-graph": "^1.54.0",
40+
"3d-force-graph": "^1.55.1",
4141
"prop-types": "^15.7.2",
4242
"react-kapsule": "^1.4.3"
4343
},
@@ -46,7 +46,7 @@
4646
},
4747
"devDependencies": {
4848
"rimraf": "^3.0.0",
49-
"rollup": "^1.21.4",
50-
"terser": "^4.3.1"
49+
"rollup": "^1.22.0",
50+
"terser": "^4.3.4"
5151
}
5252
}

src/packages/react-force-graph-vr/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ForceGraphVR = fromKapsule(
66
ForceGraphVRKapsule,
77
undefined,
88
[ // bind methods
9+
'emitParticle',
910
'd3Force',
1011
'd3ReheatSimulation',
1112
'refresh'

src/packages/react-force-graph-vr/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dist/**/*"
3838
],
3939
"dependencies": {
40-
"3d-force-graph-vr": "^1.28.0",
40+
"3d-force-graph-vr": "^1.29.0",
4141
"prop-types": "^15.7.2",
4242
"react-kapsule": "^1.4.3"
4343
},
@@ -46,7 +46,7 @@
4646
},
4747
"devDependencies": {
4848
"rimraf": "^3.0.0",
49-
"rollup": "^1.21.4",
50-
"terser": "^4.3.1"
49+
"rollup": "^1.22.0",
50+
"terser": "^4.3.4"
5151
}
5252
}

0 commit comments

Comments
 (0)