Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 移除已废弃的方法和逻辑 & 优化文档 #2566

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const expectScrollBrush = async (
s2.on(S2Event.GLOBAL_SELECTED, selectedFn);
s2.on(S2Event.DATA_CELL_BRUSH_SELECTION, dataCellBrushSelectionFn);

// TODO: g5.0 异步渲染,第一时刻底层base-brush可能无法通过elementsFromPointSync取到元素
// g5.0 异步渲染,第一时刻底层 base-brush 可能无法通过 elementsFromPointSync 取到元素
await sleep(50);

s2.emit(mouseDownEventType, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ describe('Interaction Event Controller Tests', () => {
OriginEventType.POINTER_UP,
OriginEventType.MOUSE_OUT,
GEventType.RIGHT_MOUSE_UP,
OriginEventType.DOUBLE_CLICK,
OriginEventType.CLICK,
OriginEventType.TOUCH_START,
];
Expand Down
75 changes: 0 additions & 75 deletions packages/s2-core/__tests__/unit/utils/text-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { createPivotSheet } from 'tests/util/helpers';
import type { TextTheme } from '../../../src/common';
import { ELLIPSIS_SYMBOL } from '@/common';
import {
getEllipsisText,
getEllipsisTextInner,
isUpDataValue,
getCellWidth,
getEmptyPlaceholder,
Expand Down Expand Up @@ -31,88 +29,15 @@ describe('Text Utils Tests', () => {
).measureTextWidth;
});

test('should get correct text', () => {
const text = getEllipsisText({
measureTextWidth,
text: '12',
maxWidth: 200,
placeholder: '--',
});

expect(text).toEqual('12');
});

test('should get ellipsis symbol', () => {
expect(ELLIPSIS_SYMBOL).toEqual('...');
});

test('should get correct text ellipsis', () => {
const text = getEllipsisText({
measureTextWidth,
text: '12121212121212121212',
maxWidth: 20,
placeholder: '--',
});

expect(text).toEndWith(ELLIPSIS_SYMBOL);
expect(text.length).toBeLessThanOrEqual(5);
});

test('should get correct placeholder text with ""', () => {
const text = getEllipsisText({
measureTextWidth,
text: '',
maxWidth: 20,
placeholder: '--',
});

expect(text).toEqual('--');
});

test('should get correct placeholder text with 0', () => {
const text = getEllipsisText({
measureTextWidth,
text: 0 as unknown as string,
maxWidth: 20,
placeholder: '--',
});

expect(text).toEqual('0');
});

test('should get correct placeholder text with null', () => {
const text = getEllipsisText({
measureTextWidth,
text: null,
maxWidth: 20,
placeholder: '--',
});

expect(text).toEqual('--');
});

test('should get correct ellipsis text', () => {
const text = getEllipsisText({
measureTextWidth,
text: '长度测试',
maxWidth: 24,
});

expect(text).toEndWith(ELLIPSIS_SYMBOL);
expect(text.length).toBeLessThanOrEqual(4);
});

test('should get correct text width', () => {
const width = measureTextWidth('test', font);

expect(Math.floor(width)).toEqual(isHD ? 21 : 16);
});

test('should get correct ellipsis text inner', () => {
const text = getEllipsisTextInner(measureTextWidth, 'test', 15, font);

expect(text).toEqual('t...');
});
});

test.each`
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class DataCell extends BaseCell<ViewMeta> {

switch (stateName) {
case InteractionStateName.SELECTED:
case InteractionStateName.BRUSH_SELECTED:
this.handleSelect(cells);
break;
case InteractionStateName.HOVER_FOCUS:
Expand Down Expand Up @@ -364,7 +365,6 @@ export class DataCell extends BaseCell<ViewMeta> {
const rowMeta = this.spreadsheet.dataSet.getFieldMeta(rowId!);
const fieldId = rowMeta ? rowId : valueField;
const formatter = this.spreadsheet.dataSet.getFieldFormatter(fieldId!);
// TODO: 这里只用 formatter(fieldValue, this.meta) 即可, 为了保持兼容, 暂时在第三个参入传入 meta 信息
const formattedValue =
displayFormattedValue ?? formatter(fieldValue, data, this.meta);

Expand Down
1 change: 0 additions & 1 deletion packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,6 @@ export abstract class BaseFacet {
scrollBar?.thumbHorizontalMinSize!,
);

// TODO abstract
this.hScrollBar = new ScrollBar({
isHorizontal: true,
trackLen: finalWidth,
Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ const addTotals = (
) => {
const totalsConfig = spreadsheet.getTotalsConfig(currentField);

/*
/**
* tree mode only has grand totals, but if there are subTotals configs,
* it will display in cross-area cell
* TODO valueInCol = false and one or more values
*/
if (totalsConfig?.showGrandTotals) {
const func = totalsConfig.reverseGrandTotalsLayout ? 'unshift' : 'push';
Expand Down Expand Up @@ -95,7 +94,8 @@ export const buildRowTreeHierarchy = (params: TreeHeaderParams) => {

const { collapseFields, collapseAll, expandDepth } =
spreadsheet.options.style?.rowCell!;
/*

/**
* 行头收起/展开配置优先级:collapseFields -> expandDepth -> collapseAll
* 优先从读取 collapseFields 中的特定 node 的值
* 如果没有特定配置,再查看是否配置了层级展开配置,
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/facet/layout/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Node {
// node height
public height = 0;

// cell index in layout list(TODO What's use for?)
// cell index in layout list
public colIndex = -1;

// node's level in tree hierarchy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ export class DataCellBrushSelection extends BaseBrushSelection {

this.spreadsheet.interaction.changeState({
cells: selectedCellMetas,
// TODO: 怕上层有直接消费 stateName, 暂时保留, 2.0 版本改成 InteractionStateName.BRUSH_SELECTED
stateName: InteractionStateName.SELECTED,
stateName: InteractionStateName.BRUSH_SELECTED,
onUpdateCells: afterSelectDataCells,
});

Expand Down
2 changes: 0 additions & 2 deletions packages/s2-core/src/interaction/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export class EventController {
this.addCanvasEvent(OriginEventType.POINTER_MOVE, this.onCanvasMousemove);
this.addCanvasEvent(OriginEventType.MOUSE_OUT, this.onCanvasMouseout);
this.addCanvasEvent(OriginEventType.POINTER_UP, this.onCanvasMouseup);
// TODO: g5.0 目前没支持 dbclick 事件
this.addCanvasEvent(OriginEventType.DOUBLE_CLICK, this.onCanvasDoubleClick);
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
this.addCanvasEvent(GEventType.RIGHT_MOUSE_UP, this.onCanvasContextMenu);

// spreadsheet events
Expand Down
10 changes: 2 additions & 8 deletions packages/s2-core/src/utils/cell/cell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { LineStyleProps } from '@antv/g';
import { isEmpty } from 'lodash';
import type { SimpleBBox } from '../../engine';
import {
CellClipBox,
Expand Down Expand Up @@ -200,11 +199,6 @@ export const getBorderPositionAndStyle = (
borderDash,
} = style;

// TODO: 如果是空数组 G 底层绘制会报错
const lineDash: LineStyleProps['lineDash'] = isEmpty(borderDash)
? ''
: borderDash;

const borderStyle: Partial<LineStyleProps> = [
CellBorderPosition.TOP,
CellBorderPosition.BOTTOM,
Expand All @@ -213,13 +207,13 @@ export const getBorderPositionAndStyle = (
lineWidth: horizontalBorderWidth,
stroke: horizontalBorderColor,
strokeOpacity: horizontalBorderColorOpacity,
lineDash,
lineDash: borderDash,
}
: {
lineWidth: verticalBorderWidth,
stroke: verticalBorderColor,
strokeOpacity: verticalBorderColorOpacity,
lineDash,
lineDash: borderDash,
};

let x1 = 0;
Expand Down
23 changes: 4 additions & 19 deletions packages/s2-core/src/utils/export/copy/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {
} from '../../../common/interface/export';
import { getBrushHeaderCopyable } from './pivot-header-copy';
import {
processSelectedAllPivot,
processSelectedAllPivotAsync,
asyncProcessSelectedAllPivot,
processSelectedPivotByDataCell,
processSelectedPivotByHeader,
} from './pivot-data-cell-copy';
import {
processSelectedAllTable,
asyncProcessSelectedAllTable,
processSelectedTableByDataCell,
processSelectedTableByHeader,
Expand Down Expand Up @@ -206,27 +204,14 @@ export const getSelectedData = (spreadsheet: SpreadSheet): CopyableList => {
return data!;
};

// 全量导出使用
export const processAllSelected = (params: CopyAllDataParams): CopyableList => {
const { sheetInstance } = params;

if (sheetInstance.isPivotMode()) {
const result = processSelectedAllPivot(params);

return result;
}

return processSelectedAllTable(params);
};

// 异步全量导出使用
export const processAllSelectedAsync = (
// 异步全量导出
export const asyncProcessAllSelected = (
params: CopyAllDataParams,
): Promise<CopyableList> => {
const { sheetInstance } = params;

if (sheetInstance.isPivotMode()) {
return processSelectedAllPivotAsync(params);
return asyncProcessSelectedAllPivot(params);
}

return asyncProcessSelectedAllTable(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export const processSelectedAllPivot = (
return pivotDataCellCopy.getPivotAllCopyData();
};

export const processSelectedAllPivotAsync = (
export const asyncProcessSelectedAllPivot = (
params: CopyAllDataParams,
): Promise<CopyableList> => {
const { sheetInstance, split, formatOptions, customTransformer } = params;
Expand Down
32 changes: 3 additions & 29 deletions packages/s2-core/src/utils/export/copy/table-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ class TableDataCellCopy extends BaseDataCellCopy {
/**
* allSelected: false 时,明细表点击 行头/列头 进行复制逻辑
* allSelected: true 时,明细表点击 全选 进行复制逻辑
* @param {boolean} allSelected
* @return {CopyableList}
* @deprecated 后续将废弃,使用 asyncProcessSelectedTable 替代
*/
processSelectedTable(allSelected = false): CopyableList {
Expand Down Expand Up @@ -239,47 +237,23 @@ class TableDataCellCopy extends BaseDataCellCopy {
/**
* 明细表点击行头进行复制逻辑
* @param {SpreadSheet} spreadsheet
* @param {CellMeta[]} selectedRowsOrCols
* @param {CellMeta[]} selectedHeaders
* @return {CopyableList}
*/
export const processSelectedTableByHeader = (
spreadsheet: SpreadSheet,
selectedRowsOrCols: CellMeta[],
selectedHeaders: CellMeta[],
): CopyableList => {
const tableDataCellCopy = new TableDataCellCopy({
spreadsheet,
config: {
selectedCells: selectedRowsOrCols,
selectedCells: selectedHeaders,
},
});

return tableDataCellCopy.processSelectedTable();
};

/**
* 导出全部数据
* @param {CopyAllDataParams} params
* @return {CopyableList}
* @deprecated 后续将废弃,使用 asyncProcessSelectedAllTable 替代
*/
export const processSelectedAllTable = (
params: CopyAllDataParams,
): CopyableList => {
const { sheetInstance, split, formatOptions, customTransformer } = params;
const tableDataCellCopy = new TableDataCellCopy({
spreadsheet: sheetInstance,
config: {
selectedCells: [],
separator: split,
formatOptions,
customTransformer,
},
isExport: true,
});

return tableDataCellCopy.processSelectedTable(true);
};

// 导出全部数据
export const asyncProcessSelectedAllTable = (
params: CopyAllDataParams,
Expand Down
16 changes: 2 additions & 14 deletions packages/s2-core/src/utils/export/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Copyable,
type CopyableItem,
} from '../../common/interface/export';
import { processAllSelected, processAllSelectedAsync } from './copy/core';
import { asyncProcessAllSelected } from './copy/core';

/**
* 同步复制
Expand Down Expand Up @@ -115,18 +115,6 @@ export const download = (dataString: string, fileName: string) => {
}
};

/**
* 同步获取文本数据
* @param params CopyAllDataParams
* @deprecated 后续将废弃方法,将使用 asyncGetAllPlainData
*/

export const getAllPlainData = (params: CopyAllDataParams) => {
const result = processAllSelected(params);

return result[0].content;
};

/**
* 异步获取文本数据
* @example
Expand All @@ -137,7 +125,7 @@ export const getAllPlainData = (params: CopyAllDataParams) => {
});
*/
export const asyncGetAllPlainData = async (params: CopyAllDataParams) => {
const result = await processAllSelectedAsync(params);
const result = await asyncProcessAllSelected(params);

return result[0].content;
};
Loading
Loading