From 5544d681f490308eb80a8d3b6690eaace0f5eea4 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 16 Dec 2020 10:08:11 +0000 Subject: [PATCH] added positions base prices on plot --- websrc/components/RPlot.tsx | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/websrc/components/RPlot.tsx b/websrc/components/RPlot.tsx index bb4ef7e..0e2fb7c 100644 --- a/websrc/components/RPlot.tsx +++ b/websrc/components/RPlot.tsx @@ -21,6 +21,7 @@ type PlotState = { x: Array, y: Array, current_price_line: PriceLine, + positions_price_lines: Array, } class RPlot extends Component<{}, PlotState> { @@ -28,6 +29,7 @@ class RPlot extends Component<{}, PlotState> { x: [], y: [], current_price_line: {x0: 0, x1: 0, y0: 0, y1: 0}, + positions_price_lines: [] } constructor(props) { @@ -59,6 +61,15 @@ class RPlot extends Component<{}, PlotState> { const x = new_x.slice(Math.max(new_x.length - 500, 0)); const y = new_y.slice(Math.max(new_y.length - 500, 0)); + const position_price_lines = data.positions.map((pstat): PriceLine => { + return { + x0: 0, + y0: pstat.base_price, + x1: data.tick, + y1: pstat.base_price + } + }) + this.setState({ x: x, y: y, @@ -68,11 +79,31 @@ class RPlot extends Component<{}, PlotState> { x1: data.tick, y1: data.price }, + positions_price_lines: position_price_lines }) }) } render() { + let additional_shapes = [] + + if (this.state.positions_price_lines.length > 0) { + additional_shapes = this.state.positions_price_lines.map((priceline: PriceLine) => { + return { + type: 'line', + x0: priceline.x0, + y0: priceline.y0, + x1: priceline.x1, + y1: priceline.y1, + line: { + color: 'rgb(1, 1, 1)', + width: 1, + dash: 'solid' + } + } + }) + } + return ( { dash: 'dashdot' } }, - ], + ].concat(additional_shapes), xaxis: { title: { text: 'Tick', @@ -137,6 +168,7 @@ class RPlot extends Component<{}, PlotState> { /> ) } + } export default RPlot;