58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import React from "react"
|
|
import { Component } from "react"
|
|
import Plot from "react-plotly.js"
|
|
|
|
import { NewTickData, socket } from '../';
|
|
|
|
|
|
|
|
type PlotState = {
|
|
x: Array<number>,
|
|
y: Array<number>
|
|
}
|
|
|
|
class RPlot extends Component<{}, PlotState> {
|
|
constructor(props) {
|
|
super(props)
|
|
}
|
|
|
|
state = {
|
|
x: [],
|
|
y: []
|
|
}
|
|
|
|
componentDidMount() {
|
|
socket.on("new_tick", (data: NewTickData) => {
|
|
this.setState({
|
|
x: [...this.state.x, data.tick],
|
|
y: [...this.state.y, data.price],
|
|
})
|
|
})
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Plot
|
|
data={[
|
|
{
|
|
x: this.state.x,
|
|
y: this.state.y,
|
|
type: 'scatter',
|
|
mode: 'lines+markers',
|
|
"marker.colorbar": { tickformat: ".1f"}
|
|
},
|
|
]}
|
|
layout={{ dragmode: "pan", autosize: true }}
|
|
config={{
|
|
scrollZoom: true,
|
|
displayModeBar: false,
|
|
responsive: true,
|
|
}}
|
|
style={{ width: '90%', height: '90%' }}
|
|
/>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default RPlot;
|