Skip to content

Commit

Permalink
Merge branch 'next' into tree-line
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Dec 4, 2024
2 parents 4873ede + 598f68a commit a8363ee
Show file tree
Hide file tree
Showing 64 changed files with 466 additions and 288 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
# jest-electron 需要 macOS 环境, 但是 免费用户 并发有限制, 容易排队 https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
# runs-on: macos-latest # (目前 macos-latest 对应的是 Big Sur 11, macos-12 对应 Monterey 12)
# macOS 3-core CPU, 其他 2-core CPU
runs-on: macos-latest
# > macos-14 会导致 CI 的测试卡死, 没有任何报错!!!
runs-on: macos-13
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
Expand Down
14 changes: 14 additions & 0 deletions packages/s2-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [@antv/s2-v2.1.0](https://github.com/antvis/S2/compare/@antv/s2-v2.0.1...@antv/s2-v2.1.0) (2024-11-29)


### Bug Fixes

* **tooltip:** 修复操作按钮的 visible 对角头和文本溢出场景不生效 ([#3001](https://github.com/antvis/S2/issues/3001)) ([8f56023](https://github.com/antvis/S2/commit/8f56023b4f29584bc619b00bc5a03a0c3bf30494))
* 修复行头底部存在多行文本, 初始化和滚动时文本展示溢出的问题 ([#3000](https://github.com/antvis/S2/issues/3000)) ([6204839](https://github.com/antvis/S2/commit/620483901c40d64e2e1e6be6753a08ee26f35677))
* 明细表未指定 dataCfg.fields 配置时不应该渲染空数据占位 ([#3003](https://github.com/antvis/S2/issues/3003)) ([60d6497](https://github.com/antvis/S2/commit/60d649705365bca0bde3acc836bd8eeb13e47c3c))


### Features

* 增加树状模式下行头宽度配置 rowCell.treeWidth ([#2998](https://github.com/antvis/S2/issues/2998)) ([b8fdd2a](https://github.com/antvis/S2/commit/b8fdd2a700a9a3bdc5d565c2bf89a85427c66a88))

# [@antv/s2-v2.0.1](https://github.com/antvis/S2/compare/@antv/s2-v2.0.0...@antv/s2-v2.0.1) (2024-11-26)

# [@antv/s2-v2.0.0](https://github.com/antvis/S2/compare/@antv/s2-v1.45.1...@antv/s2-v2.0.0) (2024-11-21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ Array [
]
`;

exports[`SpreadSheet Custom Cell Style Tests PivotSheet Custom Cell Style Tests #RowCell should get custom tree row cell style 1`] = `
Array [
Object {
"height": 30,
"id": "root[&]浙江",
"width": 150,
},
Object {
"height": 30,
"id": "root[&]浙江[&]义乌",
"width": 150,
},
Object {
"height": 30,
"id": "root[&]浙江[&]杭州",
"width": 150,
},
]
`;

exports[`SpreadSheet Custom Cell Style Tests PivotSheet Custom Cell Style Tests should render default cell style 1`] = `
Array [
Object {
Expand Down
24 changes: 19 additions & 5 deletions packages/s2-core/__tests__/spreadsheet/custom-cell-style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,21 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
},
},
});
await s2.render();
await s2.render(false);

expect(mapNodeSize(s2.facet.getRowNodes())).toMatchSnapshot();
});

test('should get custom tree row cell style', async () => {
s2.setOptions({
hierarchyType: 'tree',
style: {
rowCell: {
treeWidth: 150,
},
},
});
await s2.render(false);

expect(mapNodeSize(s2.facet.getRowNodes())).toMatchSnapshot();
});
Expand All @@ -113,7 +127,7 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
},
},
});
await s2.render();
await s2.render(false);

expect(mapNodeSize(s2.facet.getRowNodes())).toMatchSnapshot();
});
Expand All @@ -131,7 +145,7 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
},
},
});
await s2.render();
await s2.render(false);

expect(mapNodeSize(s2.facet.getRowNodes())).toMatchSnapshot();
});
Expand All @@ -151,7 +165,7 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
},
},
});
await s2.render();
await s2.render(false);

expect(mapNodeSize(s2.facet.getRowNodes())).toMatchSnapshot();
});
Expand Down Expand Up @@ -200,7 +214,7 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
},
},
});
await s2.render();
await s2.render(false);

const rootRowNodes = s2.facet
.getRowNodes()
Expand Down
5 changes: 3 additions & 2 deletions packages/s2-core/__tests__/spreadsheet/custom-tree-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const s2Options: S2Options = {
hierarchyType: 'tree',
style: {
rowCell: {
width: 400,
treeWidth: 400,
},
},
};
Expand Down Expand Up @@ -208,7 +208,8 @@ describe('SpreadSheet Custom Tree Tests', () => {
s2.setOptions({
style: {
rowCell: {
width: 50,
treeWidth: 50,
width: 30,
},
},
});
Expand Down
25 changes: 25 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,30 @@ describe('TableSheet normal spec', () => {

await expectEmptyPlaceholder(s2);
});

test('should not render empty placeholder if all fields is empty', async () => {
const s2 = new TableSheet(
getContainer(),
{ ...dataCfg, fields: {}, data: [] },
{
...options,
frozen: {},
seriesNumber: {
enable: false,
},
},
);

await s2.render();
const [rect, icon, text] = (s2.facet as TableFacet).emptyPlaceholderGroup
.children;

expect(
(s2.facet as TableFacet).emptyPlaceholderGroup.children,
).toHaveLength(0);
expect(rect).not.toBeDefined();
expect(icon).not.toBeDefined();
expect(text).not.toBeDefined();
});
});
});
6 changes: 3 additions & 3 deletions packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { CornerCell, DataCell } from '@/cell';
import {
DEFAULT_OPTIONS,
DEFAULT_ROW_CELL_TREE_WIDTH,
DEFAULT_STYLE,
DEFAULT_TREE_ROW_CELL_WIDTH,
} from '@/common/constant/options';
import type { ViewMeta } from '@/common/interface/basic';
import { Store } from '@/common/store';
Expand Down Expand Up @@ -261,11 +261,11 @@ describe('Pivot Mode Facet Test', () => {

expect(rowsHierarchy.getLeaves()).toHaveLength(8);
expect(rowsHierarchy.getNodes()).toHaveLength(10);
expect(rowsHierarchy.width).toBe(DEFAULT_TREE_ROW_CELL_WIDTH);
expect(rowsHierarchy.width).toBe(DEFAULT_ROW_CELL_TREE_WIDTH);
expect(rowCell?.width).toBeUndefined();

rowsHierarchy.getNodes().forEach((node, index) => {
expect(node.width).toBe(DEFAULT_TREE_ROW_CELL_WIDTH);
expect(node.width).toBe(DEFAULT_ROW_CELL_TREE_WIDTH);
expect(node.height).toBe(dataCell!.height!);
expect(node.x).toBe(0);
expect(node.y).toBe(node.height * index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ describe('Interaction Corner Cell Click Tests', () => {
[],
{
data: { summaries: [{ name: '', selectedData: [], value: null }] },
operator: {
menu: {
items: [],
},
},
},
);
expect(s2.interaction.getState()).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ describe('Interaction Hover Tests', () => {
hideSummary: true,
isTotals: undefined,
onlyShowCellText: true,
operator: {
menu: {
items: [],
},
},
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,14 @@ describe('Interaction Row Column Resize Tests', () => {
info: { ...resizeInfo, resizedWidth: 5, resizedHeight: 0 },
style: {
rowCell: {
width: 5,
treeWidth: 5,
},
},
};

expect(resize).toHaveBeenCalledWith(newResizeInfo);
expect(treeWidthResize).toHaveBeenCalledWith(newResizeInfo);
expect(s2.options.style!.rowCell!.width).toEqual(resizeInfo.width);
expect(s2.options.style!.rowCell!.treeWidth).toEqual(resizeInfo.width);
});

test('should get horizontal filed resize style', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/s2",
"version": "2.0.1",
"version": "2.1.0",
"private": false,
"description": "effective spreadsheet render core lib",
"keywords": [
Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {
const textArea = this.getTextArea();
const textStyle = this.getTextStyle();
const { cell, icon: iconStyle } = this.getStyle();

const viewport = this.handleViewport();
const textHeight = this.getActualTextHeight();

const { textStart } = adjustTextIconPositionWhileScrolling(
viewport,
Expand All @@ -456,7 +456,7 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {
{
align: normalizeTextAlign(textStyle.textBaseline!),
size: {
textSize: textStyle.fontSize!,
textSize: textHeight,
},
padding: {
start: cell.padding.top,
Expand All @@ -476,7 +476,7 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {
const iconY = getVerticalIconPosition(
iconStyle?.size!,
textStart,
textStyle.fontSize!,
textHeight,
textStyle.textBaseline!,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/common/constant/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export enum LayoutWidthType {

export const SPLIT_LINE_WIDTH = 1;

export const DEFAULT_TREE_ROW_CELL_WIDTH = 120;
export const DEFAULT_ROW_CELL_TREE_WIDTH = 120;

export const DEFAULT_CELL_TEXT_WORD_WRAP_STYLE: CellTextWordWrapStyle = {
wordWrap: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/common/interface/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export interface DataCellStyle extends CellTextWordWrapStyle {
}

export interface RowCellStyle extends BaseCellStyle, CellTextWordWrapStyle {
/**
* 树状结构的行头宽度
*/
treeWidth?: number;

/**
* 是否展示树状分层下的层级占位点
*/
Expand Down
11 changes: 6 additions & 5 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export abstract class BaseFacet {
this.init();
}

protected shouldRender() {
return !areAllFieldsEmpty(this.spreadsheet.dataCfg.fields);
}

public getLayoutResult = (): LayoutResult => {
return {
...this.layoutResult,
Expand Down Expand Up @@ -609,11 +613,8 @@ export abstract class BaseFacet {
this.emitPaginationEvent();
};

/**
* Start render, call from outside
*/
public render() {
if (areAllFieldsEmpty(this.spreadsheet.dataCfg.fields)) {
if (!this.shouldRender()) {
return;
}

Expand Down Expand Up @@ -710,7 +711,7 @@ export abstract class BaseFacet {
}

public setScrollOffset = (scrollOffset: ScrollOffset) => {
Object.keys(scrollOffset).forEach((key) => {
Object.keys(scrollOffset || {}).forEach((key) => {
const offset = get(scrollOffset, key);

if (!isUndefined(offset)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/s2-core/src/facet/frozen-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ export abstract class FrozenFacet extends BaseFacet {
}

public render() {
if (!this.shouldRender()) {
return;
}

this.calculateFrozenGroupInfo();
this.renderFrozenPanelCornerGroup();
super.render();
Expand All @@ -697,7 +701,7 @@ export abstract class FrozenFacet extends BaseFacet {
cellRange,
);

(Object.keys(result) as (keyof typeof result)[]).forEach((key) => {
(Object.keys(result || {}) as (keyof typeof result)[]).forEach((key) => {
const cells = result[key];
const group = this.frozenGroups[key];

Expand Down
10 changes: 7 additions & 3 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'lodash';
import { ColCell, RowCell, SeriesNumberCell } from '../cell';
import {
DEFAULT_TREE_ROW_CELL_WIDTH,
DEFAULT_ROW_CELL_TREE_WIDTH,
LAYOUT_SAMPLE_COUNT,
type IconTheme,
type MultiData,
Expand Down Expand Up @@ -804,6 +804,10 @@ export class PivotFacet extends FrozenFacet {
const { rowCell } = this.spreadsheet.options.style!;

// 1. 用户拖拽或手动指定的行头宽度优先级最高
if (isNumber(rowCell?.treeWidth)) {
return rowCell.treeWidth;
}

const customRowCellWidth = this.getCellCustomSize(null, rowCell?.width!);

if (isNumber(customRowCellWidth)) {
Expand All @@ -829,11 +833,11 @@ export class PivotFacet extends FrozenFacet {
this.rowCellTheme.padding?.right;

const width = Math.max(
customRowCellWidth ?? DEFAULT_TREE_ROW_CELL_WIDTH,
customRowCellWidth ?? DEFAULT_ROW_CELL_TREE_WIDTH,
maxLabelWidth,
);

return Number.isNaN(width) ? DEFAULT_TREE_ROW_CELL_WIDTH : width;
return Number.isNaN(width) ? DEFAULT_ROW_CELL_TREE_WIDTH : width;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class TableFacet extends FrozenFacet {
}

public render() {
if (!this.shouldRender()) {
return;
}

super.render();
this.renderEmptyPlaceholder();
}
Expand Down
Loading

0 comments on commit a8363ee

Please sign in to comment.