"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _react = _interopRequireWildcard(require("react"));
var _spin = _interopRequireDefault(require("antd/lib/spin"));
var _lodash = require("lodash");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var LineCharts = function LineCharts(_ref, ref) {
  var _ref$height = _ref.height,
    height = _ref$height === void 0 ? 280 : _ref$height,
    _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? 'light' : _ref$theme,
    legendData = _ref.legendData,
    _ref$yAxisList = _ref.yAxisList,
    yAxisList = _ref$yAxisList === void 0 ? [] : _ref$yAxisList,
    xAxisData = _ref.xAxisData,
    _ref$series = _ref.series,
    series = _ref$series === void 0 ? [] : _ref$series,
    _ref$grid = _ref.grid,
    grid = _ref$grid === void 0 ? {} : _ref$grid,
    _ref$loading = _ref.loading,
    loading = _ref$loading === void 0 ? false : _ref$loading,
    event$ = _ref.event$,
    onEvents = _ref.onEvents,
    visualMap = _ref.visualMap,
    _ref$legendOption = _ref.legendOption,
    legendOption = _ref$legendOption === void 0 ? {} : _ref$legendOption;
  var axisTextColor = theme === 'light' ? 'rgba(0, 0, 0, 0.6)' : '#fff';
  var echartRef = (0, _react.useRef)();
  var option = {
    grid: _objectSpread({
      top: '20%',
      left: '5%',
      right: '10%',
      bottom: '20%',
      containLabel: true
    }, grid),
    visualMap: visualMap,
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(data) {
        data.map(function (item) {
          event$ && event$.emit({
            dataIndex: item.dataIndex,
            seriesIndex: item.seriesIndex
          });
        });
        var circle = "<span style=\"display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:";
        var result = "".concat(data[0].name, "<br/>");
        data.map(function (item) {
          result += "".concat(circle + item.color, "\"></span>").concat(item.seriesName, "\uFF1A").concat((0, _lodash.isArray)(item.value) ? item.value[1] : item.value, "<br/>");
        });
        return result;
      }
    },
    legend: _objectSpread({
      left: 'center',
      top: 30,
      itemWidth: 18,
      itemHeight: 6,
      itemGap: 32,
      width: 900,
      type: 'scroll',
      textStyle: {
        color: theme === 'light' ? '#222' : '#fff',
        fontSize: 14
      },
      data: legendData
    }, legendOption),
    xAxis: {
      data: xAxisData,
      type: 'category',
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          fontSize: 12,
          color: axisTextColor //X轴文字颜色
        },
        formatter: function formatter(value) {
          return value.replace(' ', '\n');
        }
      }
    },
    yAxis: yAxisList.map(function (item) {
      return _objectSpread({
        type: 'value',
        nameTextStyle: {
          color: axisTextColor,
          fontSize: 12
        },
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          color: axisTextColor,
          fontSize: 14
        },
        splitLine: {
          show: true,
          lineStyle: {
            color: theme === 'light' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.20)',
            type: 'dashed'
          }
        }
      }, item);
    }),
    dataZoom: [{}],
    series: series
  };
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      echartRef: echartRef.current
    };
  });
  return loading ? /*#__PURE__*/_react["default"].createElement(_spin["default"], null) : /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    style: {
      width: '100%',
      height: height
    },
    option: option,
    lazyUpdate: true,
    notMerge: true,
    ref: echartRef,
    onEvents: onEvents
  });
};
var _default = exports["default"] = /*#__PURE__*/(0, _react.forwardRef)(LineCharts);
//# sourceMappingURL=index.js.map
