function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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 _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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
import ReactEcharts from 'echarts-for-react';
import { Component } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
var Index = /*#__PURE__*/function (_Component) {
  _inherits(Index, _Component);
  var _super = _createSuper(Index);
  function Index() {
    var _this;
    _classCallCheck(this, Index);
    _this = _super.call(this);
    // this.divRef = React.createRef();
    _this.resizeObserver = null;
    return _this;
  }
  _createClass(Index, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var div = this.divRef;
      var main = this.mainRef;
      // 创建一个ResizeObserver实例并定义回调函数
      var resizeObserver = new ResizeObserver(function (entries) {
        var _iterator = _createForOfIteratorHelper(entries),
          _step;
        try {
          for (_iterator.s(); !(_step = _iterator.n()).done;) {
            var entry = _step.value;
            var _entry$contentRect = entry.contentRect,
              width = _entry$contentRect.width,
              height = _entry$contentRect.height;
            main.style.transform = "scale(1.1)";
            console.log(main, 19);
            // main.style.transform = `scaleX(${width / 800}) scaleY(${height / 500})`;
          }
        } catch (err) {
          _iterator.e(err);
        } finally {
          _iterator.f();
        }
      });
      // 开始监听div的尺寸变化
      resizeObserver.observe(div);
      this.resizeObserver = resizeObserver;
      var myChart = this.echartRef.getEchartsInstance();
      // 默认高亮
      var index = 0; // 高亮索引
      myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: index,
        dataIndex: index
      });
      myChart.on('mouseover', function (e) {
        if (e.dataIndex != index) {
          myChart.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
            dataIndex: index
          });
        }
      });
      myChart.on('mouseout', function (e) {
        index = e.dataIndex;
        myChart.dispatchAction({
          type: 'highlight',
          seriesIndex: 0,
          dataIndex: e.dataIndex
        });
      });
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      //卸载移除监听
      this.resizeObserver.disconnect();
    }
  }, {
    key: "getOption",
    value: function getOption() {
      var colorList = ['#00F9FF', '#1978E5', '#FFF67C', '#60B45E', '#BECDD0'];
      var colorListShadow = ['rgba(25,63,87,1)', 'rgba(14,39,86,1)', 'rgba(56,64,63,1)', 'rgba(94, 225, 204,.3)', 'rgba(212,224,227,.1)'];
      var data = this.props.optionsData;
      // color: ['#00F9FF', '#1978E5', '#FFF67C', '#60B45E', '#BECDD0'],
      var outData = data.map(function (item, index) {
        return {
          value: item.value,
          name: '',
          //因为不展示label，可不填
          itemStyle: {
            normal: {
              color: item.color || colorListShadow[index]
            }
          }
        };
      });
      var center = ['30%', '50%'];
      var radius = {
        内: ['55%', '60%'],
        pie: ['60%', '75%'],
        外: ['75%', '80%']
      };
      var option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          itemGap: 30,
          selectedMode: false,
          orient: 'vertical',
          right: 100,
          top: 'center',
          align: 'left',
          itemHeight: 16,
          itemWidth: 16,
          textStyle: {
            color: 'white',
            rich: {
              name: {
                color: '#fff',
                fontSize: 20,
                lineHeight: 24
              },
              value: {
                color: '#fff',
                fontSize: 20,
                lineHeight: 24
              }
            }
          },
          data: data,
          formatter: function formatter(name) {
            var nameSpace = (name === null || name === void 0 ? void 0 : name.length) < 3 ? name + '   ' : name;
            var value = data === null || data === void 0 ? void 0 : data.find(function (item) {
              return (item === null || item === void 0 ? void 0 : item.name) == name;
            }).value;
            var html = "  {name|".concat(nameSpace, "}   {value|").concat(value, "}");
            var arr = [html];
            return arr.join('\n');
          }
        },
        series: [{
          name: '项目',
          type: 'pie',
          radius: radius['pie'],
          center: center,
          avoidLabelOverlap: false,
          color: colorList,
          label: {
            normal: {
              show: false,
              position: 'center',
              formatter: '{b}\n\n{c}'
            },
            emphasis: {
              show: true,
              textStyle: {
                fontSize: '30',
                fontWeight: 'bold',
                color: colorList
              }
            }
          },
          labelLine: {
            normal: {
              show: false
            }
          },
          data: data
        }, {
          name: '内边框',
          type: 'pie',
          tooltip: {
            show: false
          },
          clockWise: true,
          //顺时加载
          hoverAnimation: false,
          //鼠标移入变大
          center: center,
          //这里跟上面那组一样即可
          radius: radius['内'],
          //这里根据自己的需要自行调整
          label: {
            normal: {
              show: false //重点：此处主要是为了不展示data中的value和name
            }
          },

          data: outData
        }, {
          name: '外边框',
          type: 'pie',
          tooltip: {
            show: false
          },
          clockWise: true,
          //顺时加载
          hoverAnimation: false,
          //鼠标移入变大
          center: center,
          //这里跟上面那组一样即可
          radius: radius['外'],
          //这里根据自己的需要自行调整
          label: {
            normal: {
              show: false //重点：此处主要是为了不展示data中的value和name
            }
          },

          data: outData
        }]
      };
      return option;
    }
  }, {
    key: "onChartClick",
    value: function onChartClick() {}
  }, {
    key: "onChartLegendselectchanged",
    value: function onChartLegendselectchanged() {}
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var onEvents = {
        click: this.onChartClick,
        legendselectchanged: this.onChartLegendselectchanged
      };
      return /*#__PURE__*/_jsx("div", {
        ref: function ref(e) {
          _this2.divRef = e;
        },
        children: /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
          ref: function ref(e) {
            _this2.mainRef = e;
          }
        }, this.props), {}, {
          children: /*#__PURE__*/_jsx(ReactEcharts, _objectSpread({
            onEvents: onEvents,
            ref: function ref(e) {
              _this2.echartRef = e;
            },
            option: this.getOption(),
            theme: "Imooc"
          }, this.props))
        }))
      });
    }
  }]);
  return Index;
}(Component);
export default Index;