UNPKG

recharts

Version:
184 lines (142 loc) 6.96 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 _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 Radar */ 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 _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _ReactUtils = require('../util/ReactUtils'); var _ReactUtils2 = _interopRequireDefault(_ReactUtils); var _Polygon = require('../shape/Polygon'); var _Polygon2 = _interopRequireDefault(_Polygon); var _Dot = require('../shape/Dot'); var _Dot2 = _interopRequireDefault(_Dot); var _Layer = require('../container/Layer'); var _Layer2 = _interopRequireDefault(_Layer); 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 Radar = (0, _pureRenderDecorator2.default)(_class = (_temp = _class2 = function (_Component) { _inherits(Radar, _Component); function Radar() { _classCallCheck(this, Radar); return _possibleConstructorReturn(this, Object.getPrototypeOf(Radar).apply(this, arguments)); } _createClass(Radar, [{ key: 'renderPolygon', value: function renderPolygon() { var shape = this.props.shape; var isShapeElement = _react2.default.isValidElement(shape); return isShapeElement ? _react2.default.cloneElement(shape, this.props) : _react2.default.createElement(_Polygon2.default, this.props); } }, { key: 'renderLabels', value: function renderLabels() { var _props = this.props; var points = _props.points; var label = _props.label; var baseProps = _ReactUtils2.default.getPresentationAttributes(this.props); var customLabelProps = _ReactUtils2.default.getPresentationAttributes(label); var isLabelElement = _react2.default.isValidElement(label); var labels = points.map(function (entry, i) { var labelProps = _extends({ textAnchor: 'middle' }, baseProps, { stroke: 'none', fill: baseProps && baseProps.stroke || '#666' }, customLabelProps, entry, { index: i, key: 'label-' + i, payload: entry }); return isLabelElement ? _react2.default.cloneElement(label, labelProps) : _react2.default.createElement( 'text', _extends({}, labelProps, { className: 'recharts-radar-label' }), entry.value ); }); return _react2.default.createElement( _Layer2.default, { className: 'recharts-radar-labels' }, labels ); } }, { key: 'renderDots', value: function renderDots() { var _props2 = this.props; var dot = _props2.dot; var points = _props2.points; var baseProps = _ReactUtils2.default.getPresentationAttributes(this.props); var customDotProps = _ReactUtils2.default.getPresentationAttributes(dot); var isDotElement = _react2.default.isValidElement(dot); var dots = points.map(function (entry, i) { var dotProps = _extends({ key: 'dot-' + i, r: 3 }, baseProps, customDotProps, { cx: entry.x, cy: entry.y, index: i, playload: entry }); return isDotElement ? _react2.default.cloneElement(dot, dotProps) : _react2.default.createElement(_Dot2.default, _extends({}, dotProps, { className: 'recharts-radar-dot' })); }); return _react2.default.createElement( _Layer2.default, { className: 'recharts-radar-dots' }, dots ); } }, { key: 'render', value: function render() { var _props3 = this.props; var className = _props3.className; var points = _props3.points; var label = _props3.label; var dot = _props3.dot; if (!points || !points.length) { return null; } var layerClass = (0, _classnames2.default)('recharts-radar', className); return _react2.default.createElement( _Layer2.default, { className: layerClass }, this.renderPolygon(), label && this.renderLabels(), dot && this.renderDots() ); } }]); return Radar; }(_react.Component), _class2.displayName = 'Radar', _class2.propTypes = { className: _react.PropTypes.string, dataKey: _react.PropTypes.string.isRequired, points: _react.PropTypes.arrayOf(_react.PropTypes.shape({ x: _react.PropTypes.number, y: _react.PropTypes.number, cx: _react.PropTypes.number, cy: _react.PropTypes.number, angle: _react.PropTypes.number, radius: _react.PropTypes.number, value: _react.PropTypes.number, payload: _react.PropTypes.object })), shape: _react.PropTypes.element, dot: _react.PropTypes.oneOfType([_react.PropTypes.element, _react.PropTypes.object, _react.PropTypes.bool]), label: _react.PropTypes.oneOfType([_react.PropTypes.element, _react.PropTypes.object, _react.PropTypes.bool]) }, _class2.defaultProps = { dot: false, label: false }, _temp)) || _class; exports.default = Radar;