Skip to content

Commit ad46992

Browse files
authored
Merge pull request LGSInnovations#21 from spectriclabs/wpipelayer
Add WPipeLayer
2 parents 3c54f55 + 685f7e6 commit ad46992

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-sigplot",
33
"description": "React wrapper for SigPlot",
4-
"version": "0.1.13",
4+
"version": "0.1.14",
55
"homepage": "https://github.com/lgsinnovations/react-sigplot",
66
"author": {
77
"name": "LGS Innovations",
@@ -28,10 +28,7 @@
2828
"test": "jest --coverage"
2929
},
3030
"dependencies": {
31-
"grunt": "^1.3.0",
32-
"react": "^16.13.1",
33-
"react-dom": "^16.13.1",
34-
"sigplot": "^2.0.0-rc18"
31+
"sigplot": "^2.0.0-rc19"
3532
},
3633
"jest": {
3734
"setupFiles": [

src/wpipelayer.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react'; // eslint-disable-line no-unused-vars
2+
import Layer from './layer';
3+
4+
export default class WPipeLayer extends Layer {
5+
static propTypes = {
6+
/**
7+
* URI to WPIPE websocket server
8+
*
9+
* This usually looks like ws://<some URI>:<some port>
10+
*
11+
* Keep in mind that if the websocket server is on a different domain,
12+
* most browsers/web-servers will block cross origin requests.
13+
*
14+
* Since this layer doesn't take any numeric data,
15+
* we are omitting the use of the `data` prop here.
16+
*/
17+
wsurl: PropTypes.string,
18+
19+
/** Key-value pairs whose values alter plot settings */
20+
overrides: PropTypes.object,
21+
22+
/** Layer options */
23+
options: PropTypes.object,
24+
25+
/** Frames per second throttles the data flow to the client by the specified */
26+
fps: PropTypes.number,
27+
};
28+
29+
/**
30+
* Handles WPipeLayer being mounted onto the DOM
31+
*
32+
* All we need to do when the component 'mounts',
33+
* is call `plot.overlay_wpipe` with the relevant
34+
* websocket url and options. This will return our layer object.
35+
*
36+
* A large portion of the time, especially for dynamic
37+
* systems, this will look like a single
38+
* `this.plot.overlay_wpipe(wsurl, null, {"layerType": "1D", pipesize: ...)`
39+
* upon mount.
40+
*/
41+
componentDidMount() {
42+
const { wsurl, options, layerOptions, fps } = this.props;
43+
this.layer = this.plot.overlay_wpipe(wsurl, options, layerOptions, fps);
44+
}
45+
46+
/**
47+
* Handles new properties being passed into <WPipeLayer/>
48+
*
49+
* This will be replaced by
50+
*
51+
* static getDerivedStateFromProps(nextProps, prevState)
52+
*
53+
* in React 17.
54+
*
55+
* This sits in the lifecycle right before `shouldComponentUpdate`,
56+
* `componentWillUpdate`, and most importantly `render`, so this is
57+
* where we will call the plot's `reload` and `headermod` methods.
58+
*
59+
* @param nextProps the newly received properties
60+
*/
61+
UNSAFE_componentWillReceiveProps(nextProps) {
62+
const {
63+
wsurl: currentWsurl,
64+
options: currentOptions,
65+
layerOptions: currentLayerOptions,
66+
fps: currentFps,
67+
} = this.props;
68+
const {
69+
wsurl: nextWsurl,
70+
options: nextOptions,
71+
layerOptions: nextLayerOptions,
72+
fps: nextFps,
73+
} = nextProps;
74+
75+
// if the wsurl changes, we'll go ahead
76+
// and delete the layer and create a new one
77+
// otherwise, we only need to headermod
78+
// with the new options
79+
if (nextWsurl !== currentWsurl || currentFps !== nextFps) {
80+
this.plot.delete_layer(this.layer);
81+
this.layer = this.plot.overlay_wpipe(nextWsurl, options, layerOptions, nextFps);
82+
} else if (nextOptions !== currentOptions) {
83+
this.plot.headermod(this.layer, nextOptions);
84+
} else if (nextLayerOptions !== currentLayerOptions) {
85+
this.plot.get_layer(this.layer).change_settings(nextLayerOptions);
86+
}
87+
return false;
88+
}
89+
}

0 commit comments

Comments
 (0)