UNPKG

@data-ui/histogram

Version:

React + d3 library for creating histograms

78 lines (76 loc) 2.29 kB
import React from 'react'; import PropTypes from 'prop-types'; import { AxisLeft, AxisRight } from '@vx/axis'; import { axisStylesShape, tickStylesShape } from '../utils/propShapes'; var propTypes = { axisStyles: axisStylesShape, label: PropTypes.string, labelProps: PropTypes.object, // eslint-disable-line react/forbid-prop-types numTicks: PropTypes.number, orientation: PropTypes.oneOf(['left', 'right']), tickStyles: tickStylesShape, tickLabelProps: PropTypes.func, tickFormat: PropTypes.func, tickValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), // probably injected by parent top: PropTypes.number, left: PropTypes.number, scale: PropTypes.func }; var defaultProps = { axisStyles: {}, label: null, labelProps: null, left: 0, numTicks: 5, orientation: 'left', scale: null, tickFormat: null, tickLabelProps: undefined, tickStyles: {}, tickValues: undefined, top: 0 }; export default function YAxis(_ref) { var axisStyles = _ref.axisStyles, label = _ref.label, labelProps = _ref.labelProps, top = _ref.top, left = _ref.left, numTicks = _ref.numTicks, orientation = _ref.orientation, scale = _ref.scale, tickFormat = _ref.tickFormat, passedTickLabelProps = _ref.tickLabelProps, tickStyles = _ref.tickStyles, tickValues = _ref.tickValues; if (!scale) return null; var Axis = orientation === 'left' ? AxisLeft : AxisRight; var tickLabelProps = passedTickLabelProps; if (!tickLabelProps) { tickLabelProps = tickStyles.label && tickStyles.label[orientation] ? function () { return tickStyles.label[orientation]; } : undefined; } return React.createElement(Axis, { top: top, left: left, hideTicks: false, hideZero: false, label: label, labelProps: labelProps || (axisStyles.label || {})[orientation], numTicks: numTicks, scale: scale, stroke: axisStyles.stroke, strokeWidth: axisStyles.strokeWidth, tickFormat: tickFormat, tickLabelProps: tickLabelProps, tickLength: tickStyles.tickLength, tickStroke: tickStyles.stroke, tickValues: tickValues }); } YAxis.propTypes = propTypes; YAxis.defaultProps = defaultProps; YAxis.displayName = 'YAxis';