'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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; }; }();

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

var _d3Axis = require('d3-axis');

var axis = _interopRequireWildcard(_d3Axis);

var _d3Selection = require('d3-selection');

var selection = _interopRequireWildcard(_d3Selection);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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; }

var d3 = Object.assign({}, axis, selection);

var func = _propTypes2.default.func,
    oneOf = _propTypes2.default.oneOf,
    number = _propTypes2.default.number,
    string = _propTypes2.default.string;

var Axis = function (_React$Component) {
  _inherits(Axis, _React$Component);

  function Axis(props) {
    _classCallCheck(this, Axis);

    var _this = _possibleConstructorReturn(this, (Axis.__proto__ || Object.getPrototypeOf(Axis)).call(this, props));

    _this.renderAxis = _this.renderAxis.bind(_this);
    return _this;
  }

  _createClass(Axis, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.renderAxis();
    }
  }, {
    key: 'componentDidUpdate',
    value: function componentDidUpdate() {
      this.renderAxis();
    }
  }, {
    key: 'getTranslate',
    value: function getTranslate() {
      var _props = this.props,
          orientation = _props.orientation,
          height = _props.height,
          width = _props.width,
          zero = _props.zero;


      if (orientation === 'top') {
        return 'translate(0, ' + zero + ')';
      } else if (orientation === 'bottom') {
        return 'translate(15, ' + (zero === 0 ? height - 25 : zero) + ')';
      } else if (orientation === 'left') {
        return 'translate(' + zero + ', 0)';
      } else if (orientation === 'right') {
        return 'translate(' + (zero === 0 ? width : zero) + ', 0)';
      }
      return '';
    }
  }, {
    key: 'renderAxis',
    value: function renderAxis() {
      var node = _reactDom2.default.findDOMNode(this);
      d3.select(node).call(this.props.axis);
    }
  }, {
    key: 'render',
    value: function render() {
      var translate = this.getTranslate();
      return _react2.default.createElement('g', {
        className: this.props.className,
        transform: translate,
        width: this.props.width
      });
    }
  }]);

  return Axis;
}(_react2.default.Component);

Axis.propTypes = {
  className: string,
  height: number,
  width: number,
  orientation: oneOf(['top', 'bottom', 'left', 'right']).isRequired,
  zero: number,
  axisType: oneOf(['x', 'y']),
  axis: func.isRequired
};

Axis.defaultProps = {
  className: 'axis',
  zero: 0,
  width: 1
};

exports.default = Axis;
//# sourceMappingURL=Axis.js.map