diff --git a/src/components/Charts/Bar/index.js b/src/components/Charts/Bar/index.js index f898a122e478f6909a0a7b0ed2a80b6f490e4936..4b8a6a59b5f05bcaab6d2667508d4d9fd399dcc2 100644 --- a/src/components/Charts/Bar/index.js +++ b/src/components/Charts/Bar/index.js @@ -1,8 +1,5 @@ import React, { Component } from 'react'; import { Chart, Axis, Tooltip, Geom } from 'bizcharts'; -import Debounce from 'lodash-decorators/debounce'; -import Bind from 'lodash-decorators/bind'; -import ResizeObserver from 'resize-observer-polyfill'; import styles from '../index.less'; class Bar extends Component { @@ -11,14 +8,6 @@ class Bar extends Component { autoHideXLabels: false, }; - componentDidMount() { - window.addEventListener('resize', this.resize, { passive: true }); - } - - componentWillUnmount() { - window.removeEventListener('resize', this.resize); - } - handleRoot = n => { this.root = n; }; @@ -27,50 +16,6 @@ class Bar extends Component { this.node = n; }; - resizeObserver() { - const ro = new ResizeObserver(entries => { - const { width, height } = entries[0].contentRect; - this.setState(preState => { - if (preState.width !== width || preState.height !== height) { - return { - height, - }; - } - return null; - }); - }); - if (this.root) { - ro.observe(this.root); - } - } - - @Bind() - @Debounce(400) - resize() { - if (!this.node) { - return; - } - const canvasWidth = this.node.parentNode.clientWidth; - const { data = [], autoLabel = true } = this.props; - if (!autoLabel) { - return; - } - const minWidth = data.length * 30; - const { autoHideXLabels } = this.state; - - if (canvasWidth <= minWidth) { - if (!autoHideXLabels) { - this.setState({ - autoHideXLabels: true, - }); - } - } else if (autoHideXLabels) { - this.setState({ - autoHideXLabels: false, - }); - } - } - render() { const { height: propsHeight, diff --git a/src/components/Charts/TagCloud/index.js b/src/components/Charts/TagCloud/index.js index 4898d821a3f9282fdce7d1bb05e85c8e6f7a71d2..2f60124aaee5d2b69ce1013826b1e1eebbd80213 100644 --- a/src/components/Charts/TagCloud/index.js +++ b/src/components/Charts/TagCloud/index.js @@ -19,11 +19,8 @@ class TagCloud extends Component { }; componentDidMount() { - requestAnimationFrame(() => { - this.initTagCloud(); - this.renderChart(); - }); - window.addEventListener('resize', this.resize, { passive: true }); + this.initTagCloud(); + this.renderChart(); } componentDidUpdate(preProps) { @@ -35,16 +32,8 @@ class TagCloud extends Component { componentWillUnmount() { this.isUnmount = true; - window.cancelAnimationFrame(this.requestRef); - window.removeEventListener('resize', this.resize); } - resize = () => { - this.requestRef = requestAnimationFrame(() => { - this.renderChart(); - }); - }; - saveRootRef = node => { this.root = node; };