diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d0556006..13e12db8 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,9 +1,9 @@ -version: "3.5" +version: '3.5' services: ant-design-pro_build: build: ../ - container_name: "ant-design-pro_build" + container_name: 'ant-design-pro_build' volumes: - dist:/usr/src/app/dist @@ -11,7 +11,7 @@ services: image: nginx ports: - 80:80 - container_name: "ant-design-pro_web" + container_name: 'ant-design-pro_web' restart: unless-stopped volumes: - dist:/usr/share/nginx/html:ro diff --git a/package.json b/package.json index da5c1e9f..2032a86a 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "react-dom": "^16.7.0", "react-fittext": "^1.0.0", "react-media": "^1.9.2", + "resize-observer-polyfill": "^1.5.1", "umi": "^2.4.4", "umi-plugin-react": "^1.7.2", "umi-request": "^1.0.5" diff --git a/src/components/Charts/Bar/index.js b/src/components/Charts/Bar/index.js index f0cb65ff..77176df2 100644 --- a/src/components/Charts/Bar/index.js +++ b/src/components/Charts/Bar/index.js @@ -2,12 +2,13 @@ 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 autoHeight from '../autoHeight'; +import ResizeObserver from 'resize-observer-polyfill'; import styles from '../index.less'; -@autoHeight() class Bar extends Component { state = { + width: 0, + height: 0, autoHideXLabels: false, }; @@ -27,6 +28,24 @@ class Bar extends Component { this.node = n; }; + resizeObserver() { + const ro = new ResizeObserver(entries => { + const { width, height } = entries[0].contentRect; + this.setState((preState, { hasLegend }) => { + if (preState.width !== width || preState.height !== height) { + return { + width: width - (hasLegend ? 240 : 0), + height, + }; + } + return null; + }); + }); + if (this.root) { + ro.observe(this.root); + } + } + @Bind() @Debounce(400) resize() { @@ -56,7 +75,7 @@ class Bar extends Component { render() { const { - height, + height: propsHeight, title, forceFit = true, data, @@ -82,13 +101,15 @@ class Bar extends Component { value: y, }), ]; - + const { height: stateHeight, width } = this.state; + const height = propsHeight || stateHeight; return (