"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var echarts = _interopRequireWildcard(require("echarts"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _excluded = ["name", "chartType", "seriesData", "color", "areaColor", "colorConfig"];
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 && Object.prototype.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(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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 _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
// 判断校验方法
var judgeWay = function judgeWay(_ref) {
  var argument = _ref.argument,
    defaultData = _ref.defaultData;
  var resultData = argument || defaultData;
  return resultData;
};
function LinesChart(props) {
  var title = props.title,
    _props$titleConfig = props.titleConfig,
    titleConfig = _props$titleConfig === void 0 ? {
      left: 'center',
      bottom: 10
    } : _props$titleConfig,
    subtext = props.subtext,
    _props$loading = props.loading,
    loading = _props$loading === void 0 ? false : _props$loading,
    _props$height = props.height,
    height = _props$height === void 0 ? 200 : _props$height,
    _props$data = props.data,
    data = _props$data === void 0 ? [] : _props$data,
    _props$xAxis = props.xAxis,
    xAxis = _props$xAxis === void 0 ? [] : _props$xAxis,
    _props$textColor = props.textColor,
    textColor = _props$textColor === void 0 ? '#000' : _props$textColor,
    yAxisName = props.yAxisName,
    yAxisName2 = props.yAxisName2,
    _props$tooltipConfig = props.tooltipConfig,
    tooltipConfig = _props$tooltipConfig === void 0 ? {} : _props$tooltipConfig,
    _props$legendConfig = props.legendConfig,
    legendConfig = _props$legendConfig === void 0 ? {} : _props$legendConfig,
    _props$otherLegend = props.otherLegend,
    otherLegend = _props$otherLegend === void 0 ? [] : _props$otherLegend,
    _props$gridConfig = props.gridConfig,
    gridConfig = _props$gridConfig === void 0 ? {} : _props$gridConfig,
    _props$onEvents = props.onEvents,
    onEvents = _props$onEvents === void 0 ? {} : _props$onEvents,
    selected = props.selected,
    dataZoomShow = props.dataZoomShow,
    _props$yAxisConfig = props.yAxisConfig,
    yAxisConfig = _props$yAxisConfig === void 0 ? {} : _props$yAxisConfig,
    _props$xAxisConfig = props.xAxisConfig,
    xAxisConfig = _props$xAxisConfig === void 0 ? {} : _props$xAxisConfig,
    _props$chartConfig = props.chartConfig,
    chartConfig = _props$chartConfig === void 0 ? {} : _props$chartConfig,
    _props$boundaryGap = props.boundaryGap,
    boundaryGap = _props$boundaryGap === void 0 ? false : _props$boundaryGap,
    gridLeft = props.gridLeft,
    gridRight = props.gridRight,
    _props$darkCockpit = props.darkCockpit,
    darkCockpit = _props$darkCockpit === void 0 ? false : _props$darkCockpit,
    _props$lineColor = props.lineColor,
    lineColor = _props$lineColor === void 0 ? '#2B4C6D' : _props$lineColor,
    _props$otherConfig = props.otherConfig,
    otherConfig = _props$otherConfig === void 0 ? {} : _props$otherConfig,
    _props$notyAxisName = props.notyAxisName2,
    notyAxisName2 = _props$notyAxisName === void 0 ? false : _props$notyAxisName;
  textColor = judgeWay({
    argument: textColor,
    defaultData: _config["default"].cockpitColor
  });
  var axisColor = judgeWay({
    argument: _config["default"].cockpitStyle.textColor,
    defaultData: '#fff'
  });
  var series = [];
  for (var i = 0; i < data.length; i++) {
    var _data$i = data[i],
      name = _data$i.name,
      _data$i$chartType = _data$i.chartType,
      chartType = _data$i$chartType === void 0 ? 'line' : _data$i$chartType,
      seriesData = _data$i.seriesData,
      color = _data$i.color,
      areaColor = _data$i.areaColor,
      colorConfig = _data$i.colorConfig,
      val = _objectWithoutProperties(_data$i, _excluded);
    if (color) {
      // Util.isArray(color) &&
      if (color.length) {
        if (chartType === 'line') {
          val.itemStyle = _objectSpread({
            normal: {
              color: _objectSpread(_objectSpread({
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0,
                  color: color[0] // 0% 处的颜色
                }, {
                  offset: 1,
                  color: color[1] // 100% 处的颜色
                }]
              }, colorConfig), {}, {
                global: false // 缺省为 false
              })
            }
          }, val.itemStyle);
        } else if (chartType === 'bar') {
          val.itemStyle = _objectSpread({
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: color[0]
            }, {
              offset: 1,
              color: color[1]
            }])
          }, val.itemStyle);
        }
      } else {
        val.itemStyle = _objectSpread({
          color: color
        }, val.itemStyle);
      }
    }

    // 渐变
    if (areaColor && areaColor.length) {
      val.areaStyle = {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0,
            color: areaColor[0]
          } /*0% 处的颜色*/, {
            offset: 1,
            color: areaColor[1]
          } /* 100% 处的颜色*/],
          globalCoord: false // 缺省为 false
        }
      };
    }
    series.push(_objectSpread({
      symbolSize: 6,
      barMaxWidth: 20,
      name: name,
      type: chartType,
      smooth: true,
      data: seriesData,
      connectNulls: true
    }, val));
  }
  var yAxis = [];
  var yAxisColor = darkCockpit ? _config["default"].cockpitStyle.textColor : textColor;
  [yAxisName, yAxisName2].map(function (name, index) {
    if (name || index !== 0 || notyAxisName2) {
      yAxis.push(_objectSpread(_objectSpread({
        type: 'value',
        name: name,
        // scale: true,
        color: yAxisColor,
        nameTextStyle: {
          color: yAxisColor,
          fontSize: 12
        },
        axisLabel: {
          color: yAxisColor
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: yAxisColor,
            width: 1,
            //这里是为了突出显示加上的
            opacity: 0.3,
            type: 'dashed'
          }
        },
        axisTick: {
          show: false
        },
        splitLine: {
          lineStyle: {
            // 使用深浅的间隔色
            color: textColor,
            opacity: 0.14,
            type: 'dashed'
          }
        }
      }, darkCockpit ? {
        splitNumber: 3,
        axisLine: {
          show: false,
          lineStyle: {
            color: axisColor,
            width: 2,
            //这里是为了突出显示加上的
            opacity: 0.3,
            type: 'dashed'
          }
        },
        axisLabel: {
          color: axisColor
        },
        splitLine: {
          show: true,
          lineStyle: {
            // 使用深浅的间隔色
            color: judgeWay({
              argument: _config["default"].cockpitStyle.splitLineColor,
              defaultData: '#fff'
            }),
            opacity: 0.3,
            type: 'dashed'
          }
        }
      } : {}), Array.isArray(yAxisConfig) ? yAxisConfig[index] : yAxisConfig));
    }
  });
  var option = _objectSpread({
    color: ['#79b8ff', '#EDD256', '#54C77A', '#fc8a33', '#f8ac6e', '#ff497d', '#a5f84f', '#9b6ef8'],
    title: _objectSpread({
      show: true,
      text: title,
      left: 'center',
      subtext: subtext,
      bottom: 10,
      textStyle: {
        // color: textColor,
        fontSize: 14
      },
      subtextStyle: {
        fontSize: 16,
        lineHeight: 16
      }
    }, titleConfig),
    tooltip: _objectSpread(_objectSpread({
      trigger: 'axis',
      axisLine: {
        lineStyle: {
          color: '#FEFEFE'
        }
      },
      confine: true
    }, darkCockpit ? {
      backgroundColor: _config["default"].cockpitStyle.bgColor,
      //tooltip背景色
      borderColor: _config["default"].cockpitStyle.bgColor,
      //tooltip边框颜色
      textStyle: {
        fontWeight: 'bold',
        fontSize: 14,
        color: _config["default"].cockpitStyle.textColor
      }
    } : {}), tooltipConfig),
    legend: [_objectSpread(_objectSpread({
      type: 'scroll',
      textStyle: {
        color: textColor
      },
      selected: selected,
      pageIconColor: textColor,
      //翻页下一页的三角按钮颜色
      pageIconInactiveColor: '#aaa',
      //翻页（即翻页到头时）
      pageTextStyle: {
        color: textColor
      }
    }, darkCockpit ? {
      textStyle: {
        fontSize: 12,
        color: '#fff'
      }
    } : {}), legendConfig)].concat(_toConsumableArray(otherLegend)),
    grid: _objectSpread({
      top: !title ? yAxisConfig ? 40 : 70 : 50,
      left: gridLeft || 20,
      right: gridRight || 20,
      bottom: dataZoomShow ? 40 : 50,
      containLabel: true,
      tooltip: {
        backgroundColor: '#000'
      }
    }, gridConfig),
    dataZoom: dataZoomShow ? [{
      // 这个dataZoom组件，默认控制x轴。
      type: 'slider',
      // 这个 dataZoom 组件是 slider 型 dataZoom 组件
      start: 0,
      // 左边在 10% 的位置。
      end: 100,
      // 右边在 60% 的位置。
      height: 25,
      bottom: 10,
      textStyle: {
        opacity: 0
      }
    }, {
      // 这个dataZoom组件，也控制x轴。
      type: 'inside',
      // 这个 dataZoom 组件是 inside 型 dataZoom 组件
      start: 0,
      // 左边在 10% 的位置。
      end: 100,
      // 右边在 60% 的位置。
      height: 25,
      bottom: 10
    }] : [],
    xAxis: [_objectSpread(_objectSpread({
      type: 'category',
      boundaryGap: boundaryGap,
      // 从0开始
      data: data[0] ? data[0].xAxisData : [],
      axisLabel: {
        color: textColor
      },
      axisLine: {
        lineStyle: {
          color: lineColor,
          width: 2 //这里是为了突出显示加上的
        }
      },
      axisTick: {
        show: false
      },
      splitLine: {
        lineStyle: {
          // 使用深浅的间隔色
          color: '#525D70',
          opacity: 0.2
        }
      }
    }, darkCockpit ? {
      axisLine: {
        show: false,
        lineStyle: {
          color: axisColor,
          width: 2,
          //这里是为了突出显示加上的
          opacity: 0.3,
          type: 'dashed'
        }
      },
      axisLabel: {
        color: axisColor
      },
      splitLine: {
        show: false,
        lineStyle: {
          // 使用深浅的间隔色
          color: axisColor,
          opacity: 0.3,
          type: 'dashed'
        }
      }
    } : {}), xAxisConfig)].concat(_toConsumableArray(xAxis)),
    yAxis: yAxis,
    series: series
  }, otherConfig);
  return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], _extends({
    style: {
      height: height
    },
    echarts: echarts,
    option: option,
    showLoading: loading,
    loadingOption: {
      text: '加载中...'
    },
    onEvents: onEvents,
    notMerge: true,
    lazyUpdate: true
  }, chartConfig));
}
var _default = exports["default"] = LinesChart;
//# sourceMappingURL=LinesChart.js.map
