Add prop-types and ts types

This commit is contained in:
2018-06-28 12:41:42 +05:30
parent b595ed0ae0
commit 5120086609
+24 -14
View File
@@ -9,31 +9,39 @@ import {
const { const {
getTicksTotalFromSize, getTicksTotalFromSize,
getTickValues, getTickValues,
DIRECTION
} = AxisUtils; } = AxisUtils;
const { getAttributeScale } = ScaleUtils; const { getAttributeScale } = ScaleUtils;
const { VERTICAL, HORIZONTAL } = DIRECTION; enum Direction {
VERTICAL = 'vertical',
HORIZONTAL = 'horizontal'
};
type NumberOrString = number | string;
interface GridAreaProps { interface GridAreaProps {
direction: Direction;
highlightRegion: Array<[NumberOrString, NumberOrString]>;
style: {
[styleName: string]: any;
}
// generally supplied by xyplot
marginTop: number; marginTop: number;
marginBottom: number; marginBottom: number;
marginLeft: number; marginLeft: number;
marginRight: number; marginRight: number;
innerWidth: number; innerWidth: number;
innerHeight: number; innerHeight: number;
style: {
[styleName: string]: any;
}
} }
const GridAreaPropTypes = { const GridAreaPropTypes = {
width: PropTypes.number, direction: PropTypes.oneOf([Direction.VERTICAL, Direction.HORIZONTAL]),
height: PropTypes.number, highlightRegion: PropTypes.arrayOf(PropTypes.arrayOf(
top: PropTypes.number, PropTypes.oneOfType([PropTypes.string, PropTypes.number])
left: PropTypes.number, )),
style: PropTypes.object, style: PropTypes.object,
@@ -49,7 +57,9 @@ const GridAreaPropTypes = {
class GridArea extends PureComponent<GridAreaProps, {}> { class GridArea extends PureComponent<GridAreaProps, {}> {
static displayName = 'GridArea'; static displayName = 'GridArea';
static propTypes = GridAreaPropTypes; static propTypes = GridAreaPropTypes;
static defaultProps = {}; static defaultProps = {
direction:Direction.VERTICAL
};
static requiresSVG = true; static requiresSVG = true;
@@ -62,7 +72,7 @@ class GridArea extends PureComponent<GridAreaProps, {}> {
style style
} = this.props; } = this.props;
const isVertical = true; const isVertical = (this.props.direction === Direction.VERTICAL);
const tickXAttr = isVertical ? 'y' : 'x'; const tickXAttr = isVertical ? 'y' : 'x';
const tickYAttr = isVertical ? 'x' : 'y'; const tickYAttr = isVertical ? 'x' : 'y';
const length = isVertical ? height : width; const length = isVertical ? height : width;
@@ -74,7 +84,7 @@ class GridArea extends PureComponent<GridAreaProps, {}> {
top, top,
left left
}, 'y'); }, 'y');
const values = [[4, 5.76], [8.5, 11.25]]; const values = this.props.highlightRegion;
return ( return (
<g <g
@@ -82,7 +92,7 @@ class GridArea extends PureComponent<GridAreaProps, {}> {
className="rv-xy-plot__grid-areas" className="rv-xy-plot__grid-areas"
> >
{values.map((v, i) => { {values.map((v, i) => {
const pos = []; const pos: number[] = [];
pos[0] = scale(v[0]); pos[0] = scale(v[0]);
pos[1] = scale(v[1]); pos[1] = scale(v[1]);