import { getComVal, itemstyle } 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模拟数据
   * @returns 雷达图1配置项
   */
  static radar1(data: any) {
    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: object = {
      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: {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: itemstyle(),
              global: false, // 缺省为 false
            },
            shadowColor: getComVal("color_data")[0],
          },
          /** 线的样式 */
          lineStyle: {
            width: 0,
          },
          /** 点的样式 */
          itemStyle: {
            opacity: 0, //不绘制点
          },
          tooltip: {
            trigger: "item",
          },
          data: [
            {
              value: indicators_val,
            },
          ],
        },
      ],
    };
    return option;
  }
}
