Prevent graphs bouncing multiples times when loading analytics pages (#2800)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
c41cd44ada
Коммит
215f78af14
@@ -1,11 +1,13 @@
|
|||||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import Chart from 'chart.js';
|
|
||||||
|
import * as Utils from 'utils/utils.jsx';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import Chart from 'chart.js';
|
||||||
|
|
||||||
export default class DoughnutChart extends React.Component {
|
export default class DoughnutChart extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -16,13 +18,15 @@ export default class DoughnutChart extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.initChart(this.props);
|
this.initChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.chart) {
|
if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) {
|
||||||
this.chart.destroy();
|
if (this.chart) {
|
||||||
this.initChart(nextProps);
|
this.chart.destroy();
|
||||||
|
}
|
||||||
|
this.initChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,10 +36,13 @@ export default class DoughnutChart extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initChart(props) {
|
initChart() {
|
||||||
|
if (!this.refs.canvas) {
|
||||||
|
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).Doughnut(props.data, props.options || {}); //eslint-disable-line new-cap
|
this.chart = new Chart(ctx).Doughnut(this.props.data, this.props.options || {}); //eslint-disable-line new-cap
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import Chart from 'chart.js';
|
|
||||||
|
import * as Utils from 'utils/utils.jsx';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import Chart from 'chart.js';
|
||||||
|
|
||||||
export default class LineChart extends React.Component {
|
export default class LineChart extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -19,11 +21,13 @@ export default class LineChart extends React.Component {
|
|||||||
this.initChart();
|
this.initChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.chart) {
|
if (!Utils.areObjectsEqual(prevProps.data, this.props.data) || !Utils.areObjectsEqual(prevProps.options, this.props.options)) {
|
||||||
this.chart.destroy();
|
if (this.chart) {
|
||||||
|
this.chart.destroy();
|
||||||
|
}
|
||||||
|
this.initChart();
|
||||||
}
|
}
|
||||||
this.initChart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user