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

fix(table-sheet): 修复明细表 tooltip 展示了错误的汇总数据的问题 #2457

Merged
merged 5 commits into from
Dec 8, 2023
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

Large diffs are not rendered by default.

80 changes: 76 additions & 4 deletions packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('Table Mode Dataset Test', () => {
});

describe('test for query data', () => {
test('getCellData function', () => {
test('#getCellData', () => {
expect(
dataSet.getCellData({
query: { rowIndex: 0 },
Expand All @@ -128,7 +128,7 @@ describe('Table Mode Dataset Test', () => {
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'city',
field: 'city',
},
}),
).toEqual('杭州市');
Expand All @@ -137,7 +137,7 @@ describe('Table Mode Dataset Test', () => {
dataSet.getCellData({
query: {
rowIndex: 2,
col: 'number',
field: 'number',
},
}),
).toEqual(3877);
Expand All @@ -146,10 +146,82 @@ describe('Table Mode Dataset Test', () => {
dataSet.getCellData({
query: {
rowIndex: 5,
col: 'sub_type',
field: 'sub_type',
},
}),
).toEqual('沙发');
});

test('#getMultiData by empty query', () => {
expect(dataSet.getMultiData(null)).toMatchSnapshot();
expect(dataSet.getMultiData(null)).toEqual(dataSet.getMultiData({}));
});

test('#getMultiData by rowIndex query', () => {
expect(
dataSet.getMultiData({
rowIndex: 0,
}),
).toMatchInlineSnapshot(`
Array [
Object {
"city": "杭州市",
"number": 7789,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
]
`);

expect(
dataSet.getMultiData({
rowIndex: -1,
}),
).toMatchSnapshot();
});

test('#getMultiData by field query', () => {
expect(
dataSet.getMultiData({
field: 'city',
}),
).toMatchSnapshot();

expect(
dataSet.getMultiData({
field: 'number',
}),
).toMatchSnapshot();

expect(
dataSet.getMultiData({
field: 'sub_type',
}),
).toMatchSnapshot();
});

test('#getMultiData by field and rowIndex query', () => {
expect(
dataSet.getMultiData({
field: 'city',
rowIndex: 0,
}),
).toEqual(['杭州市']);

expect(
dataSet.getMultiData({
field: 'number',
rowIndex: 2,
}),
).toEqual([3877]);

expect(
dataSet.getMultiData({
field: 'sub_type',
rowIndex: 3,
}),
).toEqual(['桌子']);
});
});
});
16 changes: 8 additions & 8 deletions packages/s2-core/__tests__/unit/dataset/table-dataset-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'city',
field: 'city',
},
}),
).toEqual('杭州市');
Expand All @@ -66,7 +66,7 @@
dataSet.getCellData({
query: {
rowIndex: 2,
col: 'number',
field: 'number',
},
}),
).toEqual(3877);
Expand All @@ -75,7 +75,7 @@
dataSet.getCellData({
query: {
rowIndex: 5,
col: 'sub_type',
field: 'sub_type',
},
}),
).toEqual('沙发');
Expand All @@ -93,7 +93,7 @@
expect(
emptyDataSet.getCellData({
query: {
col: 'sub_type',
field: 'sub_type',
rowIndex: 0,
},
}),
Expand All @@ -116,7 +116,7 @@
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'city',
field: 'city',
},
}),
).toEqual('成都市');
Expand All @@ -136,7 +136,7 @@
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'city',
field: 'city',
},
}),
).toEqual('杭州市');
Expand All @@ -158,7 +158,7 @@
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'city',
field: 'city',
},
}),
).toEqual('成都市');
Expand All @@ -178,7 +178,7 @@
dataSet.getCellData({
query: {
rowIndex: 0,
col: 'number',
field: 'number',
},
}),
).toEqual(245);
Expand All @@ -196,7 +196,7 @@
{
sortFieldId,
sortMethod,
sortFunc: ({ data, sortMethod, sortFieldId }) => {

Check warning on line 199 in packages/s2-core/__tests__/unit/dataset/table-dataset-spec.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'sortMethod' is already declared in the upper scope

Check warning on line 199 in packages/s2-core/__tests__/unit/dataset/table-dataset-spec.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'sortFieldId' is already declared in the upper scope
return orderBy(
data,
[sortFieldId],
Expand Down
154 changes: 154 additions & 0 deletions packages/s2-core/__tests__/unit/utils/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
createFakeSpreadSheet,
createMockCellInfo,
createPivotSheet,
createTableSheet,
getContainer,
} from 'tests/util/helpers';
import type { BBox } from '@antv/g-canvas';
Expand Down Expand Up @@ -795,6 +796,159 @@ describe('Tooltip Utils Tests', () => {
},
);
});

describe('Tooltip Get Data Tests For TableSheet', () => {
beforeEach(() => {
s2 = createTableSheet(
{ showSeriesNumber: true },
{ useSimpleData: false },
);
s2.render();
});

afterEach(() => {
s2.destroy();
});

test('should get correctly summaries of selected col cell', () => {
const typeColCell = s2.getColumnLeafNodes()[1].belongsCell;
const subTypeColCell = s2.getColumnLeafNodes()[2].belongsCell;

expect(getMockTooltipData(typeColCell)).toMatchInlineSnapshot(`
Object {
"description": "类别说明。。",
"details": null,
"headInfo": null,
"infos": undefined,
"interpretation": undefined,
"name": undefined,
"summaries": Array [
Object {
"name": "",
"selectedData": Array [
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"家具",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
"办公用品",
],
"value": "",
},
],
"tips": undefined,
}
`);
expect(getMockTooltipData(subTypeColCell)).toMatchInlineSnapshot(`
Object {
"description": "子类别说明。。",
"details": null,
"headInfo": null,
"infos": undefined,
"interpretation": undefined,
"name": undefined,
"summaries": Array [
Object {
"name": "",
"selectedData": Array [
"桌子",
"桌子",
"桌子",
"桌子",
"沙发",
"沙发",
"沙发",
"沙发",
"笔",
"笔",
"笔",
"笔",
"纸张",
"纸张",
"纸张",
"纸张",
"桌子",
"桌子",
"桌子",
"桌子",
"沙发",
"沙发",
"沙发",
"沙发",
"笔",
"笔",
"笔",
"笔",
"纸张",
"纸张",
"纸张",
"纸张",
],
"value": "",
},
],
"tips": undefined,
}
`);
});

test('should get correctly summaries of selected series number cell', () => {
const seriesCell = s2.interaction.getPanelGroupAllDataCells()[0];

expect(getMockTooltipData(seriesCell)).toMatchInlineSnapshot(`
Object {
"description": undefined,
"details": null,
"headInfo": null,
"infos": undefined,
"interpretation": undefined,
"name": undefined,
"summaries": Array [
Object {
"name": "",
"selectedData": Array [
Object {
"city": "杭州市",
"number": 7789,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
],
"value": "",
},
],
"tips": undefined,
}
`);
});
});
});

test('should set container style', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/src/cell/base-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'lodash';
import {
CellTypes,
ELLIPSIS_SYMBOL,
EMPTY_FIELD_VALUE,
InteractionStateName,
SHAPE_ATTRS_MAP,
Expand Down Expand Up @@ -135,6 +136,11 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group {
return this.actualText;
}

// TODO: 2.0 使用 G 内置的方法
public isTextOverflowing() {
return this.getActualText().includes(ELLIPSIS_SYMBOL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.getActualText()可能是undefined,这里includes会报错影响功能

}

public getFieldValue() {
const { formattedValue } = this.getFormattedFieldValue();

Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import {
getValueRangeState,
setValueRangeState,
} from '../utils/condition/state-controller';
import type { CellMeta, RowData } from '../common';
import type { CellMeta, RowData, ViewMeta } from '../common';
import { generateExtraFieldMeta } from '../utils/dataset/pivot-data-set';
import type { Indexes } from '../utils/indexes';
import type { Node } from '../facet/layout/node';
import type { CellDataParams, DataType } from './index';

export abstract class BaseDataSet {
Expand Down Expand Up @@ -228,7 +229,6 @@ export abstract class BaseDataSet {

/**
* get a row cells data including cell
* @param cells
*/
public abstract getRowData(cells: CellMeta): RowData;
public abstract getRowData(cellMeta: CellMeta | ViewMeta | Node): RowData;
}
Loading
Loading