UNPKG

recharts

Version:
92 lines (66 loc) 4.05 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 Polygon */ 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); 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 Polygon = (0, _pureRenderDecorator2.default)(_class = (_temp = _class2 = function (_Component) { _inherits(Polygon, _Component); function Polygon() { _classCallCheck(this, Polygon); return _possibleConstructorReturn(this, Object.getPrototypeOf(Polygon).apply(this, arguments)); } _createClass(Polygon, [{ key: 'getPolygonPoints', value: function getPolygonPoints(points) { return points.reduce(function (result, entry) { if (entry.x === +entry.x && entry.y === +entry.y) { result.push([entry.x, entry.y]); } return result; }, []).join(' '); } }, { key: 'render', value: function render() { var _props = this.props; var points = _props.points; var className = _props.className; if (!points || !points.length) { return null; } var layerClass = (0, _classnames2.default)('recharts-polygon', className); return _react2.default.createElement('polygon', _extends({}, _ReactUtils2.default.getPresentationAttributes(this.props), { className: layerClass, points: this.getPolygonPoints(points) })); } }]); return Polygon; }(_react.Component), _class2.displayName = 'Polygon', _class2.propTypes = _extends({}, _ReactUtils.PRESENTATION_ATTRIBUTES, { className: _react.PropTypes.string, points: _react.PropTypes.arrayOf(_react.PropTypes.shape({ x: _react.PropTypes.number, y: _react.PropTypes.number })) }), _class2.defaultProps = { fill: 'none', stroke: '#333', strokeWidth: 1 }, _temp)) || _class; exports.default = Polygon;