import { EChartsOption } from 'echarts'; import { observer } from 'mobx-react'; import React from 'react'; import { curveInfo } from 'store/curve-info'; import { fullScreen } from 'store/full-screen'; import { getHight, EXPAND_GRID_HEIGHT, ICurve } from './config'; import './index.less'; import { Spin, Icon } from 'component/antd'; import LineChart, { hasData } from 'component/chart/line-chart'; export interface ICommonCurveProps { options: ICurve; parser?: (option: ICurve, data: any[]) => any; } @observer export class CommonCurve extends React.Component { public componentDidMount() { this.refresh(false); } public componentWillUnmount() { const { path } = this.props.options; curveInfo.setCurveData(path, null); } public refresh = (refresh?: boolean) => { curveInfo.getCommonCurveData(this.props.options, this.props.parser, refresh); } public expand = () => { const curveOption = this.getCurveData(); const options = Object.assign({}, curveOption, { grid: { ...curveOption.grid, height: EXPAND_GRID_HEIGHT, }, }); const loading = this.getLoading(); fullScreen.show(this.renderCurve(options, loading, true)); } public renderOpBtns = (options: EChartsOption, expand = false) => { const data = hasData(options); return (
{!expand ? this.refresh(true)} key="refresh" /> : null} {data ? this.renderExpand(expand) : null}
); } public renderExpand = (expand = false) => { if (expand) return ; return ; } public renderTitle = () => { const { title } = this.props.options; return (
{title}
); } public getCurveData = () => { const { path } = this.props.options; return curveInfo.curveData[path]; } public getLoading = () => { const { path } = this.props.options; return curveInfo.curveLoading[path] || false; } public renderOthers = () => null as JSX.Element; public renderNoData = (height?: number) => { const style = { height: `${height}px`, lineHeight: `${height}px` }; return
暂无数据
; } public renderLoading = (height?: number) => { const style = { height: `${height}px`, lineHeight: `${height}px` }; return
; } public renderEchart = (options: EChartsOption, loading = false) => { const height = getHight(options); const data = hasData(options); if (loading) return this.renderLoading(height); if (!data) return this.renderNoData(height); return ; } public renderCurve = (options: any, loading: boolean, expand = false) => { const data = hasData(options); return (
{this.renderTitle()} {this.renderEchart(options, loading)} {this.renderOpBtns(options, expand)} {data ? this.renderOthers() : null}
); } public render() { const options = this.getCurveData(); const loading = this.getLoading(); return ( <> {this.renderCurve(options, loading)} ); } }