-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 修复交叉模式下 行序号位置不正确&总计行未添加行序号 (#2412) fix: fix row series number position and height bug Co-authored-by: wuding.why <[email protected]> * refactor: extract freeze public logic * feat: the pivot table supports freezing the first row as a whole * fix: lint error fixed * fix: test case optimize --------- Co-authored-by: wuhaiyang <[email protected]> Co-authored-by: wuding.why <[email protected]>
- Loading branch information
1 parent
fdf75ba
commit be5e32e
Showing
34 changed files
with
1,892 additions
and
795 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
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, | ||
showSeriesNumber: true, | ||
}), | ||
...DEFAULT_STYLE, | ||
height: 480, | ||
width: 400, | ||
cellCfg: { | ||
width: 200, | ||
height: 50, | ||
}, | ||
}); | ||
describe('Frozen Row Header Test', () => { | ||
let facet; | ||
|
||
test.each(['grid', 'tree'])( | ||
'frozen row header group api', | ||
(hierarchyType: 'grid' | 'tree') => { | ||
s2.setOptions({ hierarchyType }); | ||
s2.render(); | ||
facet = s2.facet as PivotFacet; | ||
|
||
expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue(); | ||
expect(facet.rowHeader.frozenHeadGroup).toBeTruthy(); | ||
expect(facet.rowHeader.scrollGroup).toBeTruthy(); | ||
|
||
expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1); | ||
const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0]; | ||
|
||
expect(frozenRowCell instanceof RowCell).toBeTrue(); | ||
expect(frozenRowCell.meta.height).toEqual(30); | ||
|
||
expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3); | ||
const scrollCell = facet.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(rowHeader.getFrozenRowCount()).toBe(1); | ||
}, | ||
); | ||
}); | ||
|
||
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 seriesNumberCell = | ||
facet.rowIndexHeader.frozenHeadGroup.getChildren(); | ||
expect(seriesNumberCell).toHaveLength(1); | ||
|
||
expect( | ||
facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof | ||
SeriesNumberCell, | ||
).toBe(true); | ||
|
||
expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true); | ||
|
||
expect(seriesNumberCell[0].meta.height).toBe(30); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
KEY_GROUP_ROW_RESIZE_AREA, | ||
ResizeAreaEffect, | ||
ResizeDirectionType, | ||
} from '../common/constant'; | ||
import { | ||
getOrCreateResizeAreaGroupById, | ||
getResizeAreaAttrs, | ||
shouldAddResizeArea, | ||
} from '../utils/interaction/resize'; | ||
import type { BaseHeaderConfig } from '../facet/header/base'; | ||
import { RowCell } from './row-cell'; | ||
|
||
export class FrozenRowCell extends RowCell { | ||
private frozenRowHeight: number; | ||
|
||
protected handleRestOptions( | ||
...[headerConfig, ...options]: [BaseHeaderConfig, number] | ||
) { | ||
super.handleRestOptions(headerConfig, options); | ||
this.frozenRowHeight = options[0]; | ||
} | ||
|
||
protected drawResizeAreaInLeaf(): void { | ||
if ( | ||
!this.meta.isLeaf || | ||
!this.shouldDrawResizeAreaByType('rowCellVertical', this) | ||
) { | ||
return; | ||
} | ||
|
||
const { x, y, width, height } = this.getCellArea(); | ||
const resizeStyle = this.getResizeAreaStyle(); | ||
const resizeArea = getOrCreateResizeAreaGroupById( | ||
this.spreadsheet, | ||
KEY_GROUP_ROW_RESIZE_AREA, | ||
); | ||
|
||
const { | ||
position, | ||
seriesNumberWidth, | ||
width: headerWidth, | ||
viewportHeight: headerHeight, | ||
scrollX, | ||
scrollY, | ||
} = this.headerConfig; | ||
|
||
// const frozenRowHeight = this.getFrozenRowHeight(); | ||
const resizeAreaBBox = { | ||
// fix: When horizontally scrolling and closing the entire frozen header, the resize area is being removed prematurely. | ||
x: x + seriesNumberWidth, | ||
// packages/s2-core/src/facet/header/frozen-row.ts The y-coordinate has been decreased by the height of the frozen rows. need plus frozenRowHeight | ||
y: y + this.frozenRowHeight + height - resizeStyle.size / 2, | ||
width, | ||
height: resizeStyle.size, | ||
}; | ||
|
||
const resizeClipAreaBBox = { | ||
x: 0, | ||
// There are frozen rows, so the clip should start from the position of the frozen rows. | ||
y: this.frozenRowHeight, | ||
width: headerWidth, | ||
height: headerHeight, | ||
}; | ||
|
||
if ( | ||
!shouldAddResizeArea(resizeAreaBBox, resizeClipAreaBBox, { | ||
scrollX, | ||
scrollY, | ||
}) | ||
) { | ||
return; | ||
} | ||
|
||
const offsetX = position?.x + x - scrollX + seriesNumberWidth; | ||
const offsetY = position?.y + y + this.frozenRowHeight - scrollY; | ||
|
||
const resizeAreaWidth = this.spreadsheet.isFrozenRowHeader() | ||
? headerWidth - seriesNumberWidth - (x - scrollX) | ||
: width; | ||
|
||
resizeArea.addShape('rect', { | ||
attrs: { | ||
...getResizeAreaAttrs({ | ||
id: this.meta.id, | ||
theme: resizeStyle, | ||
type: ResizeDirectionType.Vertical, | ||
effect: ResizeAreaEffect.Cell, | ||
offsetX, | ||
offsetY, | ||
width, | ||
height, | ||
meta: this.meta, | ||
}), | ||
x: offsetX, | ||
y: offsetY + height - resizeStyle.size / 2, | ||
width: resizeAreaWidth, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.