var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/CyPie/index.tsx
var CyPie_exports = {};
__export(CyPie_exports, {
  default: () => CyPie_default
});
module.exports = __toCommonJS(CyPie_exports);
var import_react = require("react");
var import_index_module = __toESM(require("./index.module.less"));
function PieChart(props) {
  const chartRef = (0, import_react.useRef)(null);
  const divRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    let chartInstance = echarts.init(chartRef.current);
    function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, height) {
      let midRatio = (startRatio + endRatio) / 2;
      let startRadian = startRatio * Math.PI * 2;
      let endRadian = endRatio * Math.PI * 2;
      let midRadian = midRatio * Math.PI * 2;
      if (startRatio === 0 && endRatio === 1) {
        isSelected = false;
      }
      k = typeof k !== "undefined" ? k : 1 / 3;
      let offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0;
      let offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0;
      let hoverRate = isHovered ? 1.05 : 1;
      return {
        u: {
          min: -Math.PI,
          max: Math.PI * 3,
          step: Math.PI / 32
        },
        v: {
          min: 0,
          max: Math.PI * 2,
          step: Math.PI / 20
        },
        x: function(u, v) {
          if (u < startRadian) {
            return offsetX + Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
          }
          if (u > endRadian) {
            return offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
          }
          return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
        },
        y: function(u, v) {
          if (u < startRadian) {
            return offsetY + Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
          }
          if (u > endRadian) {
            return offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
          }
          return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
        },
        z: function(u, v) {
          if (u < -Math.PI * 0.5) {
            return Math.sin(u);
          }
          if (u > Math.PI * 2.5) {
            return Math.sin(u);
          }
          return Math.sin(v) > 0 ? 1 * height : -1;
        }
      };
    }
    function getPie3D(pieData, internalDiameterRatio) {
      let series2 = [];
      let sumValue = 0;
      let startValue = 0;
      let endValue = 0;
      let legendData = [];
      let k = typeof internalDiameterRatio !== "undefined" ? (1 - internalDiameterRatio) / (1 + internalDiameterRatio) : 1 / 3;
      for (let i = 0; i < pieData.length; i++) {
        sumValue += pieData[i].value;
        let seriesItem = {
          name: typeof pieData[i].name === "undefined" ? `series${i}` : pieData[i].name,
          type: "surface",
          parametric: true,
          wireframe: {
            show: false
          },
          pieData: pieData[i],
          pieStatus: {
            selected: false,
            hovered: false,
            k
          }
        };
        if (typeof pieData[i].itemStyle != "undefined") {
          let itemStyle = {};
          typeof pieData[i].itemStyle.color != "undefined" ? itemStyle.color = pieData[i].itemStyle.color : null;
          typeof pieData[i].itemStyle.opacity != "undefined" ? itemStyle.opacity = pieData[i].itemStyle.opacity : null;
          seriesItem.itemStyle = itemStyle;
        }
        series2.push(seriesItem);
      }
      for (let i = 0; i < series2.length; i++) {
        endValue = startValue + series2[i].pieData.value;
        series2[i].pieData.startRatio = startValue / sumValue;
        series2[i].pieData.endRatio = endValue / sumValue;
        series2[i].parametricEquation = getParametricEquation(
          series2[i].pieData.startRatio,
          series2[i].pieData.endRatio,
          false,
          false,
          k,
          series2[i].pieData.value
        );
        startValue = endValue;
        legendData.push(series2[i].name);
      }
      return series2;
    }
    let r = 100;
    const optionsData = props == null ? void 0 : props.optionsData;
    const series = getPie3D(optionsData, 0.8, 240, 28, 26, 0.5);
    series.push({
      name: "pie2d",
      type: "pie",
      label: {
        show: false,
        opacity: 1,
        fontSize: 14,
        lineHeight: 20,
        textStyle: {
          fontSize: 14,
          color: "#fff"
        }
      },
      labelLine: {
        length: 30,
        length2: 30
      },
      startAngle: -30,
      //起始角度，支持范围[0, 360]。
      clockwise: false,
      //饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
      radius: ["40%", "60%"],
      center: ["50%", "50%"],
      data: optionsData,
      itemStyle: {
        opacity: 0
      }
    });
    let option = {
      legend: {
        show: true,
        tooltip: {
          show: true
        },
        orient: "vertical",
        data: optionsData,
        // top: "center",
        itemGap: 30,
        itemHeight: 18,
        itemWidth: 17,
        right: 10,
        top: 60,
        textStyle: {
          color: "#fff",
          fontSize: 20
        },
        formatter: (params) => {
          let e = optionsData == null ? void 0 : optionsData.find((item) => params == (item == null ? void 0 : item.name));
          let name = params.padEnd(6, " ");
          if (e.name.length < 7) {
            name = name + "  ";
          }
          return name + e.value / 100 + "%";
        }
      },
      animation: true,
      tooltip: {
        formatter: (params) => {
          if (params.seriesName !== "mouseoutSeries" && params.seriesName !== "pie2d") {
            return `${params.seriesName}<br/><span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${params.color};"></span>${option.series[params.seriesIndex].pieData.value / 100 + "%"}`;
          }
        },
        textStyle: {
          fontSize: 14
        }
      },
      title: {
        x: "center",
        top: "20",
        textStyle: {
          color: "#fff",
          fontSize: 22
        }
      },
      graphic: {
        type: "text",
        ...props.titleStyle
      },
      labelLine: {
        show: true,
        lineStyle: {
          color: "#7BC0CB"
        },
        normal: {
          show: true,
          length: 10,
          length2: 10
        }
      },
      label: {
        show: true,
        position: "outside",
        formatter: "{b} \n{d}%",
        textStyle: {
          color: "#fff",
          fontSize: "14px"
        }
      },
      xAxis3D: {
        min: -1,
        max: 1
      },
      yAxis3D: {
        min: -1,
        max: 1
      },
      zAxis3D: {
        min: -1,
        max: 1
      },
      grid3D: {
        show: false,
        boxHeight: 0.01,
        left: "-18%",
        viewControl: {
          distance: 180,
          minDistance: 180,
          maxDistance: 180,
          alpha: 25,
          beta: 100,
          autoRotate: true
          // 自动旋转
        }
      },
      series
    };
    if (props.optionsData) {
      chartInstance.setOption(option);
    }
  }, [props.optionsData]);
  (0, import_react.useEffect)(() => {
    const div = divRef.current;
    const resizeObserver = new ResizeObserver((entries) => {
      for (const entry of entries) {
        const { width, height } = entry.contentRect;
        if (chartRef.current) {
          chartRef.current.style.transform = `scaleX(${width / 800}) scaleY(${height / 500})`;
        }
      }
    });
    resizeObserver.observe(div);
    return () => {
      resizeObserver.disconnect();
    };
  }, []);
  return /* @__PURE__ */ React.createElement("div", { className: import_index_module.default.container, ...props, ref: divRef }, /* @__PURE__ */ React.createElement("div", { ref: chartRef, className: import_index_module.default.main }));
}
var CyPie_default = PieChart;
