@data-ui/xy-chart
Version:
A package of charts with standard x- and y- axes. https://williaster.github.io/data-ui
129 lines (112 loc) • 4.52 kB
JavaScript
"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 _extends() { _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; }; return _extends.apply(this, arguments); }
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,
labelProps: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])),
labelOffset: _propTypes.default.number,
numTicks: _propTypes.default.number,
orientation: _propTypes.default.oneOf(['left', 'right']),
rangePadding: _propTypes.default.number,
tickComponent: _propTypes.default.func,
tickStyles: _propShapes.tickStylesShape,
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
innerWidth: _propTypes.default.number,
height: _propTypes.default.number,
scale: _propTypes.default.func
};
var defaultProps = {
axisStyles: {},
hideZero: false,
innerWidth: null,
height: null,
label: null,
labelProps: null,
labelOffset: undefined,
numTicks: null,
orientation: 'right',
rangePadding: null,
scale: null,
tickComponent: null,
tickFormat: null,
tickLabelProps: null,
tickStyles: {},
tickValues: undefined
};
var YAxis =
/*#__PURE__*/
function (_React$PureComponent) {
_inheritsLoose(YAxis, _React$PureComponent);
function YAxis() {
return _React$PureComponent.apply(this, arguments) || this;
}
var _proto = YAxis.prototype;
_proto.render = function render() {
var _this$props = this.props,
axisStyles = _this$props.axisStyles,
hideZero = _this$props.hideZero,
innerWidth = _this$props.innerWidth,
height = _this$props.height,
label = _this$props.label,
labelProps = _this$props.labelProps,
labelOffset = _this$props.labelOffset,
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 || !innerWidth) return null;
var Axis = orientation === 'left' ? _axis.AxisLeft : _axis.AxisRight;
var tickLabelProps = passedTickLabelProps;
if (!tickLabelProps) {
tickLabelProps = tickStyles.label && tickStyles.label[orientation] ? function () {
return tickStyles.label[orientation];
} : undefined;
}
return _react.default.createElement(Axis, {
top: 0,
left: orientation === 'right' ? innerWidth : 0,
rangePadding: rangePadding,
hideTicks: numTicks === 0,
hideZero: hideZero,
label: label,
labelProps: _extends({
verticalAnchor: 'start',
width: Math.max.apply(Math, scale.range().concat([height || 0]))
}, labelProps || (axisStyles.label || {})[orientation]),
labelOffset: labelOffset,
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 YAxis;
}(_react.default.PureComponent);
exports.default = YAxis;
YAxis.propTypes = propTypes;
YAxis.defaultProps = defaultProps;
YAxis.displayName = 'YAxis';