import { getComVal, LinearGradient } from "../echart-method";

/**
 * 雷达图
 */
export class Radar {
  /**
   * 生成雷达图模拟数据
   * @param arr 数据名称
   * @returns 雷达图模拟数据
   */
  static getRadarData(arr?: string[]) {
    let radar_data: any[] = [];
    if (arr) {
      arr.forEach((e) => {
        radar_data.push({
          name: e,
          max: 1100,
          value: Math.ceil(Math.random() * 1000),
        });
      });
    } else {
      getComVal("week").forEach((a: any) => {
        radar_data.push({
          name: a,
          max: 1100,
          value: Math.ceil(Math.random() * 1000),
        });
      });
    }
    return radar_data;
  }
  /**
   * 雷达图0
   * @param data 雷达图0模拟数据
   * @returns 雷达图0配置项
   */
  static radar0(data: any) {
    console.log(data);

    let indicator: any = [];
    let indicator_val: any = [];
    data.forEach((a: any) => {
      indicator.push({
        name: a.name,
        max: a.max,
      });
      indicator_val.push(a.value);
    });
    const option = {
      color: getComVal("color_data"),
      backgroundColor: getComVal("backgroundColor"),
      grid: getComVal("grid"),
      tooltip: {
        trigger: "axis",
      },
      radar: {
        indicator: indicator,
      },
      series: [
        {
          name: "数据",
          type: "radar",
          areaStyle: {},
          tooltip: {
            trigger: "item",
          },
          data: [
            {
              value: indicator_val,
            },
          ],
        },
      ],
    };
    return option;
  }
  /**
   * 雷达图1
   * @param data 雷达图1模拟数据
   * @param gradientColor 渐变颜色组
   * @returns 雷达图1配置项
   */
  static radar1(data: any, gradientColor: string[]) {
    let _gradientColor = gradientColor
      ? gradientColor
      : getComVal("color_data");
    let indicators: any = [];
    let indicators_val: any = [];
    data.forEach((a: any) => {
      indicators.push({
        name: a.name,
        max: a.max,
      });
      indicators_val.push(a.value);
    });
    const option: any = {
      color: getComVal("color_data")[0],
      backgroundColor: getComVal("backgroundColor"),
      grid: getComVal("grid"),
      tooltip: {
        trigger: "axis",
      },
      radar: {
        indicator: indicators,
      },
      series: [
        {
          name: "数据",
          type: "radar",
          areaStyle: {
            shadowOffsetX: 10,
            color: LinearGradient(_gradientColor),
            shadowColor: getComVal("color_data")[0],
          },
          /** 线的样式 */
          lineStyle: {
            width: 0,
          },
          /** 点的样式 */
          itemStyle: {
            opacity: 0,
          },
          tooltip: {
            trigger: "item",
          },
          data: [
            {
              value: indicators_val,
            },
          ],
        },
      ],
    };
    return option;
  }
}
