UNPKG

recharts

Version:
129 lines (95 loc) 5.66 kB
'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _class, _class2, _temp; /** * @fileOverview Reference Line */ Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _pureRenderDecorator = require('pure-render-decorator'); var _pureRenderDecorator2 = _interopRequireDefault(_pureRenderDecorator); var _ReactUtils = require('../util/ReactUtils'); var _ReactUtils2 = _interopRequireDefault(_ReactUtils); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var ReferenceLine = (0, _pureRenderDecorator2.default)(_class = (_temp = _class2 = function (_Component) { _inherits(ReferenceLine, _Component); function ReferenceLine() { _classCallCheck(this, ReferenceLine); return _possibleConstructorReturn(this, Object.getPrototypeOf(ReferenceLine).apply(this, arguments)); } _createClass(ReferenceLine, [{ key: 'getEndPoints', value: function getEndPoints() { var _props = this.props; var xAxisMap = _props.xAxisMap; var yAxisMap = _props.yAxisMap; var type = _props.type; var value = _props.value; var xAxisId = _props.xAxisId; var yAxisId = _props.yAxisId; var viewBox = _props.viewBox; var x = viewBox.x; var y = viewBox.y; var width = viewBox.width; var height = viewBox.height; var coord = undefined; if (type === 'horizontal') { coord = yAxisMap[yAxisId].scale(value); return [{ x: x, y: coord }, { x: x + width, y: coord }]; } else if (type === 'vertical') { coord = xAxisMap[xAxisId].scale(value); return [{ x: coord, y: y }, { x: coord, y: y + height }]; } } }, { key: 'render', value: function render() { var _props2 = this.props; var type = _props2.type; var value = _props2.value; if (!type) { return null; } var _getEndPoints = this.getEndPoints(); var _getEndPoints2 = _slicedToArray(_getEndPoints, 2); var start = _getEndPoints2[0]; var end = _getEndPoints2[1]; var props = _ReactUtils2.default.getPresentationAttributes(this.props); return _react2.default.createElement('line', _extends({}, props, { className: 'recharts-reference-line', x1: start.x, y1: start.y, x2: end.x, y2: end.y })); } }]); return ReferenceLine; }(_react.Component), _class2.displayName = 'ReferenceLine', _class2.propTypes = _extends({}, _ReactUtils.PRESENTATION_ATTRIBUTES, { viewBox: _react.PropTypes.shape({ x: _react.PropTypes.number, y: _react.PropTypes.number, width: _react.PropTypes.number, height: _react.PropTypes.number }), xAxisMap: _react.PropTypes.object, yAxisMap: _react.PropTypes.object, type: _react.PropTypes.oneOf(['horizontal', 'vertical']), value: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string]), yAxisId: _react.PropTypes.number, xAxisId: _react.PropTypes.number }), _class2.defaultProps = { xAxisId: 0, yAxisId: 0, fill: 'none', fillOpacity: 1, strokeWidth: 1 }, _temp)) || _class; exports.default = ReferenceLine;