Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit ea4e66c

Browse files
committed
newPlot if finance charts, react otherwise
1 parent 4e13432 commit ea4e66c

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/components/Graph.react.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
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';
44
/* global Plotly:true */
55

66
const filterEventData = (gd, eventData, event) => {
@@ -73,16 +73,31 @@ export default class PlotlyGraph extends Component {
7373
plot(props) {
7474
const {id, figure, animate, animation_options, config} = props;
7575
const gd = document.getElementById(id);
76+
7677
if (animate && this._hasPlotted && figure.data.length === gd.data.length) {
7778
return Plotly.animate(id, figure, animation_options);
7879
} 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+
}
8498
}
85-
});
99+
);
100+
86101
}
87102
}
88103

0 commit comments

Comments
 (0)