YAxis.js 6.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.YAxis = void 0;
  7. var React = _interopRequireWildcard(require("react"));
  8. var _clsx = _interopRequireDefault(require("clsx"));
  9. var _chartLayoutContext = require("../context/chartLayoutContext");
  10. var _CartesianAxis = require("./CartesianAxis");
  11. var _ChartUtils = require("../util/ChartUtils");
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  13. function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
  14. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16. 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, _toPropertyKey(descriptor.key), descriptor); } }
  17. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  18. function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
  19. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  20. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  21. function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
  22. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  23. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  24. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  25. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  26. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  27. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  28. function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); } /**
  29. * @fileOverview Y Axis
  30. */
  31. var YAxisImpl = function YAxisImpl(_ref) {
  32. var yAxisId = _ref.yAxisId;
  33. var width = (0, _chartLayoutContext.useChartWidth)();
  34. var height = (0, _chartLayoutContext.useChartHeight)();
  35. var axisOptions = (0, _chartLayoutContext.useYAxisOrThrow)(yAxisId);
  36. if (axisOptions == null) {
  37. return null;
  38. }
  39. return (
  40. /*#__PURE__*/
  41. // @ts-expect-error the axisOptions type is not exactly what CartesianAxis is expecting.
  42. React.createElement(_CartesianAxis.CartesianAxis, _extends({}, axisOptions, {
  43. className: (0, _clsx["default"])("recharts-".concat(axisOptions.axisType, " ").concat(axisOptions.axisType), axisOptions.className),
  44. viewBox: {
  45. x: 0,
  46. y: 0,
  47. width: width,
  48. height: height
  49. },
  50. ticksGenerator: function ticksGenerator(axis) {
  51. return (0, _ChartUtils.getTicksOfAxis)(axis, true);
  52. }
  53. }))
  54. );
  55. };
  56. // eslint-disable-next-line react/prefer-stateless-function -- requires static defaultProps
  57. var YAxis = exports.YAxis = /*#__PURE__*/function (_React$Component) {
  58. function YAxis() {
  59. _classCallCheck(this, YAxis);
  60. return _callSuper(this, YAxis, arguments);
  61. }
  62. _inherits(YAxis, _React$Component);
  63. return _createClass(YAxis, [{
  64. key: "render",
  65. value: function render() {
  66. return /*#__PURE__*/React.createElement(YAxisImpl, this.props);
  67. }
  68. }]);
  69. }(React.Component);
  70. _defineProperty(YAxis, "displayName", 'YAxis');
  71. _defineProperty(YAxis, "defaultProps", {
  72. allowDuplicatedCategory: true,
  73. allowDecimals: true,
  74. hide: false,
  75. orientation: 'left',
  76. width: 60,
  77. height: 0,
  78. mirror: false,
  79. yAxisId: 0,
  80. tickCount: 5,
  81. type: 'number',
  82. padding: {
  83. top: 0,
  84. bottom: 0
  85. },
  86. allowDataOverflow: false,
  87. scale: 'auto',
  88. reversed: false
  89. });