Skip to content

Commit

Permalink
Merge branch 'master' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Dec 4, 2023
2 parents 62d48e0 + b81b795 commit a5c6c6b
Show file tree
Hide file tree
Showing 34 changed files with 832 additions and 741 deletions.
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",
},
"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
103 changes: 36 additions & 67 deletions packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,73 @@
import { createPivotSheet } from 'tests/util/helpers';
import { assembleDataCfg, assembleOptions } from 'tests/util';
import { DEFAULT_STYLE } from '@/common';

import { FrozenRowCell, RowCell, SeriesNumberCell } from '@/cell';
import type { PivotFacet } from '@/facet';
import { FrozenRowHeader } from '@/facet/header';
import { FrozenSeriesNumber } from '@/facet/header/frozen-series-number';

const s2 = createPivotSheet({
...assembleDataCfg().fields,
valueInCols: true,
...assembleOptions({
frozenEntireHeadRowPivot: true,
totals: {
row: {
showGrandTotals: true,
reverseLayout: true,
},
},
frozenColCount: 2,
frozenRowCount: 2,
frozenTrailingColCount: 2,
frozenTrailingRowCount: 2,
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,
}),
...DEFAULT_STYLE,
height: 480,
width: 400,
cellCfg: {
width: 200,
height: 50,
},
});
describe('Frozen Row Header Test', () => {
let facet;
{ useSimpleData: false },
);

describe('Frozen Row Header Test', () => {
test.each(['grid', 'tree'])(
'frozen row header group api',
(hierarchyType: 'grid' | 'tree') => {
s2.setOptions({ hierarchyType });
s2.render();
facet = s2.facet as PivotFacet;
const rowHeader: PivotRowHeader = s2.facet.rowHeader as PivotRowHeader;

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

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

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

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

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

const rowHeader = facet.rowHeader;
expect(rowHeader.getFrozenRowHeight()).toBe(30);

expect(
rowHeader.isFrozenRow({
rowIndex: 0,
}),
).toBe(true);
expect(
rowHeader.isFrozenRow({
rowIndex: -1,
}),
).toBe(false);
expect(get(frozenRowCell, 'meta.height')).toEqual(30);

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

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

const seriesNumberCell =
facet.rowIndexHeader.frozenHeadGroup.getChildren();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const seriesNumberCell = rowIndexHeader.frozenHeadGroup.getChildren();
expect(seriesNumberCell).toHaveLength(1);

expect(
facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof
SeriesNumberCell,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
rowIndexHeader.scrollGroup.getChildren()[0] instanceof SeriesNumberCell,
).toBe(true);

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

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

0 comments on commit a5c6c6b

Please sign in to comment.