text: import _partialRight from "lodash/partialRight";
  import _assign from "lodash/assign";
  
  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; }; }();
  
  function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  
  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; }
  
  import PropTypes from "prop-types";
  import React from "react";
  
  import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer, VictoryTheme, Line, TextSize, addEvents } from "victory-core";
  import AxisHelpers from "./helper-methods";
  import Axis from "../../helpers/axis";
  import { BaseProps } from "../../helpers/common-props";
  
  var fallbackProps = {
    width: 450,
    height: 300,
    padding: 50
  };
  
  var animationWhitelist = ["style", "domain", "range", "tickCount", "tickValues", "offsetX", "offsetY", "padding", "width", "height"];
  
  var options = {
    components: [{ name: "axis", index: 0 }, { name: "axisLabel", index: 0 }, { name: "grid" }, { name: "parent", index: "parent" }, { name: "ticks" }, { name: "tickLabels" }]
  };
  
  var VictoryAxis = function (_React$Component) {
    _inherits(VictoryAxis, _React$Component);
  
    function VictoryAxis() {
      _classCallCheck(this, VictoryAxis);
  
      return _possibleConstructorReturn(this, (VictoryAxis.__proto__ || Object.getPrototypeOf(VictoryAxis)).apply(this, arguments));
    }
  
    _createClass(VictoryAxis, [{
      key: "renderLine",
      value: function renderLine(props) {
        var axisComponent = props.axisComponent;
  
        var axisProps = this.getComponentProps(axisComponent, "axis", 0);
        return React.cloneElement(axisComponent, axisProps);
      }
    }, {
      key: "renderLabel",
      value: function renderLabel(props) {
        var axisLabelComponent = props.axisLabelComponent,
            label = props.label;
  
        if (!label) {
          return null;
        }
        var axisLabelProps = this.getComponentProps(axisLabelComponent, "axisLabel", 0);
        return React.cloneElement(axisLabelComponent, axisLabelProps);
      }
    }, {
      key: "renderGridAndTicks",
      value: function renderGridAndTicks(props) {
        var _this2 = this;
  
        var tickComponent = props.tickComponent,
            tickLabelComponent = props.tickLabelComponent,
            gridComponent = props.gridComponent;
  
  
        return this.dataKeys.map(function (key, index) {
          var tickProps = _this2.getComponentProps(tickComponent, "ticks", index);
          var TickComponent = React.cloneElement(tickComponent, tickProps);
          var gridProps = _this2.getComponentProps(gridComponent, "grid", index);
          var GridComponent = React.cloneElement(gridComponent, gridProps);
          var tickLabelProps = _this2.getComponentProps(tickLabelComponent, "tickLabels", index);
          var TickLabel = React.cloneElement(tickLabelComponent, tickLabelProps);
  
          return React.cloneElement(props.groupComponent, { key: "tick-group-" + key }, GridComponent, TickComponent, TickLabel);
        });
      }
    }, {
      key: "fixLabelOverlap",
      value: function fixLabelOverlap(gridAndTicks, props) {
        var isVertical = Helpers.isVertical(props);
        var size = isVertical ? props.height : props.width;
        var isVictoryLabel = function (child) {
          return child.type && child.type.role === "label";
        };
        var labels = gridAndTicks.map(function (gridAndTick) {
          return gridAndTick.props.children;
        }).reduce(function (accumulator, childArr) {
          return accumulator.concat(childArr);
        }).filter(isVictoryLabel).map(function (child) {
          return child.props;
        });
        var paddingToObject = function (padding) {
          return typeof padding === "object" ? _assign({}, { top: 0, right: 0, bottom: 0, left: 0 }, padding) : { top: padding, right: padding, bottom: padding, left: padding };
        };
        var labelsSumSize = labels.reduce(function (sum, label) {
          var padding = paddingToObject(label.style.padding);
          var labelSize = TextSize.approximateTextSize(label.text, {
            angle: label.angle,
            fontSize: label.style.fontSize,
            letterSpacing: label.style.letterSpacing,
            fontFamily: label.style.fontFamily
          });
          return sum + (isVertical ? labelSize.height + padding.top + padding.bottom : labelSize.width + padding.right + padding.left);
        }, 0);
        var availiableLabelCount = Math.floor(size * gridAndTicks.length / labelsSumSize);
        var divider = Math.ceil(gridAndTicks.length / availiableLabelCount) || 1;
        var getLabelCoord = function (gridAndTick) {
          return gridAndTick.props.children.filter(isVictoryLabel).reduce(function (prev, child) {
            return (isVertical ? child.props.y : child.props.x) || 0;
          }, 0);
        };
        var sorted = gridAndTicks.sort(function (a, b) {
          return isVertical ? getLabelCoord(b) - getLabelCoord(a) //ordinat axis has top-bottom orientation
          : getLabelCoord(a) - getLabelCoord(b);
        } //ordinat axis has left-right orientation
        );
        return sorted.filter(function (gridAndTick, index) {
          return index % divider === 0;
        });
      }
  
      // Overridden in native versions
  
    }, {
      key: "shouldAnimate",
      value: function shouldAnimate() {
        return !!this.props.animate;
      }
    }, {
      key: "render",
      value: function render() {
        var props = Helpers.modifyProps(this.props, fallbackProps, "axis");
        if (this.shouldAnimate()) {
          return this.animateComponent(props, animationWhitelist);
        }
  
        var gridAndTicks = this.renderGridAndTicks(props);
        var modifiedGridAndTicks = props.fixLabelOverlap ? this.fixLabelOverlap(gridAndTicks, props) : gridAndTicks;
        var children = [this.renderLine(props), this.renderLabel(props)].concat(_toConsumableArray(modifiedGridAndTicks));
        return props.standalone ? this.renderContainer(props.containerComponent, children) : React.cloneElement(props.groupComponent, {}, children);
      }
    }]);
  
    return VictoryAxis;
  }(React.Component);
  
  VictoryAxis.displayName = "VictoryAxis";
  VictoryAxis.role = "axis";
  VictoryAxis.defaultTransitions = {
    onExit: {
      duration: 500
    },
    onEnter: {
      duration: 500
    }
  };
  VictoryAxis.propTypes = _extends({}, BaseProps, {
    axisComponent: PropTypes.element,
    axisLabelComponent: PropTypes.element,
    crossAxis: PropTypes.bool,
    dependentAxis: PropTypes.bool,
    events: PropTypes.arrayOf(PropTypes.shape({
      target: PropTypes.oneOf(["axis", "axisLabel", "grid", "ticks", "tickLabels"]),
      eventKey: PropTypes.oneOfType([PropTypes.array, CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), PropTypes.string]),
      eventHandlers: PropTypes.object
    })),
    fixLabelOverlap: PropTypes.bool,
    gridComponent: PropTypes.element,
    groupComponent: PropTypes.element,
    label: PropTypes.any,
    offsetX: PropTypes.number,
    offsetY: PropTypes.number,
    orientation: PropTypes.oneOf(["top", "bottom", "left", "right"]),
    origin: PropTypes.shape({ x: PropTypes.number, y: PropTypes.number }),
    style: PropTypes.shape({
      parent: PropTypes.object, axis: PropTypes.object, axisLabel: PropTypes.object,
      grid: PropTypes.object, ticks: PropTypes.object, tickLabels: PropTypes.object
    }),
    tickComponent: PropTypes.element,
    tickCount: CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.greaterThanZero]),
    tickFormat: PropTypes.oneOfType([PropTypes.func, CustomPropTypes.homogeneousArray]),
    tickLabelComponent: PropTypes.element,
    tickValues: CustomPropTypes.homogeneousArray
  });
  VictoryAxis.defaultProps = {
    axisComponent: React.createElement(Line, { type: "axis" }),
    axisLabelComponent: React.createElement(VictoryLabel, null),
    tickLabelComponent: React.createElement(VictoryLabel, null),
    tickComponent: React.createElement(Line, { type: "tick" }),
    gridComponent: React.createElement(Line, { type: "grid" }),
    scale: "linear",
    standalone: true,
    theme: VictoryTheme.grayscale,
    tickCount: 5,
    containerComponent: React.createElement(VictoryContainer, null),
    groupComponent: React.createElement("g", { role: "presentation" }),
    fixLabelOverlap: false
  };
  VictoryAxis.getDomain = AxisHelpers.getDomain.bind(AxisHelpers);
  VictoryAxis.getAxis = Axis.getAxis.bind(Axis);
  VictoryAxis.getScale = AxisHelpers.getScale.bind(AxisHelpers);
  VictoryAxis.getStyles = _partialRight(AxisHelpers.getStyles.bind(AxisHelpers), fallbackProps.style);
  VictoryAxis.getBaseProps = _partialRight(AxisHelpers.getBaseProps.bind(AxisHelpers), fallbackProps);
  VictoryAxis.expectedComponents = ["axisComponent", "axisLabelComponent", "groupComponent", "containerComponent", "tickComponent", "tickLabelComponent", "gridComponent"];
  
  
  export default addEvents(VictoryAxis, options);