"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _umd = require("amos-viz/lib/echarts/umd"), _rayValidate = require("ray-validate"), _DateUtil = require("./../common/date/DateUtil");

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, o) : null;
    n && (n.get || n.set) ? Object.defineProperty(a, o, n) : a[o] = e[o];
  }
  return a.default = e, r && r.set(e, a), a;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } else r = a.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

var setToolTip = function(e, t) {
  var r = (0, _DateUtil.dateToNoYS)(e[0].data[0]);
  return r = "".concat(r, "<br/>"), e.map((function(e) {
    var a = e.seriesName, i = e.data[1];
    r = "".concat(r, " ").concat('<img src="/src/assets/iot/topo/dot/blue.png" alt>', " ").concat(a, " ").concat(i).concat(t, "<br/>");
  })), r;
}, dataConversion = function(e, t) {
  var r = [];
  return t.map((function(t) {
    r.push({
      name: t.name,
      type: "line",
      symbol: t.icon,
      symbolSize: 6,
      itemStyle: {
        normal: {
          color: t.color
        }
      },
      lineStyle: {
        color: t.color
      },
      areaStyle: {
        normal: {
          color: "#E7F3FF"
        }
      },
      smooth: !0,
      data: getData(e, t.valueVarName)
    });
  })), r;
}, getData = function(e, t) {
  return (e[t] ? e[t] : []).map((function(e) {
    if ((0, _rayValidate.isNum)(e.value)) return [ e.exeTime, e.value.toFixed(2) ];
  }));
}, HistoryChartView = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), (a = t.call(this, e)).chartOptions = a.chartOptions.bind((0, 
    _assertThisInitialized2.default)(a)), a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "chartOptions",
    value: function() {
      var e = this.props, t = e.unit, r = (e.interval, e.min), a = e.max, i = e.data, o = e.legend, n = e.axisLabelFormatter;
      return t || (t = ""), {
        tooltip: {
          trigger: "axis",
          backgroundColor: "#345FA6",
          formatter: function(e) {
            return setToolTip(e, t);
          }
        },
        legend: {
          itemWidth: 11,
          itemHeight: 11,
          data: o,
          bottom: 0
        },
        grid: {
          left: "3%",
          right: "4%",
          top: "13%",
          bottom: "10%",
          containLabel: !0
        },
        xAxis: [ {
          type: "value",
          nameTextStyle: {
            color: "#222",
            fontSize: 15
          },
          nameGap: 20,
          splitLine: {
            show: !1
          },
          axisLine: {
            show: !0,
            lineStyle: {
              color: "#BBB"
            }
          },
          splitNumber: 8,
          min: r,
          max: a,
          axisLabel: {
            textStyle: {
              color: "#222",
              fontSize: 13
            },
            formatter: function(e, t) {
              return n(e);
            }
          }
        } ],
        yAxis: {
          name: "单位：".concat(t),
          nameLocation: "middle",
          nameGap: 40,
          type: "value",
          splitLine: {
            lineStyle: {
              type: "dotted"
            }
          },
          axisLine: {
            show: !1
          },
          axisTick: {
            show: !1
          }
        },
        series: dataConversion(i, o)
      };
    }
  }, {
    key: "render",
    value: function() {
      var e = this.chartOptions();
      return _react.default.createElement("div", {
        className: "three-phase-view"
      }, _react.default.createElement(_umd.LineChart, {
        lineOps: e,
        shouldDispose: this.props.shouldDispose,
        chartStyle: this.props.chartStyle
      }));
    }
  } ]), r;
}(_react.Component);

HistoryChartView.displayName = "HistoryChartView", HistoryChartView.propTypes = {
  unit: _propTypes.default.string,
  interval: _propTypes.default.number,
  min: _propTypes.default.number,
  max: _propTypes.default.number,
  axisLabelFormatter: _propTypes.default.func,
  data: _propTypes.default.object,
  legend: _propTypes.default.array,
  chartStyle: _propTypes.default.object,
  shouldDispose: _propTypes.default.bool
}, HistoryChartView.defaultProps = {
  data: {},
  legend: [],
  chartStyle: {
    width: "100%",
    height: "20rem"
  }
};

var _default = HistoryChartView;

exports.default = _default;