text: "use strict";
  
  var _interopRequireWildcard = require("@babel/runtime/helpers/builtin/interopRequireWildcard");
  
  var _interopRequireDefault = require("@babel/runtime/helpers/builtin/interopRequireDefault");
  
  exports.__esModule = true;
  exports.getBackground = getBackground;
  exports.getXGuides = getXGuides;
  exports.getYGuides = getYGuides;
  exports.getXText = getXText;
  exports.getYText = getYText;
  exports.getBackgroundRenderData = getBackgroundRenderData;
  exports.default = ChartBackground;
  
  var _findLast2 = _interopRequireDefault(require("lodash/findLast"));
  
  var _compact2 = _interopRequireDefault(require("lodash/compact"));
  
  var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
  
  var _filter2 = _interopRequireDefault(require("lodash/filter"));
  
  var _sum2 = _interopRequireDefault(require("lodash/sum"));
  
  var _map2 = _interopRequireDefault(require("lodash/map"));
  
  var _includes2 = _interopRequireDefault(require("lodash/includes"));
  
  var React = _interopRequireWildcard(require("react"));
  
  var _propTypes = _interopRequireDefault(require("prop-types"));
  
  var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
  
  var _defaults = require("../chartCore/defaults");
  
  var _path2DUtils = require("../utils/path2DUtils");
  
  var _getForKey = require("../chartCore/getForKey");
  
  var _rectUtils = require("../utils/rectUtils");
  
  var _CanvasRender = _interopRequireDefault(require("../CanvasRender"));
  
  var _BottomLabel = _interopRequireDefault(require("./BottomLabel"));
  
  var _LeftLabel = _interopRequireDefault(require("./LeftLabel"));
  
  // Copyright 2018 Kensho Technologies, LLC.
  function getBackground(props) {
    if (props.backgroundShow === false) return undefined;
    var _props$backgroundOffs = props.backgroundOffset,
        backgroundOffset = _props$backgroundOffs === void 0 ? _defaults.BACKGROUND_OFFSET : _props$backgroundOffs,
        plotRect = props.plotRect,
        theme = props.theme;
    var backgroundRect = (0, _rectUtils.inset)(-backgroundOffset, plotRect);
    var backgroundPath = (0, _path2DUtils.getPath2D)();
    backgroundPath.rect(backgroundRect.x, backgroundRect.y, backgroundRect.width, backgroundRect.height);
    return {
      fill: theme.plotBackgroundFill,
      path2D: backgroundPath,
      stroke: 'transparent',
      type: 'area'
    };
  }
  
  function getXGuides(props, thick) {
    if (!(0, _includes2.default)(props.groupedKeys, 'x')) return undefined;
    if (props.xShowGuides === false) return undefined;
    var _props$backgroundOffs2 = props.backgroundOffset,
        backgroundOffset = _props$backgroundOffs2 === void 0 ? _defaults.BACKGROUND_OFFSET : _props$backgroundOffs2,
        plotRect = props.plotRect,
        theme = props.theme,
        xScale = props.xScale,
        xTicks = props.xTicks;
    return (0, _map2.default)(xTicks, function (d) {
      var linePath = (0, _path2DUtils.getPath2D)();
      var x = xScale(d.value);
      linePath.moveTo(x, plotRect.y - backgroundOffset);
      linePath.lineTo(x, plotRect.y + plotRect.height + backgroundOffset);
      return {
        path2D: linePath,
        type: 'line',
        lineWidth: thick ? theme.guideZeroLineWidth : theme.guideLineWidth,
        stroke: thick ? theme.guideZeroStroke : theme.guideStroke
      };
    });
  }
  
  function getYGuides(props, thick) {
    if (!(0, _includes2.default)(props.groupedKeys, 'y')) return undefined;
    if (props.yShowGuides === false) return undefined;
    var _props$backgroundOffs3 = props.backgroundOffset,
        backgroundOffset = _props$backgroundOffs3 === void 0 ? _defaults.BACKGROUND_OFFSET : _props$backgroundOffs3,
        plotRect = props.plotRect,
        theme = props.theme,
        yScale = props.yScale,
        yTicks = props.yTicks;
    return (0, _map2.default)(yTicks, function (d) {
      var linePath = (0, _path2DUtils.getPath2D)();
      var y = yScale(d.value);
      linePath.moveTo(plotRect.x - backgroundOffset, y);
      linePath.lineTo(plotRect.x + plotRect.width + backgroundOffset, y);
      return {
        path2D: linePath,
        type: 'line',
        lineWidth: thick ? theme.guideZeroLineWidth : theme.guideLineWidth,
        stroke: thick ? theme.guideZeroStroke : theme.guideStroke
      };
    });
  }
  
  function getXText(props) {
    if (!(0, _includes2.default)(props.groupedKeys, 'x')) return undefined;
    if (props.xShowTicks === false) return undefined;
    var theme = props.theme;
    var defaultOffset = theme.axisTickFontSize * (theme.lineHeight - 1);
    var _props$backgroundOffs4 = props.backgroundOffset,
        backgroundOffset = _props$backgroundOffs4 === void 0 ? _defaults.BACKGROUND_OFFSET : _props$backgroundOffs4,
        plotRect = props.plotRect,
        xScale = props.xScale,
        _props$xTickOffset = props.xTickOffset,
        xTickOffset = _props$xTickOffset === void 0 ? defaultOffset : _props$xTickOffset,
        xTicks = props.xTicks;
    return (0, _map2.default)(xTicks, function (d) {
      return {
        type: 'text',
        text: d.text,
        x: xScale(d.value),
        y: (0, _sum2.default)([backgroundOffset, plotRect.y, plotRect.height, xTickOffset]),
        textBaseline: 'top',
        textAlign: 'center',
        font: theme.axisTickFontSize + "px " + theme.fontFamilyMono
      };
    });
  }
  
  function getYText(props) {
    if (!(0, _includes2.default)(props.groupedKeys, 'y')) return undefined;
    if (props.yShowTicks === false) return undefined;
    var theme = props.theme;
    var defaultOffset = theme.axisTickFontSize * (theme.lineHeight - 1);
    var _props$backgroundOffs5 = props.backgroundOffset,
        backgroundOffset = _props$backgroundOffs5 === void 0 ? _defaults.BACKGROUND_OFFSET : _props$backgroundOffs5,
        plotRect = props.plotRect,
        yScale = props.yScale,
        _props$yTickOffset = props.yTickOffset,
        yTickOffset = _props$yTickOffset === void 0 ? defaultOffset : _props$yTickOffset,
        yTicks = props.yTicks;
    return (0, _map2.default)(yTicks, function (d) {
      return {
        type: 'text',
        text: d.text,
        x: (0, _sum2.default)([plotRect.x, -backgroundOffset, -yTickOffset]),
        y: yScale(d.value),
        textAlign: 'right',
        textBaseline: 'middle',
        fill: theme.textFill,
        font: theme.axisTickFontSize + "px " + theme.fontFamilyMono
      };
    });
  }
  
  function getBackgroundRenderData(props) {
    var background = getBackground(props);
    var xTicks = props.xTicks || (0, _getForKey.getTicks)(props, 'x');
    var yTicks = props.yTicks || (0, _getForKey.getTicks)(props, 'y');
    var xGuides = getXGuides(Object.assign({}, props, {
      xTicks: xTicks
    }));
    var yGuides = getYGuides(Object.assign({}, props, {
      yTicks: yTicks
    }));
    var xText = getXText(Object.assign({}, props, {
      xTicks: xTicks
    }));
    var yText = getYText(Object.assign({}, props, {
      yTicks: yTicks
    }));
    var thickXGuide = getXGuides(Object.assign({}, props, {
      xTicks: (0, _filter2.default)(xTicks, function (d) {
        return d.value === 0;
      })
    }), true);
    var thickYGuide = getYGuides(Object.assign({}, props, {
      yTicks: (0, _filter2.default)(yTicks, function (d) {
        return d.value === 0;
      })
    }), true);
    return (0, _flatten2.default)((0, _compact2.default)([background, xGuides, yGuides, thickXGuide, thickYGuide, xText, yText]));
  }
  
  function getLabelText(props, key) {
    var text = props[key + "Name"] || props[key];
    if (text) return text;
    var layer = (0, _findLast2.default)(props.layers, function (d) {
      return d[key + "Name"] || d[key];
    });
    if (layer) return layer[key + "Name"] || layer[key];
    return undefined;
  }
  
  function ChartBackground(props) {
    return React.createElement("div", null, React.createElement(_CanvasRender.default, {
      height: props.height,
      plotRect: props.plotRect,
      renderData: getBackgroundRenderData(props),
      theme: props.theme,
      width: props.width
    }), props.yShowLabel ? React.createElement(_LeftLabel.default, {
      plotRect: props.plotRect,
      text: getLabelText(props, 'y'),
      theme: props.theme
    }) : null, props.xShowLabel ? React.createElement(_BottomLabel.default, {
      plotRect: props.plotRect,
      text: getLabelText(props, 'x'),
      theme: props.theme
    }) : null);
  }
  
  ChartBackground.propTypes = process.env.NODE_ENV !== "production" ? {
    height: _propTypes.default.number,
    onUpdate: _propTypes.default.func,
    plotRect: _propTypes.default.object,
    theme: _propTypes.default.object,
    width: _propTypes.default.number,
    x: _propTypes.default.string,
    xName: _propTypes.default.string,
    xShowLabel: _propTypes.default.bool,
    y: _propTypes.default.string,
    yName: _propTypes.default.string,
    yShowLabel: _propTypes.default.bool
  } : {};
  ChartBackground.defaultProps = {
    theme: _defaultTheme.default,
    xShowLabel: true,
    yShowLabel: true
  };