export function processLineExtremeData()

in src/rule/extremeData.ts [254:372]


export function processLineExtremeData(chartObj: any, config: any, data: any) {
  // 此处需要所有数据点的个数,不能直接用dataSize
  // const { dataSize } = chartObj;
  const dataSize = data?.length || 0;
  const chartName = chartObj?.chartRule?.name;
  const { force } = chartObj.props;

  // 计算线的数量
  const lineCount = Array.from(new Set(data.map((d: any) => d.type))).length;
  let isEqual = false;
  if (lineCount === 1) {
    let temp = data?.[0]?.y;
    const filterArr = data?.filter((el: any) => el?.y !== temp);
    if (!filterArr?.length && temp !== null && temp !== undefined) {
      isEqual = true;
    }
  }

  // 只有一个点的时候,在Y轴中间,并开启label与symbol
  if (lineCount === 1 && dataSize === 1) {
    warn(chartName, '当前线图数据较少,为优化展示,已自动开启标记和文本。若要关闭可加force配置项。');
    if (force === true || force?.extreme === true) {
      return { isExtreme: true };
    }
    return {
      config: {
        yAxis: {
          ...config.yAxis,
          min: data?.[0]?.y > 0 ? 0 : data?.[0]?.y * 2,
          max: data?.[0]?.y > 0 ? data?.[0]?.y * 2 : 0,
        },
        // label判断自定义
        label: {
          labelFormatter: config.yAxis.labelFormatter,
          ...(typeof config?.label === 'object' ? config.label : {}),
          visible: true,
        },
        symbol: {
          ...(typeof config?.symbol === 'object' ? config?.symbol : {}),
          visible: true,
        },
      },
      isExtreme: true,
    };
  } else if (dataSize === lineCount) {
    // 多条线,每条线一个点时,开启symbol,label暂不开启
    warn(chartName, '当前线图数据较少,为优化展示,已自动开启标记。若要关闭可加force配置项。');
    if (force === true || force?.extreme === true) {
      return { isExtreme: true };
    }
    return {
      config: {
        // label: {
        //   ...(typeof config?.label === 'object' ? config?.label : {}),
        //   visible: true,
        // },
        symbol: {
          ...(typeof config?.symbol === 'object' ? config?.symbol : {}),
          visible: true,
        },
      },
      isExtreme: true,
    };
  } else if (lineCount === 1 && dataSize === 2) {
    // 一条线两个点,开启area、symbol和label
    warn(chartName, '当前线图数据较少,为优化展示,已自动开启面积、标记、文本。若要关闭可加force配置项。');
    if (force === true || force?.extreme === true) {
      return { isExtreme: true };
    }
    return {
      config: {
        // label判断自定义
        label: {
          labelFormatter: config.yAxis.labelFormatter,
          ...(typeof config?.label === 'object' ? config?.label : {}),
          visible: true,
        },
        symbol: {
          ...(typeof config?.symbol === 'object' ? config?.symbol : {}),
          visible: true,
        },
        area: true,
      },
      isExtreme: true,
    };
  } else if (lineCount === 1 && isEqual) {
    warn(chartName, '当前线图数据相同,为优化展示,已自动将线居中显示。若要关闭可加force配置项。');
    if (force === true || force?.extreme === true) {
      return { isExtreme: true };
    }
    return {
      config: {
        yAxis: {
          ...config.yAxis,
          min: data?.[0]?.y > 0 ? 0 : data?.[0]?.y * 2,
          max: data?.[0]?.y > 0 ? data?.[0]?.y * 2 : 0,
          tickCount: 3,
        },
      },
      isExtreme: true,
    };
  } else if (lineCount > 3 && !config.stack && config.area) {
    // 当补开启堆叠面积图的时候,且分组数量大于3组
    warn(chartName, '当前线图组数超过3组,不适合开启面积图,已自动关闭面积图配置。若要关闭可加force配置项。');
    if (force === true || force?.extreme === true) {
      return { isExtreme: true };
    }
    return {
      config: {
        area: false,
      },
      isExtreme: true,
    };
  }

  return {
    isExtreme: false,
  };
}