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';

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

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

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

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

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

    return (
      <div className={styles.miniChart} style={{ height }}>
50
        <div className={styles.chartContent}>
niko's avatar
niko committed
51 52 53 54 55 56 57 58 59
          {height > 0 && (
            <Chart
              animate={animate}
              scale={scaleProps}
              height={chartHeight}
              forceFit={forceFit}
              data={data}
              padding={padding}
            >
nikogu's avatar
nikogu committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
              <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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
              <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>
          )}
103 104 105 106 107
        </div>
      </div>
    );
  }
}