diff --git a/Workplace/package.json b/Workplace/package.json index ff500b4c83538eef7bc851a675ace0a8bf2d5414..1adc1a0e9bf036222b7b3785e1cd7a7302464870 100644 --- a/Workplace/package.json +++ b/Workplace/package.json @@ -16,7 +16,8 @@ "moment": "^2.22.2", "prop-types": "^15.5.10", "react": "^16.6.3", - "umi-request": "^1.0.0" + "umi-request": "^1.0.0", + "bizcharts": "^3.5.2" }, "devDependencies": { "umi": "^2.6.9", @@ -24,4 +25,4 @@ "umi-plugin-react": "^1.3.0-beta.1" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/Workplace/src/components/Radar/autoHeight.tsx b/Workplace/src/components/Radar/autoHeight.tsx new file mode 100644 index 0000000000000000000000000000000000000000..aa25500027388d713c0cc4e9f19a087810646f8a --- /dev/null +++ b/Workplace/src/components/Radar/autoHeight.tsx @@ -0,0 +1,75 @@ +import React from 'react'; + +export type IReactComponent
= + | React.StatelessComponent
+ | React.ComponentClass
+ | React.ClassicComponentClass
; + +function computeHeight(node: HTMLDivElement) { + node.style.height = '100%'; + const totalHeight = parseInt(getComputedStyle(node).height + '', 10); + const padding = + parseInt(getComputedStyle(node).paddingTop + '', 10) + + parseInt(getComputedStyle(node).paddingBottom + '', 10); + return totalHeight - padding; +} + +function getAutoHeight(n: HTMLDivElement) { + if (!n) { + return 0; + } + + let node = n; + + let height = computeHeight(node); + const parentNode = node.parentNode as HTMLDivElement; + if (parentNode) { + height = computeHeight(parentNode); + } + + return height; +} + +interface IAutoHeightProps { + height?: number; +} + +function autoHeight() { + return function
( + WrappedComponent: React.ComponentClass
| React.SFC
+ ): React.ComponentClass
{ + class AutoHeightComponent extends React.Component
{ + state = { + computedHeight: 0, + }; + root!: HTMLDivElement; + componentDidMount() { + const { height } = this.props; + if (!height) { + const h = getAutoHeight(this.root); + // eslint-disable-next-line + this.setState({ computedHeight: h }); + if (h < 1) { + const h = getAutoHeight(this.root); + this.setState({ computedHeight: h }); + } + } + } + handleRoot = (node: HTMLDivElement) => { + this.root = node; + }; + render() { + const { height } = this.props; + const { computedHeight } = this.state; + const h = height || computedHeight; + return ( +