From 5120086609f0acc8fb09e562274be5656cfb531f Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Thu, 28 Jun 2018 12:41:42 +0530 Subject: [PATCH] Add prop-types and ts types --- src/grid-area.tsx | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/grid-area.tsx b/src/grid-area.tsx index 6d8c099..7da5d14 100644 --- a/src/grid-area.tsx +++ b/src/grid-area.tsx @@ -9,31 +9,39 @@ import { const { getTicksTotalFromSize, getTickValues, - DIRECTION } = AxisUtils; const { getAttributeScale } = ScaleUtils; -const { VERTICAL, HORIZONTAL } = DIRECTION; +enum Direction { + VERTICAL = 'vertical', + HORIZONTAL = 'horizontal' +}; + +type NumberOrString = number | string; interface GridAreaProps { + direction: Direction; + highlightRegion: Array<[NumberOrString, NumberOrString]>; + + style: { + [styleName: string]: any; + } + + // generally supplied by xyplot marginTop: number; marginBottom: number; marginLeft: number; marginRight: number; innerWidth: number; innerHeight: number; - - style: { - [styleName: string]: any; - } } const GridAreaPropTypes = { - width: PropTypes.number, - height: PropTypes.number, - top: PropTypes.number, - left: PropTypes.number, + direction: PropTypes.oneOf([Direction.VERTICAL, Direction.HORIZONTAL]), + highlightRegion: PropTypes.arrayOf(PropTypes.arrayOf( + PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + )), style: PropTypes.object, @@ -49,7 +57,9 @@ const GridAreaPropTypes = { class GridArea extends PureComponent { static displayName = 'GridArea'; static propTypes = GridAreaPropTypes; - static defaultProps = {}; + static defaultProps = { + direction:Direction.VERTICAL + }; static requiresSVG = true; @@ -62,7 +72,7 @@ class GridArea extends PureComponent { style } = this.props; - const isVertical = true; + const isVertical = (this.props.direction === Direction.VERTICAL); const tickXAttr = isVertical ? 'y' : 'x'; const tickYAttr = isVertical ? 'x' : 'y'; const length = isVertical ? height : width; @@ -74,7 +84,7 @@ class GridArea extends PureComponent { top, left }, 'y'); - const values = [[4, 5.76], [8.5, 11.25]]; + const values = this.props.highlightRegion; return ( { className="rv-xy-plot__grid-areas" > {values.map((v, i) => { - const pos = []; + const pos: number[] = []; pos[0] = scale(v[0]); pos[1] = scale(v[1]);