UNPKG

victory-chart

Version:
86 lines (68 loc) 4.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 _react = require("react"); var _react2 = _interopRequireDefault(_react); var _victoryCore = require("victory-core"); 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 Bar = function (_React$Component) { _inherits(Bar, _React$Component); function Bar() { _classCallCheck(this, Bar); return _possibleConstructorReturn(this, Object.getPrototypeOf(Bar).apply(this, arguments)); } _createClass(Bar, [{ key: "getVerticalBarPath", value: function getVerticalBarPath(position, width) { var x = position.x; var y0 = position.y0; var y1 = position.y1; var size = width / 2; return "M " + (x - size) + ", " + y0 + "\n L " + (x - size) + ", " + y1 + "\n L " + (x + size) + ", " + y1 + "\n L " + (x + size) + ", " + y0 + "\n L " + (x - size) + ", " + y0; } }, { key: "getHorizontalBarPath", value: function getHorizontalBarPath(position, width) { var x = position.x; var y0 = position.y0; var y1 = position.y1; var size = width / 2; return "M " + y0 + ", " + (x - size) + "\n L " + y0 + ", " + (x + size) + "\n L " + y1 + ", " + (x + size) + "\n L " + y1 + ", " + (x - size) + "\n L " + y0 + ", " + (x - size); } }, { key: "getBarPath", value: function getBarPath(position, width) { return this.props.horizontal ? this.getHorizontalBarPath(position, width) : this.getVerticalBarPath(position, width); } }, { key: "render", value: function render() { var style = _victoryCore.Helpers.evaluateStyle(this.props.style, this.props.datum); // TODO better bar width calculation var barWidth = style.width || 8; var path = typeof this.props.position.x === "number" ? this.getBarPath(this.props.position, barWidth) : undefined; var events = _victoryCore.Helpers.getPartialEvents(this.props.events, this.props.index, this.props); return _react2.default.createElement("path", _extends({}, events, { d: path, style: style, shapeRendering: "optimizeSpeed" })); } }]); return Bar; }(_react2.default.Component); Bar.propTypes = { index: _react.PropTypes.number, events: _react.PropTypes.object, position: _react.PropTypes.object, horizontal: _react.PropTypes.bool, style: _react.PropTypes.object, datum: _react.PropTypes.object }; exports.default = Bar;