Skip to content

Commit

Permalink
fix(table-sheet): 明细表数据为空时错误的展示一行空数据 close #2255 (#2357)
Browse files Browse the repository at this point in the history
* fix(table-sheet): 明细表数据为空时错误的展示一行空数据 close #2255

* test: 修复测试

* test: 修复测试

* fix: 重命名

---------

Co-authored-by: Wenjun Xu <[email protected]>
  • Loading branch information
lijinke666 and wjgogogo authored Oct 11, 2023
1 parent b719c8a commit 7751c49
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describe('Pivot Dataset Test', () => {
getDimensionsWithoutPathPre(sortedDimensionValues[EXTRA_FIELD]),
).toEqual(['number', 'number', 'number', 'number']);
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ describe('Table Mode Dataset Test', () => {
test('should get correct meta data', () => {
expect(dataSet.meta).toEqual(expect.objectContaining([]));
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { DataCell, DEFAULT_STYLE, type Fields, Node } from '@/index';
import { getFrozenLeafNodesCount } from '@/facet/utils';
import { SpreadSheet } from '@/sheet-type';
import { getTheme } from '@/theme';

const actualDataSet = jest.requireActual(
'@/data-set/base-data-set',
).BaseDataSet;

jest.mock('@/sheet-type', () => {
const container = new Canvas({
width: 100,
Expand Down Expand Up @@ -59,6 +61,9 @@ jest.mock('@/sheet-type', () => {
interaction: {
clearHoverTimer: jest.fn(),
},
dataSet: {
isEmpty: jest.fn(),
},
};
}),
};
Expand All @@ -77,6 +82,7 @@ jest.mock('@/data-set/table-data-set', () => {
getCellData: () => 1,
getFieldMeta: jest.fn(),
getFieldFormatter: actualDataSet.prototype.getFieldFormatter,
isEmpty: jest.fn(),
};
}),
};
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class TableColCell extends ColCell {
y,
};
}

return {
x: position.x + x - scrollX,
y: position.y + y,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
find,
get,
identity,
isEmpty,
isNil,
map,
max,
Expand Down Expand Up @@ -117,6 +118,10 @@ export abstract class BaseDataSet {
return this.displayData;
}

public isEmpty() {
return isEmpty(this.getDisplayDataSet());
}

public getValueRangeByField(field: string): ValueRange {
const cacheRange = getValueRangeState(this.spreadsheet, field);
if (cacheRange) {
Expand Down
21 changes: 12 additions & 9 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
getFrozenRowsForGrid,
getRowsForGrid,
} from '../utils/grid';
import type { PanelIndexes } from '../utils/indexes';
import type { Indexes, PanelIndexes } from '../utils/indexes';
import { getValidFrozenOptions } from '../utils/layout/frozen';
import { BaseFacet } from './base-facet';
import { CornerBBox } from './bbox/cornerBBox';
Expand Down Expand Up @@ -1129,14 +1129,17 @@ export class TableFacet extends BaseFacet {
}
}

const indexes = calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);
// https://github.com/antvis/S2/issues/2255
const indexes = this.spreadsheet.dataSet.isEmpty()
? ([] as unknown as Indexes)
: calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);

this.panelScrollGroupIndexes = indexes;

Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/sheet-type/table-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class TableSheet extends SpreadSheet {
}
return new TableDataCell(facet, this);
};

return {
...this.options,
...fields,
Expand Down
1 change: 1 addition & 0 deletions s2-site/docs/api/basic-class/base-data-set.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ s2.dataSet.getFieldName('type')
| getCellData | 获取单个的单元格数据 | (params: [CellDataParams](#celldataparams)) => [DataType[]](#datatype) | |
| getMultiData | 获取批量的单元格数据 | (query: [DataType](#datatype), isTotals?: boolean, isRow?: boolean, drillDownFields?: string[]) => [DataType[]](#datatype) | |
| moreThanOneValue | 是否超过 1 个数值 | () => [ViewMeta](#viewmeta) | |
| isEmpty | 是否为空数据集 | () => `boolean` | `@antv/s2-v1.51.1` |

### DataType

Expand Down

1 comment on commit 7751c49

@vercel
Copy link

@vercel vercel bot commented on 7751c49 Oct 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2-antv-s2.vercel.app
antvis-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app

Please sign in to comment.