"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _groupBy = _interopRequireDefault(require("lodash/groupBy"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 xAxis = _toConsumableArray(new Array(24)).map(function (_, index) {
  return add0(index);
});
function add0(num) {
  return num >= 10 ? num.toString() : "0".concat(num);
}
function transferData(data) {
  var chartData = [];
  var dataGroupByDate = (0, _groupBy["default"])(data, 'date');
  var count = 0;
  for (var key in dataGroupByDate) {
    dataGroupByDate[key].forEach(function (item, index) {
      chartData.push([index, count, item.value]);
    });
    count++;
  }
  return {
    yAxis: Object.keys(dataGroupByDate).map(function (item) {
      return item.substring(5);
    }),
    chartData: chartData
  };
}
var getGaugeOption = function getGaugeOption(_ref) {
  var _ref$data = _ref.data,
    data = _ref$data === void 0 ? [] : _ref$data;
  var _transferData = transferData(data),
    yAxis = _transferData.yAxis,
    chartData = _transferData.chartData;
  var max = Math.max.apply(Math, _toConsumableArray(chartData.map(function (item) {
    return item[2];
  })));
  if (!(chartData === null || chartData === void 0 ? void 0 : chartData.length)) return {};
  return {
    tooltip: {
      position: 'top',
      formatter: function formatter(params) {
        var value = params.value,
          marker = params.marker;
        var date = yAxis[value[1]];
        var hour = "".concat(add0(value[0]), ":00-").concat(add0(value[0] + 1), ":00");
        return "<div>".concat(date, " ").concat(hour, "</div><div>").concat(marker, " \u6295\u653E\u6B21\u6570\uFF1A").concat(value[2], "\u6B21</div>");
      }
    },
    grid: {
      top: 50,
      bottom: 0,
      right: 0,
      left: 0,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: xAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        interval: 0,
        color: '#fff'
      },
      axisTick: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: yAxis,
      splitArea: {
        show: true
      },
      axisLabel: {
        color: '#fff',
        interval: 0
      },
      axisTick: {
        show: false
      }
    },
    visualMap: {
      // type: 'piecewise',
      min: 0,
      max: max,
      calculable: true,
      orient: 'horizontal',
      left: 'center',
      top: 0,
      inRange: {
        color: ['#364357', '#00759C', '#29A8F0', '#F5B829', '#E7473F']
      },
      textStyle: {
        color: '#fff'
      }
    },
    series: [{
      name: '24h分布',
      type: 'heatmap',
      data: chartData,
      label: {
        show: true
      },
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }]
  };
};
var Distribute1 = function Distribute1(props) {
  return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getGaugeOption(props),
    style: {
      height: '100%'
    }
  });
};
var _default = exports["default"] = Distribute1;
//# sourceMappingURL=Distribute1.js.map
