"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.numberTo = exports.mergeXAxisAndData = exports.mergeSeriesAndData = exports.mergeConfigAndData = exports.getColor = exports["default"] = exports.convertPieData = exports.convertDecimal = void 0;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _antd = require("antd");
var _excluded = ["data"],
  _excluded2 = ["name", "nameTextStyle"],
  _excluded3 = ["name", "data"],
  _excluded4 = ["name", "data", "type"],
  _excluded5 = ["name", "data", "type"],
  _excluded6 = ["name", "data", "type", "lingColor"],
  _excluded7 = ["type", "color", "barLabelConfig"],
  _excluded8 = ["name", "data"],
  _excluded9 = ["name", "data"],
  _excluded10 = ["data", "onEvents", "color", "legend", "unit", "tooltip", "grid", "xAxis", "yAxis", "height", "series", "loading", "title", "dataZoom", "noDataText", "style", "imgStyle", "noDataStyle"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
var color = '#86909C';
var fontSize = '12px';

/**
 * 小数处理，默认2位
 * @param value
 * @param len
 * @returns {number|*}
 */
var convertDecimal = exports.convertDecimal = function convertDecimal(value) {
  var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
  if (value && String(value).indexOf('.') !== -1) {
    var _String$split = String(value).split('.'),
      _String$split2 = _slicedToArray(_String$split, 2),
      start = _String$split2[0],
      end = _String$split2[1];
    if (String(end).length > len) {
      end = end.substring(0, len);
    }
    return Number("".concat(start, ".").concat(end));
  }
  return value;
};

/**
 * 转换饼图数据，处理占比截取为默认2位小数
 * @param data
 * @returns {*[]}
 */
var convertPieData = exports.convertPieData = function convertPieData(data) {
  var _data2;
  var _data = [];
  if ((_data2 = data) !== null && _data2 !== void 0 && _data2.length) {
    data = data.filter(function (v) {
      return Number(v.value);
    });
    var total = 0;
    data.map(function (v) {
      if (v.value) {
        total += Number(v.value);
      }
    });
    data.map(function (v) {
      var value = v.value;
      var rate = (value || 0) / total * 100 || 0;
      rate = convertDecimal(rate);
      _data.push(_objectSpread(_objectSpread({}, v), {}, {
        rate: rate
      }));
    });
  }
  return _data;
};

/**
 * 合并 xAxis 配置及数据
 * @param xAxis
 * @param data
 * @returns {*&{data: *[]}}
 */
var mergeXAxisAndData = exports.mergeXAxisAndData = function mergeXAxisAndData(xAxis, data) {
  var times = [];
  if (data !== null && data !== void 0 && data.length) {
    var field = xAxis.field,
      format = xAxis.format;
    if (field) {
      data.map(function (v) {
        var time = field ? v[field] : v;
        times.push(time);
      });
    }
  }
  return _objectSpread({
    data: times
  }, xAxis);
};
var numberTo = exports.numberTo = function numberTo(data, number, limit) {
  if (number) {
    return (Number(data) / number).toFixed(limit || 2);
  }
  return data;
};

/**
 * 合并 series 和数据
 * @param series
 * @param data
 * @returns {*[]}
 */
var mergeSeriesAndData = exports.mergeSeriesAndData = function mergeSeriesAndData(series, data) {
  var _series = [];
  series.map(function (s) {
    var seriesItem = _objectSpread({}, s);
    if (data !== null && data !== void 0 && data.length && s.field) {
      seriesItem.data = [];
      data.map(function (v) {
        seriesItem.data.push(numberTo(v[s.field], s.numberTo));
      });
    }
    _series.push(seriesItem);
  });
  return _series;
};

/**
 * 合并配置和数据
 * @param options
 * @returns {{}}
 */
var mergeConfigAndData = exports.mergeConfigAndData = function mergeConfigAndData(options) {
  var xAxis = options.xAxis,
    yAxis = options.yAxis,
    series = options.series,
    data = options.data;
  var val = {};
  if (!(data && (data.length || Object.keys(data).length))) {
    return options;
  }
  if (yAxis !== null && yAxis !== void 0 && yAxis.field) {
    val.yAxis = mergeXAxisAndData(yAxis, data);
  }
  if (xAxis !== null && xAxis !== void 0 && xAxis.field) {
    val.xAxis = mergeXAxisAndData(xAxis, data);
  }
  if (series !== null && series !== void 0 && series.length) {
    val.series = mergeSeriesAndData(series, data);
  }
  return _objectSpread(_objectSpread({}, options), val);
};
var getUnit = function getUnit(units, name) {
  if (units && _typeof(units) === 'object') {
    if (Array.isArray(units)) {
      var _units$filter$;
      return (_units$filter$ = units.filter(function (item) {
        return item.name === name;
      })[0]) === null || _units$filter$ === void 0 ? void 0 : _units$filter$.value;
    } else {
      return (units === null || units === void 0 ? void 0 : units[name]) || '';
    }
  }
  return units || '';
};
/**
 * 获取 tooltip
 * @param options
 * @returns {*&{trigger: string}}
 */
var getTooltip = function getTooltip(options, unit, series) {
  var _series$;
  return _objectSpread({
    trigger: ((_series$ = series[0]) === null || _series$ === void 0 ? void 0 : _series$.type) === 'pie' ? 'item' : 'axis',
    confine: true,
    // 限制在图表区域里
    borderWidth: 0,
    formatter: function formatter(params) {
      var _series$2;
      if (((_series$2 = series[0]) === null || _series$2 === void 0 ? void 0 : _series$2.type) === 'pie') {
        var currentUnit = getUnit(unit, params.name);
        return "".concat(params.name, "\uFF1A").concat(params.value).concat(currentUnit);
      }
      var res = params[0].name;
      for (var i = 0; i < params.length; i++) {
        var _currentUnit = getUnit(unit, params[i].seriesName);
        res += "<br>".concat(params[i].marker).concat(params[i].seriesName, "\uFF1A").concat(params[i].value).concat(_currentUnit);
      }
      return res;
    }
  }, options);
};

/**
 * 获取 图例
 * @param options
 * @returns {*&{pageTextStyle: {color: string}, textStyle: {color: string}, type: string, pageIconInactiveColor: string, pageIconColor: string}}
 */
var getLegend = function getLegend(options) {
  return _objectSpread({
    type: 'scroll',
    left: 'center',
    itemGap: 12
  }, options);
};

/**
 * 获取布局
 * @param grid
 * @param dataZoom
 * @returns {*&{top: string, left: number, bottom: string, right: number, containLabel: boolean}}
 */
var getGrid = function getGrid(grid, dataZoom) {
  return _objectSpread({
    left: 5,
    right: 5,
    top: 35,
    bottom: dataZoom !== null && dataZoom !== void 0 && dataZoom.show ? 30 : 10,
    containLabel: true
  }, grid);
};

/**
 * 获取 xAxis 单项
 * @param options 参数可以是: "[xx, xx]"、"{data: [xx, xx], ...}"
 * @returns {{axisLabel: {textStyle: {color: string}}, data: *, axisLine: {lineStyle: {color: string}}, axisTick: {show: boolean}, type: string, boundaryGap: boolean}}
 */
var getXAxisItem = function getXAxisItem(options) {
  var _ref = Array.isArray(options) ? {
      data: options
    } : options,
    data = _ref.data,
    other = _objectWithoutProperties(_ref, _excluded);
  return _objectSpread({
    type: 'category',
    boundaryGap: true,
    // false 从0开始
    axisTick: {
      show: false
    },
    axisLabel: {
      textStyle: {
        fontSize: fontSize,
        color: color
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        type: [3, 3],
        dashOffset: 3,
        color: '#E5E6EB'
      }
    },
    data: data
  }, other);
};

/**
 * 获取 xAxis 配置
 * @param xAxis 参数说明："[xx, xx]"、"[[xx, xx], [xx, xx]]"、"[{data: [xx, xx], ...}]"
 * @returns {(*&{axisLabel: {textStyle: {color: string}}, data, axisLine: {lineStyle: {color: string}}, axisTick: {show: boolean}, type: string, boundaryGap: boolean})|*[]}
 */
var getXAxis = function getXAxis(xAxis) {
  if (xAxis) {
    if (_typeof(xAxis[0]) === 'object') {
      var _xAxis = [];
      _xAxis.map(function (v) {
        _xAxis.push(getXAxisItem(v));
      });
      return _xAxis;
    }
    return getXAxisItem(xAxis);
  }
  return {
    show: false
  };
};

/**
 * 获取单个 yAxis 配置
 * @param options 参数可以是："xx"、"{name: 'xx', ...其他配置}"
 * @returns {{axisLabel: {textStyle: {color: string}, showMaxLabel: boolean}, axisLine: {lineStyle: {color: string}}, axisTick: {show: boolean}, splitLine: {show: boolean}, nameTextStyle: {color: string}}}
 */
var getYAxisItem = function getYAxisItem(options) {
  options = options || {};
  var _ref2 = typeof options === 'string' ? {
      name: options
    } : options,
    name = _ref2.name,
    nameTextStyle = _ref2.nameTextStyle,
    other = _objectWithoutProperties(_ref2, _excluded2);
  return _objectSpread({
    name: name,
    axisLabel: {
      textStyle: {
        color: color,
        fontSize: fontSize
      }
    },
    axisLine: {
      show: false,
      lineStyle: {
        color: '#E5E6EB',
        width: 1
      }
    },
    axisTick: {
      show: false
    },
    splitLine: {
      show: true,
      lineStyle: {
        type: [3, 3],
        dashOffset: 3,
        color: '#E5E6EB'
      }
    },
    nameTextStyle: _objectSpread({
      fontSize: fontSize,
      color: color
    }, nameTextStyle)
  }, other);
};

/**
 * 获取 yAxis 配置
 * @param yAxis 参数可以是: "xx"、"['xx', 'xxx']"、"[{name: 'xx', ...其他配置}]"
 * @returns {{axisLabel: {textStyle: {color: string}, showMaxLabel: boolean}, axisLine: {lineStyle: {color: string}}, axisTick: {show: boolean}, splitLine: {show: boolean}, nameTextStyle: {color: string}}|*[]}
 */
var getYAxis = function getYAxis(yAxis) {
  if (yAxis) {
    if (Array.isArray(yAxis)) {
      var _yAxis = [];
      yAxis.map(function (v, i) {
        var options = typeof v === 'string' ? {
          name: v
        } : v;
        _yAxis.push(getYAxisItem(_objectSpread({
          nameTextStyle: {
            padding: i === 0 ? [0, 30, 0, 0] : [0, 0, 0, 30]
          }
        }, options)));
      });
      return _yAxis;
    }
    return getYAxisItem(yAxis);
  }
  return {
    show: false
  };
};

/**
 * 获取 折线图 数据项
 * @param name
 * @param data
 * @param other
 * @returns {*&{connectNulls: boolean, data, symbolSize: number, name, type: string, smooth: boolean}}
 */
var getLineSeries = function getLineSeries(_ref3) {
  var name = _ref3.name,
    data = _ref3.data,
    other = _objectWithoutProperties(_ref3, _excluded3);
  return _objectSpread({
    type: 'line',
    symbol: 'circle',
    symbolSize: 0,
    smooth: true,
    connectNulls: true,
    name: name,
    data: data
  }, other);
};

/**
 * 获取 柱状图 数据项
 * @param name
 * @param data
 * @param other
 * @returns {*&{barMaxWidth: number, connectNulls: boolean, data, barMinWidth: number, name, type: string}}
 */
var getBarSeries = function getBarSeries(_ref4) {
  var name = _ref4.name,
    data = _ref4.data,
    type = _ref4.type,
    other = _objectWithoutProperties(_ref4, _excluded4);
  // 特殊样式处理
  return _objectSpread({
    type: 'bar',
    symbol: 'circle',
    barMaxWidth: 20,
    barMinWidth: 5,
    connectNulls: true,
    name: name,
    data: data
  }, other);
};
var getPictorialBar = function getPictorialBar(_ref5) {
  var name = _ref5.name,
    data = _ref5.data,
    type = _ref5.type,
    other = _objectWithoutProperties(_ref5, _excluded5);
  return _objectSpread({
    type: 'pictorialBar',
    name: name,
    data: data
  }, other);
};
var getLingBarSeries = function getLingBarSeries(_ref6) {
  var name = _ref6.name,
    data = _ref6.data,
    type = _ref6.type,
    lingColor = _ref6.lingColor,
    other = _objectWithoutProperties(_ref6, _excluded6);
  return [_objectSpread({
    type: 'bar',
    barWidth: 20,
    name: name,
    data: data
  }, other), {
    name: name,
    data: data,
    type: 'pictorialBar',
    barMaxWidth: 10,
    symbol: 'diamond',
    symbolOffset: [0, '50%'],
    symbolSize: [20, 10],
    itemStyle: {
      color: getColor(lingColor || other.color)
    },
    silent: true,
    // 图形是否不响应和触发鼠标事件，默认为 false，即响应和触发鼠标事件。
    tooltip: {
      show: false
    },
    legend: {
      show: false
    },
    zlevel: 2
  }, {
    name: name,
    data: data,
    type: 'pictorialBar',
    barMaxWidth: 10,
    symbolPosition: 'end',
    symbol: 'diamond',
    symbolOffset: [0, '-50%'],
    symbolSize: [20, 10],
    itemStyle: {
      color: getColor(lingColor || other.color)
    },
    silent: true,
    // 图形是否不响应和触发鼠标事件，默认为 false，即响应和触发鼠标事件。
    tooltip: {
      show: false
    },
    legend: {
      show: false
    },
    zlevel: 2
  }];
};
var getNailBarSeries = function getNailBarSeries(_ref7) {
  var type = _ref7.type,
    color = _ref7.color,
    barLabelConfig = _ref7.barLabelConfig,
    other = _objectWithoutProperties(_ref7, _excluded7);
  var _color = Array.isArray(color) ? color : [color, color];
  return _objectSpread({
    type: 'bar',
    barWidth: 16,
    label: _objectSpread({
      show: true,
      formatter: function formatter() {
        return '';
      },
      position: 'top',
      offset: [0, 4],
      // 相对于数据点的偏移量，[水平偏移, 垂直偏移]
      shadowColor: _color[0],
      backgroundColor: _color[0],
      shadowBlur: 10,
      width: 20,
      height: 4
    }, barLabelConfig),
    name: name,
    color: color
  }, other);
};
var getWordCloudSeries = function getWordCloudSeries(_ref8) {
  var name = _ref8.name,
    data = _ref8.data;
  return [{
    // name,
    type: 'wordCloud',
    //size: ['9%', '99%'],
    sizeRange: [14, 50],
    //textRotation: [0, 45, 90, -45],
    rotationRange: [-45, 90],
    shape: 'circle',
    textPadding: 0,
    width: '100%',
    // 画布高
    height: '100%',
    autoSize: {
      enable: true,
      minSize: 6
    },
    textStyle: {
      normal: {
        color: function color() {
          return "rgb(".concat(Math.round(Math.random() * 256), ",").concat(Math.round(Math.random() * 256), ",").concat(Math.round(Math.random() * 256), ")");
        }
      },
      emphasis: {
        shadowBlur: 2,
        shadowColor: '#333'
      }
    },
    data: data
  }];
};

/**
 * 获取 饼图 数据项
 * @param name
 * @param data
 * @param other
 * @returns {*&{connectNulls: boolean, data, symbolSize: number, name, type: string, smooth: boolean}}
 */
var getPieSeries = function getPieSeries(_ref9) {
  var name = _ref9.name,
    data = _ref9.data,
    other = _objectWithoutProperties(_ref9, _excluded8);
  return _objectSpread({
    type: 'pie',
    name: name,
    data: data
  }, other);
};

/**
 * 获取 散点图 数据项
 * @param name
 * @param data
 * @param other
 * @returns {*&{connectNulls: boolean, data, symbolSize: number, name, type: string, smooth: boolean}}
 */
var getScatterSeries = function getScatterSeries(_ref10) {
  var name = _ref10.name,
    data = _ref10.data,
    other = _objectWithoutProperties(_ref10, _excluded9);
  return _objectSpread({
    type: 'scatter',
    name: name,
    data: data
  }, other);
};

/**
 * 获取颜色
 * @param color 参数可为："#xxx", "['#xxx', '#xxx]"
 * @returns {string|{x: number, y: number, y2: number, x2: number, global: boolean, colorStops: *[], type: string}}
 */
var getColor = exports.getColor = function getColor(color) {
  if (typeof color === 'string') {
    return color;
  } else if (Array.isArray(color)) {
    var colorStops = [];
    color.map(function (c, i) {
      if (typeof c === 'string') {
        colorStops.push({
          offset: i,
          color: color[i] // 0% 处的颜色
        });
      } else {
        colorStops.push(_objectSpread({
          offset: i,
          color: c.color
        }, c));
      }
    });
    return {
      type: 'linear',
      x: 0,
      y: 0,
      x2: 0,
      y2: 1,
      colorStops: colorStops,
      global: false // 缺省为 false
    };
  }
};

/**
 * 获取区间渐变颜色
 * @param color 参数可为："#xxx", "['#xxx', '#xxx]"
 * @returns {{color: {x: number, y: number, y2: number, globalCoord: boolean, x2: number, colorStops: [{offset: number, color: string},{offset: number, color: string}], type: string}}}
 */
var getAreaColor = function getAreaColor(color) {
  var _ref11 = typeof color === 'string' ? [color, color] : color,
    _ref12 = _slicedToArray(_ref11, 2),
    start = _ref12[0],
    end = _ref12[1];
  return {
    color: {
      type: 'linear',
      x: 0,
      y: 0,
      x2: 0,
      y2: 1,
      colorStops: [{
        offset: 0,
        color: start
      } /*0% 处的颜色*/, {
        offset: 1,
        color: end
      } /* 100% 处的颜色*/],
      globalCoord: false // 缺省为 false
    }
  };
};

/**
 * 获取数据
 * @param series 参数："{name, data, type, color, areaColor}"
 * @returns {*[]}
 */
var getSeries = function getSeries(series) {
  var _series = [];
  var FUN_MAP = {
    nailBar: getNailBarSeries,
    // 钉子柱状图
    bar: getBarSeries,
    // 柱状图
    lingBar: getLingBarSeries,
    // 立体柱状图
    line: getLineSeries,
    // 折线图
    pie: getPieSeries,
    // 饼图
    scatter: getScatterSeries,
    //散点图
    pictorialBar: getPictorialBar,
    // 自定义样式的柱状图
    wordCloud: getWordCloudSeries // 词云图
  };
  series.map(function (v) {
    var type = v.type,
      color = v.color,
      areaColor = v.areaColor;
    if (type === 'nailBar') {
      color = color || ['rgba(88,139,240,0.6)', 'rgba(138,177,255,0.2)'];
    }
    var _seriesItem;
    if (FUN_MAP[type]) {
      _seriesItem = FUN_MAP[type](v);
    } else {
      //其他类型
      _seriesItem = v;
    }
    // 自身颜色
    if (color) {
      if (Array.isArray(_seriesItem)) {
        _seriesItem[0].itemStyle = _seriesItem[0].itemStyle || {};
        _seriesItem[0].itemStyle.color = getColor(color);
      } else {
        _seriesItem.itemStyle = _seriesItem.itemStyle || {};
        _seriesItem.itemStyle.color = getColor(color);
      }
    }

    // 区间颜色
    if (areaColor && areaColor.length) {
      _seriesItem.areaStyle = getAreaColor(areaColor);
    }
    if (Array.isArray(_seriesItem)) {
      _series.push.apply(_series, _toConsumableArray(_seriesItem));
    } else {
      _series.push(_seriesItem);
    }
  });
  return _series;
};
var getDataZoom = function getDataZoom(options) {
  var _dataZoom = [];
  if (options !== null && options !== void 0 && options.show) {
    _dataZoom = options !== null && options !== void 0 && options.otherDataZoom ? options.otherDataZoom : [{
      type: 'slider',
      filterMode: 'none',
      height: 10,
      textStyle: {
        opacity: 0
      },
      startValue: 0,
      // 开始的值
      endValue: 100,
      //  结束的值
      bottom: 10
    }, {
      type: 'inside',
      filterMode: 'none',
      height: 10,
      textStyle: {
        opacity: 0
      }
    }];
  }
  return _dataZoom;
};
var Chart = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var _option$series;
  var _mergeConfigAndData = mergeConfigAndData(props || {}),
    data = _mergeConfigAndData.data,
    onEvents = _mergeConfigAndData.onEvents,
    color = _mergeConfigAndData.color,
    legend = _mergeConfigAndData.legend,
    _mergeConfigAndData$u = _mergeConfigAndData.unit,
    unit = _mergeConfigAndData$u === void 0 ? '' : _mergeConfigAndData$u,
    tooltip = _mergeConfigAndData.tooltip,
    grid = _mergeConfigAndData.grid,
    xAxis = _mergeConfigAndData.xAxis,
    yAxis = _mergeConfigAndData.yAxis,
    _mergeConfigAndData$h = _mergeConfigAndData.height,
    height = _mergeConfigAndData$h === void 0 ? '100%' : _mergeConfigAndData$h,
    series = _mergeConfigAndData.series,
    _mergeConfigAndData$l = _mergeConfigAndData.loading,
    loading = _mergeConfigAndData$l === void 0 ? false : _mergeConfigAndData$l,
    title = _mergeConfigAndData.title,
    dataZoom = _mergeConfigAndData.dataZoom,
    noDataText = _mergeConfigAndData.noDataText,
    _mergeConfigAndData$s = _mergeConfigAndData.style,
    style = _mergeConfigAndData$s === void 0 ? {} : _mergeConfigAndData$s,
    _mergeConfigAndData$i = _mergeConfigAndData.imgStyle,
    imgStyle = _mergeConfigAndData$i === void 0 ? {} : _mergeConfigAndData$i,
    _mergeConfigAndData$n = _mergeConfigAndData.noDataStyle,
    noDataStyle = _mergeConfigAndData$n === void 0 ? {} : _mergeConfigAndData$n,
    other = _objectWithoutProperties(_mergeConfigAndData, _excluded10);
  var option = _objectSpread({
    title: title,
    legend: getLegend(legend),
    tooltip: getTooltip(tooltip, unit || (typeof yAxis === 'string' ? yAxis : ''), series),
    grid: getGrid(grid, dataZoom),
    xAxis: getXAxis(xAxis),
    yAxis: getYAxis(yAxis),
    series: getSeries(series),
    dataZoom: getDataZoom(dataZoom)
  }, other);
  if (color) {
    option.color = color;
  }
  var chartRef = (0, _react.useRef)({});
  (0, _react.useImperativeHandle)(ref, function () {
    return _objectSpread({}, chartRef.current);
  });

  // 解决 echarts 点击空白地方不生效的问题
  var onClick = function onClick(e) {
    if (onEvents !== null && onEvents !== void 0 && onEvents.onClick) {
      var _chartRef$current, _chartRef$current$get;
      var chart = (_chartRef$current = chartRef.current) === null || _chartRef$current === void 0 || (_chartRef$current$get = _chartRef$current.getEchartsInstance) === null || _chartRef$current$get === void 0 ? void 0 : _chartRef$current$get.call(_chartRef$current);
      if (chart) {
        var rect = chart.getDom().getBoundingClientRect();
        var x = e.clientX - rect.left;
        var y = e.clientY - rect.top;
        var pointInPixel = [x, y];
        if (chart.containPixel('grid', pointInPixel)) {
          var xIndex = chart.convertFromPixel({
            seriesIndex: 0
          }, [x, y])[0];
          onEvents === null || onEvents === void 0 || onEvents.onClick(xIndex);
        }
      }
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    onClick: onClick,
    style: _objectSpread({
      height: height,
      width: '100%'
    }, style)
  }, (_option$series = option.series) !== null && _option$series !== void 0 && (_option$series = _option$series[0]) !== null && _option$series !== void 0 && (_option$series = _option$series.data) !== null && _option$series !== void 0 && _option$series.length ? /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    ref: chartRef,
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: height || '100%'
    },
    onEvents: onEvents
  }) : /*#__PURE__*/_react["default"].createElement(_antd.Empty, {
    image: _antd.Empty.PRESENTED_IMAGE_SIMPLE
  }));
}), function (prevProps, nextProps) {
  // 这个函数用于比较前后两个props是否相同
  // 如果相同，则不会重新渲染
  return JSON.stringify(prevProps) === JSON.stringify(nextProps);
});
var _default = exports["default"] = Chart;
//# sourceMappingURL=index.js.map
