"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 = _interopRequireWildcard(require("react"));
var _icons = _interopRequireDefault(require("@ant-design/icons"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _utils = require("@vtx/utils");
var _useSettings2 = _interopRequireDefault(require("../vm-hooks/useSettings"));
require("./index.less");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 _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 _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 _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; }
var getOption = function getOption(_ref) {
  var _ref$xAxis = _ref.xAxis,
    xAxis = _ref$xAxis === void 0 ? [] : _ref$xAxis,
    _ref$data = _ref.data,
    data = _ref$data === void 0 ? [] : _ref$data,
    _ref$dataZoomShow = _ref.dataZoomShow,
    dataZoomShow = _ref$dataZoomShow === void 0 ? true : _ref$dataZoomShow,
    _ref$xAxisConfig = _ref.xAxisConfig,
    xAxisConfig = _ref$xAxisConfig === void 0 ? [] : _ref$xAxisConfig,
    isDark = _ref.isDark;
  var textColor = isDark ? '#fff' : '#929292';
  var bgColor = isDark ? '#0C2A48' : '#fff';
  var borderColor = isDark ? '#1E4771' : '#fff';
  return {
    color: ['#0E85FF', '#49FF81', '#26D4FF', '#F5D629', '#C97CFF'],
    toolbox: {
      show: false,
      feature: {
        saveAsImage: {
          show: true,
          excludeComponents: ['toolbox'],
          pixelRatio: 2
        }
      }
    },
    tooltip: {
      trigger: 'axis',
      backgroundColor: bgColor,
      borderColor: borderColor,
      textStyle: {
        color: textColor
      },
      confine: true
    },
    legend: {
      type: 'scroll',
      top: 0,
      left: 'center',
      textStyle: {
        color: textColor
      }
    },
    grid: {
      top: 50,
      left: 40,
      right: 40,
      bottom: dataZoomShow ? 50 : 0,
      containLabel: true
    },
    xAxis: [{
      type: 'category',
      boundaryGap: true,
      data: xAxis,
      axisTick: {
        show: true
      },
      axisLine: {
        show: true
      },
      z: 10,
      axisLabel: {
        color: textColor
      }
    }].concat(_toConsumableArray(xAxisConfig)),
    yAxis: {
      name: '',
      nameTextStyle: {
        color: textColor
      },
      axisLine: {
        show: true
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: textColor
      },
      minInterval: 1,
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(255,255,255,0.2)'
        }
      }
    },
    series: data.map(function (item) {
      return Object.assign(Object.assign({
        type: 'line',
        name: item.name,
        smooth: true,
        // showSymbol: false, // 不展示点
        symbolSize: 4
      }, item), {
        data: item.data,
        connectNulls: false,
        xAxisIndex: item.xAxisIndex,
        color: item.color || '',
        label: item.label ? item.label : {}
      });
    }),
    dataZoom: dataZoomShow ? [{
      // 这个dataZoom组件，默认控制x轴。
      type: 'slider',
      start: 0,
      end: 100,
      fillerColor: 'rgba(97, 212, 225, 0.35)',
      borderColor: 'rgba(97, 212, 225, 0.35)',
      handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
      handleSize: '150%',
      height: 10,
      handleStyle: {
        color: '#fff',
        shadowBlur: 3,
        shadowColor: 'rgba(0, 0, 0, 0.4)',
        shadowOffsetX: 2,
        shadowOffsetY: 2
      },
      showDataShadow: false,
      showDetail: false
    }, {
      // 这个dataZoom组件，也控制x轴。
      type: 'inside',
      start: 0,
      end: 100,
      height: 10
    }] : []
  };
};
var Line = function Line(_ref2) {
  var xAxis = _ref2.xAxis,
    data = _ref2.data,
    style = _ref2.style,
    exportShow = _ref2.exportShow,
    dataZoomShow = _ref2.dataZoomShow,
    xAxisConfig = _ref2.xAxisConfig;
  var echarts_react = (0, _react.useRef)(null);
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark,
    theme = _useSettings.theme;
  // 保存为图片
  var saveImage = function saveImage() {
    var _a;
    var echartsInstance = (_a = echarts_react === null || echarts_react === void 0 ? void 0 : echarts_react.current) === null || _a === void 0 ? void 0 : _a.getEchartsInstance();
    if (echartsInstance) {
      var imgUrl = echartsInstance.getDataURL({
        pixelRatio: 1,
        backgroundColor: '#fff',
        excludeComponents: [
        //保存图表时忽略的工具组件,默认忽略工具栏
        'toolbox'],
        type: 'png' //图片类型支持png和jpeg
      });
      (0, _utils.downloadFile)(imgUrl, '图片', 'blob');
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "wrap"
  }, exportShow && (/*#__PURE__*/_react["default"].createElement("div", {
    className: "exportBtn-wrap ".concat(theme)
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "btn",
    onClick: function onClick() {
      saveImage();
    }
  }, /*#__PURE__*/_react["default"].createElement(_icons["default"], {
    style: {
      color: 'var(----sub-title-color)',
      fontSize: 20
    }
  })))), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    ref: echarts_react,
    option: getOption({
      xAxis: xAxis,
      data: data,
      dataZoomShow: dataZoomShow,
      xAxisConfig: xAxisConfig,
      isDark: isDark
    }),
    style: Object.assign({
      height: '100%',
      width: '100%'
    }, style),
    notMerge: true,
    lazyUpdate: true
  }));
};
var _default = exports["default"] = Line;
//# sourceMappingURL=Line.js.map
