Commit 388d804e authored by jim's avatar jim

Maybe useful performance optimization

parent 62e77dea
...@@ -26,17 +26,26 @@ export default class ActiveChart extends Component { ...@@ -26,17 +26,26 @@ export default class ActiveChart extends Component {
}; };
componentDidMount() { componentDidMount() {
this.timer = setInterval(() => { this.loopData();
this.setState({
activeData: getActiveData(),
});
}, 1000);
} }
componentWillUnmount() { componentWillUnmount() {
clearInterval(this.timer); clearTimeout(this.timer);
} }
loopData = () => {
this.timer = setTimeout(() => {
this.setState(
{
activeData: getActiveData(),
},
() => {
requestAnimationFrame(() => {
this.loopData();
});
}
);
}, 1000);
};
render() { render() {
const { activeData = [] } = this.state; const { activeData = [] } = this.state;
......
...@@ -25,6 +25,7 @@ class Bar extends Component { ...@@ -25,6 +25,7 @@ class Bar extends Component {
if (!this.node) { if (!this.node) {
return; return;
} }
requestAnimationFrame(() => {
const canvasWidth = this.node.parentNode.clientWidth; const canvasWidth = this.node.parentNode.clientWidth;
const { data = [], autoLabel = true } = this.props; const { data = [], autoLabel = true } = this.props;
if (!autoLabel) { if (!autoLabel) {
...@@ -44,6 +45,7 @@ class Bar extends Component { ...@@ -44,6 +45,7 @@ class Bar extends Component {
autoHideXLabels: false, autoHideXLabels: false,
}); });
} }
});
} }
handleRoot = n => { handleRoot = n => {
......
...@@ -19,8 +19,6 @@ export default class Pie extends Component { ...@@ -19,8 +19,6 @@ export default class Pie extends Component {
}; };
componentDidMount() { componentDidMount() {
this.getLegendData();
this.resize();
window.addEventListener('resize', this.resize); window.addEventListener('resize', this.resize);
} }
...@@ -46,12 +44,17 @@ export default class Pie extends Component { ...@@ -46,12 +44,17 @@ export default class Pie extends Component {
getG2Instance = chart => { getG2Instance = chart => {
this.chart = chart; this.chart = chart;
requestAnimationFrame(() => {
this.getLegendData();
this.resize();
});
}; };
// for custom lengend view // for custom lengend view
getLegendData = () => { getLegendData = () => {
if (!this.chart) return; if (!this.chart) return;
const geom = this.chart.getAllGeoms()[0]; // 获取所有的图形 const geom = this.chart.getAllGeoms()[0]; // 获取所有的图形
if (!geom) return;
const items = geom.get('dataArray') || []; // 获取图形对应的 const items = geom.get('dataArray') || []; // 获取图形对应的
const legendData = items.map(item => { const legendData = items.map(item => {
...@@ -71,6 +74,7 @@ export default class Pie extends Component { ...@@ -71,6 +74,7 @@ export default class Pie extends Component {
@Bind() @Bind()
@Debounce(300) @Debounce(300)
resize() { resize() {
requestAnimationFrame(() => {
const { hasLegend } = this.props; const { hasLegend } = this.props;
if (!hasLegend || !this.root) { if (!hasLegend || !this.root) {
window.removeEventListener('resize', this.resize); window.removeEventListener('resize', this.resize);
...@@ -87,6 +91,7 @@ export default class Pie extends Component { ...@@ -87,6 +91,7 @@ export default class Pie extends Component {
legendBlock: false, legendBlock: false,
}); });
} }
});
} }
handleRoot = n => { handleRoot = n => {
......
...@@ -12,7 +12,9 @@ export default class Radar extends Component { ...@@ -12,7 +12,9 @@ export default class Radar extends Component {
}; };
componentDidMount() { componentDidMount() {
requestAnimationFrame(() => {
this.getLengendData(); this.getLengendData();
});
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
......
...@@ -19,8 +19,10 @@ class TagCloud extends Component { ...@@ -19,8 +19,10 @@ class TagCloud extends Component {
}; };
componentDidMount() { componentDidMount() {
requestAnimationFrame(() => {
this.initTagCloud(); this.initTagCloud();
this.renderChart(); this.renderChart();
});
window.addEventListener('resize', this.resize); window.addEventListener('resize', this.resize);
} }
...@@ -36,7 +38,9 @@ class TagCloud extends Component { ...@@ -36,7 +38,9 @@ class TagCloud extends Component {
} }
resize = () => { resize = () => {
requestAnimationFrame(() => {
this.renderChart(); this.renderChart();
});
}; };
saveRootRef = node => { saveRootRef = node => {
......
...@@ -13,9 +13,10 @@ export default class WaterWave extends PureComponent { ...@@ -13,9 +13,10 @@ export default class WaterWave extends PureComponent {
}; };
componentDidMount() { componentDidMount() {
requestAnimationFrame(() => {
this.renderChart(); this.renderChart();
this.resize(); this.resize();
});
window.addEventListener('resize', this.resize); window.addEventListener('resize', this.resize);
} }
...@@ -28,11 +29,13 @@ export default class WaterWave extends PureComponent { ...@@ -28,11 +29,13 @@ export default class WaterWave extends PureComponent {
} }
resize = () => { resize = () => {
requestAnimationFrame(() => {
const { height } = this.props; const { height } = this.props;
const { offsetWidth } = this.root.parentNode; const { offsetWidth } = this.root.parentNode;
this.setState({ this.setState({
radio: offsetWidth < height ? offsetWidth / height : 1, radio: offsetWidth < height ? offsetWidth / height : 1,
}); });
});
}; };
renderChart() { renderChart() {
......
...@@ -52,6 +52,7 @@ export default class Info extends Component { ...@@ -52,6 +52,7 @@ export default class Info extends Component {
if (!this.main) { if (!this.main) {
return; return;
} }
requestAnimationFrame(() => {
let mode = 'inline'; let mode = 'inline';
const { offsetWidth } = this.main; const { offsetWidth } = this.main;
if (this.main.offsetWidth < 641 && offsetWidth > 400) { if (this.main.offsetWidth < 641 && offsetWidth > 400) {
...@@ -63,6 +64,7 @@ export default class Info extends Component { ...@@ -63,6 +64,7 @@ export default class Info extends Component {
this.setState({ this.setState({
mode, mode,
}); });
});
}; };
render() { render() {
const { match, routerData, currentUser } = this.props; const { match, routerData, currentUser } = this.props;
......
...@@ -68,11 +68,13 @@ class AdvancedForm extends PureComponent { ...@@ -68,11 +68,13 @@ class AdvancedForm extends PureComponent {
window.removeEventListener('resize', this.resizeFooterToolbar); window.removeEventListener('resize', this.resizeFooterToolbar);
} }
resizeFooterToolbar = () => { resizeFooterToolbar = () => {
requestAnimationFrame(() => {
const sider = document.querySelectorAll('.ant-layout-sider')[0]; const sider = document.querySelectorAll('.ant-layout-sider')[0];
const width = `calc(100% - ${sider.style.width})`; const width = `calc(100% - ${sider.style.width})`;
if (this.state.width !== width) { if (this.state.width !== width) {
this.setState({ width }); this.setState({ width });
} }
});
}; };
render() { render() {
const { form, dispatch, submitting } = this.props; const { form, dispatch, submitting } = this.props;
......
...@@ -212,6 +212,7 @@ export default class AdvancedProfile extends Component { ...@@ -212,6 +212,7 @@ export default class AdvancedProfile extends Component {
@Bind() @Bind()
@Debounce(200) @Debounce(200)
setStepDirection() { setStepDirection() {
requestAnimationFrame(() => {
const { stepDirection } = this.state; const { stepDirection } = this.state;
const w = getWindowWidth(); const w = getWindowWidth();
if (stepDirection !== 'vertical' && w <= 576) { if (stepDirection !== 'vertical' && w <= 576) {
...@@ -223,6 +224,7 @@ export default class AdvancedProfile extends Component { ...@@ -223,6 +224,7 @@ export default class AdvancedProfile extends Component {
stepDirection: 'horizontal', stepDirection: 'horizontal',
}); });
} }
});
} }
render() { render() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment