From 66b26c6e4612633026158c7de39b0fbc650185c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=84=9A=E9=81=93?= Date: Sun, 21 Apr 2019 11:54:31 +0800 Subject: [PATCH] remove ant-design-pro/Charts/Radar --- Workplace/package.json | 5 +- Workplace/src/components/Radar/autoHeight.tsx | 75 +++++++++++++++++++ .../src/components}/Radar/index.less | 0 .../src/components}/Radar/index.tsx | 4 +- Workplace/src/index.tsx | 5 +- 5 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 Workplace/src/components/Radar/autoHeight.tsx rename {Analysis/src/components/Charts => Workplace/src/components}/Radar/index.less (100%) rename {Analysis/src/components/Charts => Workplace/src/components}/Radar/index.tsx (97%) diff --git a/Workplace/package.json b/Workplace/package.json index ff500b4c..1adc1a0e 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 00000000..aa255000 --- /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 ( +

+ {h > 0 && } +
+ ); + } + } + return AutoHeightComponent; + }; +} +export default autoHeight; diff --git a/Analysis/src/components/Charts/Radar/index.less b/Workplace/src/components/Radar/index.less similarity index 100% rename from Analysis/src/components/Charts/Radar/index.less rename to Workplace/src/components/Radar/index.less diff --git a/Analysis/src/components/Charts/Radar/index.tsx b/Workplace/src/components/Radar/index.tsx similarity index 97% rename from Analysis/src/components/Charts/Radar/index.tsx rename to Workplace/src/components/Radar/index.tsx index ab79250d..555da2da 100644 --- a/Analysis/src/components/Charts/Radar/index.tsx +++ b/Workplace/src/components/Radar/index.tsx @@ -1,7 +1,7 @@ import React, { Component } from 'react'; -import { Chart, G2, Tooltip, Geom, Coord, Axis } from 'bizcharts'; +import { Chart, Tooltip, Geom, Coord, Axis } from 'bizcharts'; import { Row, Col } from 'antd'; -import autoHeight from '../autoHeight'; +import autoHeight from './autoHeight'; import styles from './index.less'; export interface IRadarProps { diff --git a/Workplace/src/index.tsx b/Workplace/src/index.tsx index 7a87036f..5eb1d986 100644 --- a/Workplace/src/index.tsx +++ b/Workplace/src/index.tsx @@ -4,17 +4,16 @@ import { connect } from 'dva'; import Link from 'umi/link'; import { Row, Col, Card, List, Avatar } from 'antd'; import { Dispatch } from 'redux'; -import { Charts } from 'ant-design-pro'; + import EditableLinkGroup from './components/EditableLinkGroup'; import PageHeaderWrapper from './components/PageHeaderWrapper'; +import Radar from './components/Radar'; import { ModalState } from './model'; import { CurrentUser, Activeties, RadarData, Notice } from './data'; import styles from './style.less'; -const { Radar } = Charts; - const links = [ { title: '操作一', -- GitLab