From f82a87e3554a881c51c36db62bd77a2ceadae2ed Mon Sep 17 00:00:00 2001 From: Abhas Date: Fri, 22 Jun 2018 16:36:55 +0530 Subject: [PATCH] Add basic grid-area --- src/grid-area.tsx | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/grid-area.tsx diff --git a/src/grid-area.tsx b/src/grid-area.tsx new file mode 100644 index 0000000..d2fd8e6 --- /dev/null +++ b/src/grid-area.tsx @@ -0,0 +1,106 @@ +import * as React from 'react'; +import { PureComponent } from 'react'; +import * as PropTypes from 'prop-types'; +import { + AxisUtils, + ScaleUtils +} from 'react-vis'; + +const { + getTicksTotalFromSize, + getTickValues, + DIRECTION +} = AxisUtils; + +const { getAttributeScale } = ScaleUtils; + +const { VERTICAL, HORIZONTAL } = DIRECTION; + +interface GridAreaProps { + 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, + + style: PropTypes.object, + + // generally supplied by xyplot + marginTop: PropTypes.number, + marginBottom: PropTypes.number, + marginLeft: PropTypes.number, + marginRight: PropTypes.number, + innerWidth: PropTypes.number, + innerHeight: PropTypes.number, +}; + +class GridArea extends PureComponent { + displayName = 'GridArea'; + propTypes = GridAreaPropTypes; + defaultProps = {}; + + requiresSVG = true; + + render() { + const { + innerWidth: width, + innerHeight: height, + marginTop: top, + marginLeft: left, + style + } = this.props; + + const isVertical = true; + const tickXAttr = isVertical ? 'y' : 'x'; + const tickYAttr = isVertical ? 'x' : 'y'; + const length = isVertical ? height : width; + + const scale = getAttributeScale(this.props, 'y'); + const values = [[4, 5.76], [8.5, 11.25]]; + + return ( + + {values.map((v, i) => { + const pos = []; + pos[0] = scale(v[0]); + pos[1] = scale(v[1]); + + const minPos = Math.min(...pos); + const maxPos = Math.max(...pos); + + const rectProps = { + x: 0, + width: width, + y: minPos, + height: maxPos - minPos, + }; + return ( + + ); + })} + + ); + } +} + +export default GridArea;