"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.LinePlot = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _plot = require("../../plot");

var _utils = require("../utils");

var _plot2 = _interopRequireDefault(require("./common/plot"));

var _shape = require("@vx/shape");

var _group = require("@vx/group");

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var CustomBarElement = function CustomBarElement(props) {
  var index = props.index,
      pointDiameter = props.pointDiameter,
      barX = props.barX,
      barWidth = props.barWidth,
      pointHeight = props.pointHeight,
      label = props.label,
      value = props.value,
      classes = props.classes,
      scale = props.scale;
  var x = barX + (barWidth - pointDiameter) / 2;
  var y = scale.y(index) - (pointHeight - pointDiameter) / 2;
  return /*#__PURE__*/_react["default"].createElement(_group.Group, null, /*#__PURE__*/_react["default"].createElement(_shape.LinePath, {
    data: [{
      x: x,
      y: y
    }, {
      x: x + pointDiameter,
      y: y - pointDiameter
    }],
    key: "point-".concat(label, "-").concat(value, "-").concat(index, "-1"),
    className: classes.line,
    x: function x(d) {
      return d.x;
    },
    y: function y(d) {
      return d.y;
    },
    strokeWidth: pointDiameter / 5
  }), /*#__PURE__*/_react["default"].createElement(_shape.LinePath, {
    data: [{
      x: x,
      y: y - pointDiameter
    }, {
      x: x + pointDiameter,
      y: y
    }],
    key: "point-".concat(label, "-").concat(value, "-").concat(index, "-2"),
    className: classes.line,
    x: function x(d) {
      return d.x;
    },
    y: function y(d) {
      return d.y;
    },
    strokeWidth: pointDiameter / 5
  }));
};

CustomBarElement.propTypes = {
  index: _propTypes["default"].number,
  pointDiameter: _propTypes["default"].number,
  barX: _propTypes["default"].number,
  barWidth: _propTypes["default"].number,
  pointHeight: _propTypes["default"].number,
  value: _propTypes["default"].number,
  label: _propTypes["default"].string,
  classes: _propTypes["default"].object,
  scale: _propTypes["default"].object
};

var LinePlot = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(LinePlot, _React$Component);

  var _super = _createSuper(LinePlot);

  function LinePlot() {
    (0, _classCallCheck2["default"])(this, LinePlot);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(LinePlot, [{
    key: "render",
    value: function render() {
      var props = this.props;
      var data = props.data,
          graphProps = props.graphProps;

      var _ref = graphProps || {},
          _ref$scale = _ref.scale,
          scale = _ref$scale === void 0 ? {} : _ref$scale,
          _ref$size = _ref.size,
          size = _ref$size === void 0 ? {} : _ref$size;

      var xBand = (0, _utils.dataToXBand)(scale.x, data, size.width, 'linePlot');
      return /*#__PURE__*/_react["default"].createElement(_plot2["default"], (0, _extends2["default"])({}, props, {
        xBand: xBand,
        CustomBarElement: CustomBarElement
      }));
    }
  }]);
  return LinePlot;
}(_react["default"].Component);

exports.LinePlot = LinePlot;
(0, _defineProperty2["default"])(LinePlot, "propTypes", {
  data: _propTypes["default"].array,
  onChange: _propTypes["default"].func,
  graphProps: _plot.types.GraphPropsType.isRequired
});

var _default = function _default() {
  return {
    type: 'linePlot',
    Component: LinePlot,
    name: 'Line Plot'
  };
};

exports["default"] = _default;
//# sourceMappingURL=line.js.map