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: 交叉表支持冻结首行能力 #2416

Merged
merged 4 commits into from
Dec 4, 2023
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
9 changes: 7 additions & 2 deletions packages/s2-core/__tests__/bugs/issue-1191-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import * as mockDataConfig from 'tests/data/simple-data.json';
import { getContainer } from 'tests/util/helpers';
import type { Group } from '@antv/g-canvas';
import type { S2DataConfig, S2Options } from '@/common/interface';
import { PivotSheet, SpreadSheet } from '@/sheet-type';

Expand Down Expand Up @@ -76,15 +77,19 @@ describe('Link Field Tests', () => {

test('province row cell should use link field style', () => {
// 浙江省对应 cell
const province = s2.facet.rowHeader.getChildByIndex(0);
const province = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getChildByIndex(0);
// @ts-ignore
expect(province.textShape.attr('fill')).toEqual('red');
// @ts-ignore
expect(province.linkFieldShape).toBeDefined();
});
test('city row cell should not use link field style', () => {
// 义乌对应 cell
const city = s2.facet.rowHeader.getChildByIndex(1);
const city = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getChildByIndex(1);
// @ts-ignore
expect(city.textShape.attr('fill')).not.toEqual('red');
// @ts-ignore
Expand Down
5 changes: 3 additions & 2 deletions packages/s2-core/__tests__/bugs/issue-1201-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* https://github.com/antvis/S2/issues/1201
* fillOpacity
*/
import type { IGroup } from '@antv/g-canvas';
import type { Group, IGroup } from '@antv/g-canvas';
import { getContainer } from '../util/helpers';
import * as mockDataConfig from '../data/data-issue-292.json';
import { PivotSheet } from '@/sheet-type';
Expand Down Expand Up @@ -45,7 +45,8 @@ describe('background color opacity test', () => {
expect(cornerCell.backgroundShape.attr('fillOpacity')).toEqual(0.1);

// row cell
const rowCell = s2.facet.rowHeader.getChildByIndex(0);
const rowHeaderScrollGroup = s2.facet.rowHeader.getChildByIndex(0) as Group;
const rowCell = rowHeaderScrollGroup.getFirst();
// @ts-ignore
expect(rowCell.backgroundShape.attr('fillOpacity')).toEqual(0.2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Object {
"linkTextFill": "#326EF4",
"opacity": 1,
"textAlign": "center",
"textBaseline": "middle",
"textBaseline": "top",
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
},
"text": Object {
"fill": "#000000",
Expand Down
21 changes: 15 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/theme-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jest/expect-expect */
import { createPivotSheet } from 'tests/util/helpers';
import type { IGroup, ShapeAttrs } from '@antv/g-canvas';
import type { Group, IGroup, ShapeAttrs } from '@antv/g-canvas';
import { get } from 'lodash';
import type {
TextBaseline,
Expand Down Expand Up @@ -157,7 +157,9 @@ describe('SpreadSheet Theme Tests', () => {
},
});
s2.render();
const rowCell = s2.facet.rowHeader.getFirst() as RowCell;
const rowCell = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getFirst() as RowCell;
const actionIconCfg: ShapeAttrs = get(rowCell, 'actionIcons.[0].cfg');

expect(actionIconCfg.fill).toEqual(iconInfo.fill);
Expand Down Expand Up @@ -191,7 +193,9 @@ describe('SpreadSheet Theme Tests', () => {
s2.setThemeCfg(getRowCellThemeCfg(align));
s2.render();

const rowCell = s2.facet.rowHeader.getFirst() as RowCell;
const rowCell = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getFirst() as RowCell;

const rowCellWidth = get(rowCell, 'meta.width');
const actionIconCfg: ShapeAttrs = get(rowCell, 'actionIcons.[0].cfg');
Expand Down Expand Up @@ -458,13 +462,18 @@ describe('SpreadSheet Theme Tests', () => {

s2.render();

const rowCell = s2.facet.rowHeader.getChildByIndex(0) as IGroup; // 浙江省
const rowCell = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getFirst() as IGroup; // 浙江省
const textOfRowCell = getTextShape(rowCell);

const seriesCell = s2.facet.rowIndexHeader.getChildByIndex(3) as IGroup; // 序号1
const seriesCell = (
s2.facet.rowIndexHeader.getChildByIndex(0) as Group
).getFirst() as IGroup; // 序号1
const textOfSeriesCell = getTextShape(seriesCell);

expect(textOfRowCell.attr('textBaseline')).toEqual(textBaseline);
expect(textOfSeriesCell.attr('textBaseline')).toEqual('top');
expect(textOfSeriesCell.attr('textBaseline')).toEqual(textBaseline);
expect(textOfRowCell.attr('y')).toEqual(textOfSeriesCell.attr('y'));
},
);
Expand Down
21 changes: 14 additions & 7 deletions packages/s2-core/__tests__/unit/cell/row-cell-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { get } from 'lodash';
import { createPivotSheet } from 'tests/util/helpers';
import type { RowCell } from '@antv/s2';
import type { Group } from '@antv/g-canvas';
import type { SpreadSheet } from '@/sheet-type';
import type { TextAlign } from '@/common';

Expand Down Expand Up @@ -34,7 +35,9 @@ describe('Row Cell Tests', () => {
});
s2.render();

const provinceCell = s2.facet.rowHeader.getChildByIndex(0) as RowCell;
const provinceCell = (
s2.facet.rowHeader.getChildByIndex(0) as Group
).getChildByIndex(0) as RowCell;
const { minX, maxX } = (provinceCell as any).linkFieldShape.getBBox();

// 宽度相当
Expand Down Expand Up @@ -67,7 +70,8 @@ describe('Row Cell Tests', () => {
});
test('should draw right condition text shape', () => {
s2.render();
const rowCell = s2.facet.rowHeader.getChildByIndex(1);
const scrollGroup = s2.facet.rowHeader.getChildByIndex(0) as Group;
const rowCell = scrollGroup.getChildByIndex(1);
expect(get(rowCell, 'textShape.attrs.fill')).toEqual('#5083F5');
});

Expand All @@ -88,7 +92,8 @@ describe('Row Cell Tests', () => {
},
});
s2.render();
const rowCell = s2.facet.rowHeader.getChildByIndex(1);
const scrollRowGroup = s2.facet.rowHeader.getChildByIndex(0) as Group;
const rowCell = scrollRowGroup.getChildByIndex(1);
expect(get(rowCell, 'conditionIconShape.cfg.name')).toEqual('CellUp');
expect(get(rowCell, 'conditionIconShape.cfg.fill')).toEqual('red');
});
Expand All @@ -109,7 +114,8 @@ describe('Row Cell Tests', () => {
},
});
s2.render();
const rowCell = s2.facet.rowHeader.getChildByIndex(0);
const scrollGroup = s2.facet.rowHeader.getChildByIndex(0) as Group;
const rowCell = scrollGroup.getChildByIndex(0);
expect(get(rowCell, 'backgroundShape.attrs.fill')).toEqual('#F7B46F');
});
});
Expand All @@ -135,9 +141,10 @@ describe('Row Cell Tests', () => {
});
s2.render();
test('should draw right condition background shape', () => {
const rowCell0 = s2.facet.rowHeader.getChildByIndex(0);
const rowCell1 = s2.facet.rowHeader.getChildByIndex(1);
const rowCell2 = s2.facet.rowHeader.getChildByIndex(2);
const scrollGroup = s2.facet.rowHeader.getChildByIndex(0) as Group;
const rowCell0 = scrollGroup.getChildByIndex(0);
const rowCell1 = scrollGroup.getChildByIndex(1);
const rowCell2 = scrollGroup.getChildByIndex(2);
expect(get(rowCell0, 'actualText')).toEqual('浙江');
expect(get(rowCell0, 'backgroundShape.attrs.fill')).toEqual(defaultColor);
expect(get(rowCell1, 'actualText')).toEqual('义乌');
Expand Down
69 changes: 69 additions & 0 deletions packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { createPivotSheet } from 'tests/util/helpers';
import { get } from 'lodash';
import { DEFAULT_OPTIONS } from '@/common';

import { FrozenRowCell, SeriesNumberCell } from '@/cell';
import { PivotRowHeader } from '@/facet/header';
import { SeriesNumberHeader } from '@/facet/header/series-number';

const s2 = createPivotSheet(
{
...DEFAULT_OPTIONS,
frozenFirstRowPivot: true,
totals: { row: { showGrandTotals: true, reverseLayout: true } },
showSeriesNumber: true,
},
{ useSimpleData: false },
);
describe('Frozen Row Header Test', () => {
test.each(['grid', 'tree'])(
'frozen row header group api',
(hierarchyType: 'grid' | 'tree') => {
s2.setOptions({ hierarchyType });
s2.render();
const rowHeader: PivotRowHeader = s2.facet.rowHeader as PivotRowHeader;

expect(rowHeader instanceof PivotRowHeader).toBeTrue();
expect(rowHeader.frozenHeadGroup).toBeTruthy();
expect(rowHeader.scrollGroup).toBeTruthy();

expect(rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1);
const frozenRowCell = rowHeader.frozenHeadGroup.getChildren()[0];

expect(frozenRowCell instanceof FrozenRowCell).toBeTrue();
expect(get(frozenRowCell, 'meta.height')).toEqual(30);

expect(rowHeader.scrollGroup.getChildren()).toHaveLength(10);
const scrollCell = rowHeader.scrollGroup.getChildren()[0];

expect(scrollCell instanceof FrozenRowCell).toBeTrue();
expect(get(frozenRowCell, 'meta.height')).toEqual(30);

expect(rowHeader.getFrozenFirstRowHeight()).toBe(30);
},
);
});

describe('Frozen Series Number Test', () => {
test.each(['grid', 'tree'])(
'series number test',
(hierarchyType: 'grid' | 'tree') => {
s2.setOptions({ hierarchyType });
s2.render();
const rowIndexHeader: SeriesNumberHeader = s2.facet
.rowIndexHeader as SeriesNumberHeader;
expect(rowIndexHeader instanceof SeriesNumberHeader).toBe(true);

const seriesNumberCell = rowIndexHeader.frozenHeadGroup.getChildren();
expect(seriesNumberCell).toHaveLength(1);

expect(
rowIndexHeader.scrollGroup.getChildren()[0] instanceof SeriesNumberCell,
).toBe(true);

expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true);

expect(get(seriesNumberCell[0], 'meta.height')).toBe(30);
},
);
});
Loading
Loading