-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathHexapodPlot.js
50 lines (42 loc) · 1.38 KB
/
HexapodPlot.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from "react"
import * as defaults from "../templates"
import { getNewPlotParams } from "../hexapod"
import Scatter3d from "plotly.js/lib/scatter3d"
import Mesh3d from "plotly.js/lib/mesh3d"
import createPlotlyComponent from "react-plotly.js/factory"
class HexapodPlot extends React.Component {
cameraView = defaults.CAMERA_VIEW
state = { ready: false }
Plot = null
logCameraView = relayoutData => {
this.cameraView = relayoutData["scene.camera"]
}
componentDidMount() {
import("plotly.js/lib/core").then(Plotly => {
Plotly.register([Scatter3d, Mesh3d])
this.Plot = createPlotlyComponent(Plotly)
this.setState({ ready: true })
})
}
render() {
if (!this.state.ready) {
return <p>Loading your cute robot...</p>
}
if (!this.props.hexapod) {
return null
}
const [data, layout] = getNewPlotParams(this.props.hexapod, this.cameraView)
const props = {
data,
layout,
onRelayout: this.logCameraView,
revision: this.props.revision,
config: { displaylogo: false, responsive: true },
style: { height: "100%", width: "100%" },
useResizeHandler: true,
}
const Plot = this.Plot
return <Plot {...props} />
}
}
export default HexapodPlot