UNPKG

@data-ui/xy-chart

Version:

A package of charts with standard x- and y- axes. https://williaster.github.io/data-ui

121 lines (105 loc) 3.98 kB
"use strict"; exports.__esModule = true; exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _axis = require("@vx/axis"); var _propShapes = require("../utils/propShapes"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } var propTypes = { axisStyles: _propShapes.axisStylesShape, hideZero: _propTypes.default.bool, label: _propTypes.default.string, labelOffset: _propTypes.default.number, labelProps: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])), numTicks: _propTypes.default.number, orientation: _propTypes.default.oneOf(['bottom', 'top']), rangePadding: _propTypes.default.number, tickStyles: _propShapes.tickStylesShape, tickComponent: _propTypes.default.func, tickLabelProps: _propTypes.default.func, tickFormat: _propTypes.default.func, tickValues: _propTypes.default.arrayOf( // number or date/moment object _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.object, _propTypes.default.string])), // probably injected by parent innerHeight: _propTypes.default.number, scale: _propTypes.default.func }; var defaultProps = { axisStyles: {}, hideZero: false, innerHeight: null, label: null, labelOffset: 14, labelProps: null, numTicks: null, orientation: 'bottom', rangePadding: null, scale: null, tickComponent: null, tickFormat: null, tickLabelProps: null, tickStyles: {}, tickValues: undefined }; var XAxis = /*#__PURE__*/ function (_React$PureComponent) { _inheritsLoose(XAxis, _React$PureComponent); function XAxis() { return _React$PureComponent.apply(this, arguments) || this; } var _proto = XAxis.prototype; _proto.render = function render() { var _this$props = this.props, axisStyles = _this$props.axisStyles, innerHeight = _this$props.innerHeight, hideZero = _this$props.hideZero, label = _this$props.label, labelOffset = _this$props.labelOffset, labelProps = _this$props.labelProps, numTicks = _this$props.numTicks, orientation = _this$props.orientation, rangePadding = _this$props.rangePadding, scale = _this$props.scale, tickComponent = _this$props.tickComponent, tickFormat = _this$props.tickFormat, passedTickLabelProps = _this$props.tickLabelProps, tickStyles = _this$props.tickStyles, tickValues = _this$props.tickValues; if (!scale || !innerHeight) return null; var Axis = orientation === 'bottom' ? _axis.AxisBottom : _axis.AxisTop; var tickLabelProps = passedTickLabelProps; if (!tickLabelProps) { tickLabelProps = tickStyles.label && tickStyles.label[orientation] ? function () { return tickStyles.label[orientation]; } : undefined; } return _react.default.createElement(Axis, { top: orientation === 'bottom' ? innerHeight : 0, left: 0, rangePadding: rangePadding, hideTicks: numTicks === 0, hideZero: hideZero, label: label, labelOffset: labelOffset, labelProps: labelProps || (axisStyles.label || {})[orientation], numTicks: numTicks, scale: scale, stroke: axisStyles.stroke, strokeWidth: axisStyles.strokeWidth, tickComponent: tickComponent, tickFormat: tickFormat, tickLabelProps: tickLabelProps, tickLength: tickStyles.tickLength, tickStroke: tickStyles.stroke, tickValues: tickValues }); }; return XAxis; }(_react.default.PureComponent); exports.default = XAxis; XAxis.propTypes = propTypes; XAxis.defaultProps = defaultProps; XAxis.displayName = 'XAxis';