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: 增加对自定义行列头总计、小计节点和组内排序的支持,修复明细表自定义列头 icon 问题 icon closes #2898 #2893 #2934

Merged
merged 18 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 51 additions & 1 deletion packages/s2-core/__tests__/spreadsheet/custom-grid-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { pick } from 'lodash';
import { CustomGridData } from 'tests/data/data-custom-grid';
import { waitForRender } from 'tests/util';
import { getContainer } from 'tests/util/helpers';
import { KEY_GROUP_COL_RESIZE_AREA } from '../../src/common/constant';
import {
KEY_GROUP_COL_RESIZE_AREA,
VALUE_FIELD,
} from '../../src/common/constant';
import { Aggregation } from '../../src/common/interface/basic';
import { CustomGridPivotDataSet } from '../../src/data-set/custom-grid-pivot-data-set';
import {
customColGridSimpleFields,
Expand Down Expand Up @@ -538,5 +542,51 @@ describe('SpreadSheet Custom Grid Tests', () => {
s2.facet.getColNodes().some((node) => node.isCollapsed),
).toBeFalsy();
});

// https://github.com/antvis/S2/issues/2893
test.each(['tree', 'grid'])(
'should render correct total node for %s mode',
async (hierarchyType) => {
s2.setOptions({
hierarchyType,
totals: {
row: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['type'],
calcGrandTotals: {
aggregation: Aggregation.SUM,
},
calcSubTotals: {
aggregation: Aggregation.SUM,
},
},
col: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['type'],
calcGrandTotals: {
aggregation: Aggregation.SUM,
},
calcSubTotals: {
aggregation: Aggregation.SUM,
},
},
},
});

await s2.render(false);

expect(s2.facet.getRowGrandTotalsNodes()).toHaveLength(1);
expect(s2.facet.getColGrandTotalsNodes()).toHaveLength(0);

expect(s2.facet.getCellMeta(0, 0).data[VALUE_FIELD]).toEqual(24);
expect(s2.facet.getCellMeta(0, 1).data[VALUE_FIELD]).toEqual(10);
},
);
});
});
25 changes: 25 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/custom-table-col-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,29 @@ describe('TableSheet Custom Tests', () => {

expect(resizeAreaList.length).toEqual(8);
});

test.each([
{ showDefaultHeaderActionIcon: false },
{ showDefaultHeaderActionIcon: true },
])(
'should render correctly sort action icon in value cell for custom col header with %o',
async (options) => {
s2.setOptions(options);

await s2.render(false);

const fields = s2.facet
.getColCells()
.filter((cell) => {
return cell.getActionIcons().length >= 1;
})
.map((cell) => cell.getMeta().field);

expect(fields).toEqual(
options.showDefaultHeaderActionIcon
? ['province', 'city', 'type', 'price', 'number']
: [],
);
},
);
});
5 changes: 0 additions & 5 deletions packages/s2-core/__tests__/spreadsheet/custom-tree-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { S2DataConfig, S2Options } from '@/common/interface';
import { PivotSheet, SpreadSheet } from '@/sheet-type';
import { getContainer } from 'tests/util/helpers';
import { CustomTreePivotDataSet } from '../../src';
import type { HeaderCell } from '../../src/cell/header-cell';
import { customRowGridSimpleFields } from '../data/custom-grid-simple-fields';
import { customTreeNodes } from '../data/custom-tree-nodes';
Expand Down Expand Up @@ -81,10 +80,6 @@ describe('SpreadSheet Custom Tree Tests', () => {
expect(s2.dataSet.fields.valueInCols).toBeFalsy();
});

test('should use custom tree pivot dataSet', () => {
expect(s2.dataSet).toBeInstanceOf(CustomTreePivotDataSet);
});

test('should get correctly dataset fields', () => {
expect(s2.dataSet.fields).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
*/
import { EXTRA_FIELD, ORIGIN_FIELD } from '@/common/constant';
import type { S2DataConfig } from '@/common/interface';
import { CustomTreePivotDataSet } from '@/data-set/custom-tree-pivot-data-set';
import { CustomGridPivotDataSet } from '@/data-set/custom-grid-pivot-data-set';
import { PivotSheet } from '@/sheet-type';
import { get } from 'lodash';
import { customTreeNodes } from 'tests/data/custom-tree-nodes';
import { CustomTreeData } from 'tests/data/data-custom-tree';
import { Store } from '../../../src';

jest.mock('@/sheet-type');

jest.mock('@/interaction/root');

const MockPivotSheet = PivotSheet as unknown as jest.Mock<PivotSheet>;

describe('Custom Tree Dataset Test', () => {
describe('Custom Grid Dataset Test', () => {
const values = [
'measure-a',
'measure-b',
Expand All @@ -35,14 +36,21 @@ describe('Custom Tree Dataset Test', () => {
},
};

const mockSheet = new MockPivotSheet();
const dataSet = new CustomTreePivotDataSet(mockSheet);
let dataSet: CustomGridPivotDataSet;

dataSet.setDataCfg(dataCfg);
beforeEach(() => {
const mockSheet = new MockPivotSheet();

mockSheet.isCustomRowFields = () => true;
mockSheet.store = new Store();

dataSet = new CustomGridPivotDataSet(mockSheet);
dataSet.setDataCfg(dataCfg);
});

describe('test base dataset structure', () => {
test('should get correct field data', () => {
expect(dataSet.fields.rows).toEqual([EXTRA_FIELD]);
expect(dataSet.fields.rows).toEqual([...customTreeNodes, EXTRA_FIELD]);
expect(dataSet.fields.columns).toEqual(['type', 'sub_type']);
expect(dataSet.fields.values).toEqual(values);
});
Expand Down
11 changes: 10 additions & 1 deletion packages/s2-core/src/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ export class TableColCell extends ColCell {
}

protected showSortIcon() {
return this.spreadsheet.options.showDefaultHeaderActionIcon;
const { extra } = this.meta;
const { options } = this.spreadsheet;
const { showDefaultHeaderActionIcon } = options;

if (!extra?.isCustomNode) {
return showDefaultHeaderActionIcon;
}

// 自定义列头时, 只在叶子节点展示
return showDefaultHeaderActionIcon && this.meta.isLeaf;
}

protected getTextStyle() {
Expand Down
8 changes: 3 additions & 5 deletions packages/s2-core/src/data-set/custom-grid-pivot-data-set.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { EXTRA_FIELD, i18n } from '../common';
import type { S2DataConfig } from '../common/interface';
import { CustomTreePivotDataSet } from './custom-tree-pivot-data-set';
import { PivotDataSet } from './pivot-data-set';

export class CustomGridPivotDataSet extends CustomTreePivotDataSet {
export class CustomGridPivotDataSet extends PivotDataSet {
processDataCfg(dataCfg: S2DataConfig): S2DataConfig {
const valueInCols = !this.spreadsheet.isCustomRowFields();
const originalRows = dataCfg.fields.rows || [];
const rows = valueInCols
? [...originalRows]
: [...originalRows, EXTRA_FIELD];
const rows = valueInCols ? originalRows : [...originalRows, EXTRA_FIELD];
const meta = this.processMeta(dataCfg.meta!, i18n('数值'));

return {
Expand Down
64 changes: 0 additions & 64 deletions packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts

This file was deleted.

9 changes: 1 addition & 8 deletions packages/s2-core/src/data-set/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { BaseDataSet } from './base-data-set';
import { CustomGridPivotDataSet } from './custom-grid-pivot-data-set';
import { CustomTreePivotDataSet } from './custom-tree-pivot-data-set';
import { PivotDataSet } from './pivot-data-set';
import { TableDataSet } from './table-data-set';

export { CellData } from './cell-data';

export {
BaseDataSet,
CustomGridPivotDataSet,
CustomTreePivotDataSet,
PivotDataSet,
TableDataSet,
};
export { BaseDataSet, CustomGridPivotDataSet, PivotDataSet, TableDataSet };

export * from './interface';
Loading
Loading