index.js 2.42 KB
Newer Older
niko's avatar
niko committed
1 2 3
import React from 'react';
import { Chart, Axis, Tooltip, Geom } from 'bizcharts';
import autoHeight from '../autoHeight';
4 5
import styles from '../index.less';

niko's avatar
niko committed
6
@autoHeight()
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
7
export default class MiniArea extends React.PureComponent {
niko's avatar
niko committed
8
  render() {
afc163's avatar
afc163 committed
9
    const {
niko's avatar
niko committed
10 11 12 13
      height,
      data = [],
      forceFit = true,
      color = 'rgba(24, 144, 255, 0.2)',
nikogu's avatar
nikogu committed
14
      borderColor = '#1089ff',
niko's avatar
niko committed
15 16 17 18 19 20
      scale = {},
      borderWidth = 2,
      line,
      xAxis,
      yAxis,
      animate = true,
afc163's avatar
afc163 committed
21
    } = this.props;
22

niko's avatar
niko committed
23
    const padding = [36, 5, 30, 5];
24

niko's avatar
niko committed
25
    const scaleProps = {
26 27 28
      x: {
        type: 'cat',
        range: [0, 1],
niko's avatar
niko committed
29
        ...scale.x,
30 31 32
      },
      y: {
        min: 0,
niko's avatar
niko committed
33
        ...scale.y,
34
      },
niko's avatar
niko committed
35
    };
36

niko's avatar
niko committed
37 38 39 40 41 42 43
    const tooltip = [
      'x*y',
      (x, y) => ({
        name: x,
        value: y,
      }),
    ];
niko's avatar
niko committed
44

niko's avatar
niko committed
45
    const chartHeight = height + 54;
46 47 48

    return (
      <div className={styles.miniChart} style={{ height }}>
49
        <div className={styles.chartContent}>
niko's avatar
niko committed
50 51 52 53 54 55 56 57 58
          {height > 0 && (
            <Chart
              animate={animate}
              scale={scaleProps}
              height={chartHeight}
              forceFit={forceFit}
              data={data}
              padding={padding}
            >
nikogu's avatar
nikogu committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
              <Axis
                key="axis-x"
                name="x"
                label={false}
                line={false}
                tickLine={false}
                grid={false}
                {...xAxis}
              />
              <Axis
                key="axis-y"
                name="y"
                label={false}
                line={false}
                tickLine={false}
                grid={false}
                {...yAxis}
              />
niko's avatar
niko committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
              <Tooltip showTitle={false} crosshairs={false} />
              <Geom
                type="area"
                position="x*y"
                color={color}
                tooltip={tooltip}
                shape="smooth"
                style={{
                  fillOpacity: 1,
                }}
              />
              {line ? (
                <Geom
                  type="line"
                  position="x*y"
                  shape="smooth"
                  color={borderColor}
                  size={borderWidth}
                  tooltip={false}
                />
              ) : (
                <span style={{ display: 'none' }} />
              )}
            </Chart>
          )}
102 103 104 105 106
        </div>
      </div>
    );
  }
}