"use strict";

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

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

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 _styles = require("@material-ui/core/styles");

var _classnames = _interopRequireDefault(require("classnames"));

var _grid = require("@vx/grid");

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

var _renderUi = require("../render-ui");

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 Grid = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(Grid, _React$Component);

  var _super = _createSuper(Grid);

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

  (0, _createClass2["default"])(Grid, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          classes = _this$props.classes,
          className = _this$props.className,
          graphProps = _this$props.graphProps,
          xBand = _this$props.xBand,
          rowTickValues = _this$props.rowTickValues,
          columnTickValues = _this$props.columnTickValues;

      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,
          _ref$range = _ref.range,
          range = _ref$range === void 0 ? {} : _ref$range;

      var _range$step = range.step,
          step = _range$step === void 0 ? 0 : _range$step,
          _range$labelStep = range.labelStep,
          labelStep = _range$labelStep === void 0 ? 0 : _range$labelStep;
      var highlightNonLabel = step && labelStep && step < labelStep; // if highlightNonLabel is true, we need to separate the unlabled lines in order to render them in a different color

      var _reduce = (rowTickValues || []).reduce(function (acc, value) {
        if (highlightNonLabel && value % labelStep !== 0) {
          acc.unlabeledLines.push(value);
        } else {
          acc.labeledLines.push(value);
        }

        return acc;
      }, {
        unlabeledLines: [],
        labeledLines: []
      }),
          unlabeledLines = _reduce.unlabeledLines,
          labeledLines = _reduce.labeledLines;

      return /*#__PURE__*/_react["default"].createElement("g", {
        className: (0, _classnames["default"])(classes.grid, className)
      }, /*#__PURE__*/_react["default"].createElement(_grid.GridRows, {
        scale: scale.y,
        width: size.width,
        tickValues: unlabeledLines,
        lineStyle: {
          stroke: _renderUi.color.fadedPrimary(),
          strokeWidth: 1
        }
      }), /*#__PURE__*/_react["default"].createElement(_grid.GridRows, {
        scale: scale.y,
        width: size.width,
        tickValues: labeledLines,
        lineStyle: {
          stroke: _renderUi.color.visualElementsColors.GRIDLINES_COLOR,
          strokeWidth: 1
        }
      }), /*#__PURE__*/_react["default"].createElement(_grid.GridColumns, {
        scale: xBand,
        height: size.height,
        offset: xBand.bandwidth() / 2,
        tickValues: columnTickValues
      }));
    }
  }]);
  return Grid;
}(_react["default"].Component);

exports.Grid = Grid;
(0, _defineProperty2["default"])(Grid, "propTypes", {
  classes: _propTypes["default"].object.isRequired,
  className: _propTypes["default"].string,
  graphProps: _plot.types.GraphPropsType.isRequired,
  xBand: _propTypes["default"].func,
  columnTickValues: _propTypes["default"].array,
  rowTickValues: _propTypes["default"].array
});
(0, _defineProperty2["default"])(Grid, "defaultProps", {});

var styles = function styles() {
  return {
    grid: {
      stroke: _renderUi.color.primaryLight()
    }
  };
};

var _default = (0, _styles.withStyles)(styles)(Grid);

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