Этот коммит содержится в:
enahum
2016-06-09 12:08:20 -03:00
коммит произвёл Joram Wilander
родитель 6a3e742e9b
Коммит 1b2fd5af5e
2 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@@ -23,26 +23,26 @@ export default class DoughnutChart extends React.Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) { if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) {
if (this.chart) { this.initChart(true);
this.chart.destroy();
}
this.initChart();
} }
} }
componentWillUnmount() { componentWillUnmount() {
if (this.chart) { if (this.chart && this.refs.canvas) {
this.chart.destroy(); this.chart.destroy();
} }
} }
initChart() { initChart(update) {
if (!this.refs.canvas) { if (!this.refs.canvas) {
return; return;
} }
var el = ReactDOM.findDOMNode(this.refs.canvas); var el = ReactDOM.findDOMNode(this.refs.canvas);
var ctx = el.getContext('2d'); var ctx = el.getContext('2d');
this.chart = new Chart(ctx, {type: 'doughnut', data: this.props.data, options: this.props.options || {}}); //eslint-disable-line new-cap this.chart = new Chart(ctx, {type: 'doughnut', data: this.props.data, options: this.props.options || {}}); //eslint-disable-line new-cap
if (update) {
this.chart.update();
}
} }
render() { render() {

Просмотреть файл

@@ -23,26 +23,26 @@ export default class LineChart extends React.Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) { if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) {
if (this.chart) { this.initChart(true);
this.chart.destroy();
}
this.initChart();
} }
} }
componentWillUnmount() { componentWillUnmount() {
if (this.chart) { if (this.chart && this.refs.canvas) {
this.chart.destroy(); this.chart.destroy();
} }
} }
initChart() { initChart(update) {
if (!this.refs.canvas) { if (!this.refs.canvas) {
return; return;
} }
var el = ReactDOM.findDOMNode(this.refs.canvas); var el = ReactDOM.findDOMNode(this.refs.canvas);
var ctx = el.getContext('2d'); var ctx = el.getContext('2d');
this.chart = new Chart(ctx, {type: 'line', data: this.props.data, options: this.props.options || {}}); //eslint-disable-line new-cap this.chart = new Chart(ctx, {type: 'line', data: this.props.data, options: this.props.options || {}}); //eslint-disable-line new-cap
if (update) {
this.chart.update();
}
} }
render() { render() {