index.js 1.99 KB
Newer Older
nikogu's avatar
nikogu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import React, { PureComponent } from 'react';

import { NumberInfo, MiniArea } from '../Charts';
import { fixedZero } from '../../utils/utils';

import styles from './index.less';

function getActiveData() {
  const activeData = [];
  for (let i = 0; i < 24; i += 1) {
    activeData.push({
      x: `${fixedZero(i)}:00`,
      y: (i * 50) + (Math.floor(Math.random() * 200)),
    });
  }
  return activeData;
}

export default class ActiveChart extends PureComponent {
  state = {
    activeData: getActiveData(),
  }

  componentDidMount() {
nikogu's avatar
nikogu committed
25
    this.timer = setInterval(() => {
nikogu's avatar
nikogu committed
26 27 28 29 30 31
      this.setState({
        activeData: getActiveData(),
      });
    }, 1000);
  }

nikogu's avatar
nikogu committed
32 33 34 35
  componentWillUnmount() {
    clearInterval(this.timer);
  }

nikogu's avatar
nikogu committed
36 37 38 39 40 41 42 43 44 45 46 47 48
  render() {
    const { activeData = [] } = this.state;

    return (
      <div className={styles.activeChart}>
        <NumberInfo
          subTitle="目标评估"
          total="有望达到预期"
        />
        <div style={{ marginTop: 32 }}>
          <MiniArea
            animate={false}
            line
niko's avatar
niko committed
49 50 51
            borderColor="#00a2fc"
            borderWidth={2}
            color="#c9eafe"
nikogu's avatar
nikogu committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
            height={84}
            yAxis={{
              tickCount: 3,
              tickLine: false,
              labels: false,
              title: false,
              line: false,
            }}
            data={activeData}
          />
        </div>
        {
          activeData && (
            <div className={styles.activeChartGrid}>
              <p>{[...activeData].sort()[activeData.length - 1].y + 200} 亿元</p>
              <p>{[...activeData].sort()[Math.floor(activeData.length / 2)].y} 亿元</p>
            </div>
          )
        }
        {
          activeData && (
            <div className={styles.activeChartLegend}>
              <span>00:00</span>
              <span>{activeData[Math.floor(activeData.length / 2)].x}</span>
              <span>{activeData[activeData.length - 1].x}</span>
            </div>
          )
        }
      </div>
    );
  }
}