antvis / S2

⚡️ A practical visualization library for tabular analysis.
https://s2.antv.antgroup.com
MIT License
1.46k stars 193 forks source link

🐛Meta in merged cell was unpredicted because of unsorted cellInfos #2854

Open linwaiwai opened 1 month ago

linwaiwai commented 1 month ago

🏷 Version

Package Version
@antv/s2 2.0.0-next.23
@antv/s2-vue 2.0.0-next.14

Sheet Type

🖋 Description

When scrolling the spreadsheet, the return of getMeta function is confusing after extending class MergedCell . It returns data or null .

⌨️ Code Snapshots

export const getTempMergedCell = (
  allVisibleCells: DataCell[],
  sheet?: SpreadSheet,
  cellsInfos: MergedCellInfo[] = [],
): TempMergedCell => {
  const { cellsMeta, cells, invisibleCellInfo } = getVisibleInfo(
    cellsInfos,
    allVisibleCells,
  );
  let viewMeta: ViewMeta | Node | undefined = cellsMeta;
  let mergedAllCells: DataCell[] = cells;
  // some cells are invisible and some cells are visible
  const isPartiallyVisible =
    invisibleCellInfo?.length > 0 &&
    invisibleCellInfo.length < cellsInfos.length;

  // 当 MergedCell 只有部分在可视区域时,在此获取 MergedCell 不在可视区域内的 cells
  if (isPartiallyVisible) {
    const { cells: invisibleCells, cellsMeta: invisibleMeta } =
      getInvisibleInfo(invisibleCellInfo, sheet!);

    viewMeta = viewMeta || invisibleMeta;
    mergedAllCells = cells.concat(invisibleCells); // this is the boob which will explode anytime
  }

  if (!isEmpty(cells) && !viewMeta) {
    // 如果没有指定合并后的文本绘制的位置,默认画在选择的第一个单元格内
    viewMeta = mergedAllCells[0]?.getMeta() as ViewMeta;
  }

  return {
    cells: mergedAllCells,
    viewMeta: viewMeta as ViewMeta,
  };
};

When scolling the spreadsheet, invisibleCells may be any position includes top, bottom, left , right . But here , Simplely add it to the tail. So the viewMeta will be data or null .

mergedAllCells should be sorted by colIndex and rowIndex .

🔗 Reproduce Link

🤔 Steps to Reproduce

😊 Expected Behavior

viewMeta should be data anytimes

😅 Current Behavior

💻 System information

Environment Info
System
Browser