|
1 | 1 | import React, {Component} from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import {contains, filter, has, isNil, type} from 'ramda'; |
| 3 | +import {contains, intersection, filter, has, isNil, type, pluck} from 'ramda'; |
4 | 4 | /* global Plotly:true */ |
5 | 5 |
|
6 | 6 | const filterEventData = (gd, eventData, event) => { |
@@ -73,16 +73,31 @@ export default class PlotlyGraph extends Component { |
73 | 73 | plot(props) { |
74 | 74 | const {id, figure, animate, animation_options, config} = props; |
75 | 75 | const gd = document.getElementById(id); |
| 76 | + |
76 | 77 | if (animate && this._hasPlotted && figure.data.length === gd.data.length) { |
77 | 78 | return Plotly.animate(id, figure, animation_options); |
78 | 79 | } else { |
79 | | - return Plotly.react(id, figure.data, figure.layout, config).then(() => { |
80 | | - if (!this._hasPlotted) { |
81 | | - this.bindEvents(); |
82 | | - Plotly.Plots.resize(document.getElementById(id)); |
83 | | - this._hasPlotted = true; |
| 80 | + |
| 81 | + let PlotMethod; |
| 82 | + if (intersection( |
| 83 | + pluck('type', figure.data), |
| 84 | + ['candlestick', 'ohlc']).length |
| 85 | + ) { |
| 86 | + PlotMethod = Plotly.newPlot; |
| 87 | + } else { |
| 88 | + PlotMethod = Plotly.react; |
| 89 | + } |
| 90 | + |
| 91 | + return PlotMethod(id, figure.data, figure.layout, config).then( |
| 92 | + () => { |
| 93 | + if (!this._hasPlotted) { |
| 94 | + this.bindEvents(); |
| 95 | + Plotly.Plots.resize(document.getElementById(id)); |
| 96 | + this._hasPlotted = true; |
| 97 | + } |
84 | 98 | } |
85 | | - }); |
| 99 | + ); |
| 100 | + |
86 | 101 | } |
87 | 102 | } |
88 | 103 |
|
|
0 commit comments