Skip to content

Commit

Permalink
Merge branch 'master' into JuzeDev1013
Browse files Browse the repository at this point in the history
# Conflicts:
#	s2-site/docs/api/basic-class/base-data-set.zh.md
  • Loading branch information
JuZe committed Oct 19, 2023
2 parents 0a0fa17 + bd09e3d commit f61a961
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 47 deletions.
9 changes: 9 additions & 0 deletions packages/s2-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [@antv/s2-v1.51.1](https://github.com/antvis/S2/compare/@antv/s2-v1.51.0...@antv/s2-v1.51.1) (2023-10-13)


### Bug Fixes

* **layout:** 修复隐藏结点时对父节点的布局计算错误 close [#2355](https://github.com/antvis/S2/issues/2355) ([#2360](https://github.com/antvis/S2/issues/2360)) ([c8d2c94](https://github.com/antvis/S2/commit/c8d2c94c21527ae52ece3485524d374d09b1cba7))
* **table-sheet:** 明细表数据为空时错误的展示一行空数据 close [#2255](https://github.com/antvis/S2/issues/2255) ([#2357](https://github.com/antvis/S2/issues/2357)) ([7751c49](https://github.com/antvis/S2/commit/7751c4968b69752243928cbcd2c50333b06b2c66))
* 列头绘制多列文本时错误的使用了数值单元格的样式 close [#2359](https://github.com/antvis/S2/issues/2359) ([#2364](https://github.com/antvis/S2/issues/2364)) ([4953b4e](https://github.com/antvis/S2/commit/4953b4e430f3c1857ce6648bcdc2493c37bb1092))

# [@antv/s2-v1.51.0](https://github.com/antvis/S2/compare/@antv/s2-v1.50.0...@antv/s2-v1.51.0) (2023-09-22)


Expand Down
140 changes: 140 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2359-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* @description spec for issue #2359
* https://github.com/antvis/S2/issues/2359
* 明细表: 自定义列头误用 dataCell 样式
*/
import { pick } from 'lodash';
import { createTableSheet } from 'tests/util/helpers';
import { TableColCell, drawObjectText } from '../../src';
import type { S2CellType, S2Options } from '@/common/interface';

class TestColCell extends TableColCell {
drawTextShape() {
drawObjectText(this, {
values: [['A', 'B', 'C']],
});
}
}

const s2Options: S2Options = {
width: 300,
height: 480,
showSeriesNumber: true,
colCell: (...args) => new TestColCell(...args),
};

describe('Table Sheet Custom Multiple Values Tests', () => {
test('should use current cell text theme', () => {
const s2 = createTableSheet(s2Options);

s2.setTheme({
colCell: {
measureText: {
fontSize: 12,
},
bolderText: {
fontSize: 14,
},
text: {
fontSize: 20,
fill: 'red',
},
},
dataCell: {
text: {
fontSize: 30,
fill: 'green',
},
},
});
s2.render();

const mapTheme = (cell: S2CellType) => {
return cell
.getTextShapes()
.map((shape) => pick(shape.attr(), ['fill', 'fontSize']));
};

const colCellTexts = s2
.getColumnNodes()
.map((node) => mapTheme(node.belongsCell));

const dataCellTexts = s2.interaction
.getPanelGroupAllDataCells()
.map(mapTheme);

expect(colCellTexts).toMatchInlineSnapshot(`
Array [
Array [
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
],
Array [
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
Object {
"fill": "red",
"fontSize": 20,
},
],
]
`);

expect(dataCellTexts).toMatchInlineSnapshot(`
Array [
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "#000000",
"fontSize": 12,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
Array [
Object {
"fill": "green",
"fontSize": 30,
},
],
]
`);
});
});
28 changes: 28 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(hiddenColumnsInfo).toBeTruthy();
expect(parentNode.hiddenChildNodeInfo).toEqual(hiddenColumnsInfo);
});
// https://github.com/antvis/S2/issues/2355
test('should render correctly x and width after hide columns when there is only one value for the higher-level dimension.', () => {
const nodeId = 'root[&]笔[&]义乌[&]price';

pivotSheet.setOptions({
style: {
colCfg: {
width: 100,
},
},
});
const data = pivotSheet.dataCfg.data.map((i) => ({ ...i, cost: 0 }));
pivotSheet.setDataCfg({
data,
fields: {
values: ['cost', 'price'],
},
});
pivotSheet.render();

pivotSheet.interaction.hideColumns([nodeId]);
const rootNode = pivotSheet
.getColumnNodes()
.find((node) => node.id === 'root[&]笔');

expect(rootNode.width).toEqual(300);
expect(rootNode.x).toEqual(0);
});

// https://github.com/antvis/S2/issues/2194
test('should render correctly when always hidden last column', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describe('Pivot Dataset Test', () => {
getDimensionsWithoutPathPre(sortedDimensionValues[EXTRA_FIELD]),
).toEqual(['number', 'number', 'number', 'number']);
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ describe('Table Mode Dataset Test', () => {
test('should get correct meta data', () => {
expect(dataSet.meta).toEqual(expect.objectContaining([]));
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { DataCell, DEFAULT_STYLE, type Fields, Node } from '@/index';
import { getFrozenLeafNodesCount } from '@/facet/utils';
import { SpreadSheet } from '@/sheet-type';
import { getTheme } from '@/theme';

const actualDataSet = jest.requireActual(
'@/data-set/base-data-set',
).BaseDataSet;

jest.mock('@/sheet-type', () => {
const container = new Canvas({
width: 100,
Expand Down Expand Up @@ -59,6 +61,9 @@ jest.mock('@/sheet-type', () => {
interaction: {
clearHoverTimer: jest.fn(),
},
dataSet: {
isEmpty: jest.fn(),
},
};
}),
};
Expand All @@ -77,6 +82,7 @@ jest.mock('@/data-set/table-data-set', () => {
getCellData: () => 1,
getFieldMeta: jest.fn(),
getFieldFormatter: actualDataSet.prototype.getFieldFormatter,
isEmpty: jest.fn(),
};
}),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@antv/s2",
"version": "1.51.0",
"version": "1.51.1",
"main": "lib/index.js",
"unpkg": "dist/index.min.js",
"module": "esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class TableColCell extends ColCell {
y,
};
}

return {
x: position.x + x - scrollX,
y: position.y + y,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
find,
get,
identity,
isEmpty,
isNil,
map,
max,
Expand Down Expand Up @@ -117,6 +118,10 @@ export abstract class BaseDataSet {
return this.displayData;
}

public isEmpty() {
return isEmpty(this.getDisplayDataSet());
}

public getValueRangeByField(field: string): ValueRange {
const cacheRange = getValueRangeState(this.spreadsheet, field);
if (cacheRange) {
Expand Down
3 changes: 3 additions & 0 deletions packages/s2-core/src/facet/layout/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ export class Node {

public isTotalRoot?: boolean;

/**
* @deprecated 已废弃, 该属性只记录相邻一级的隐藏信息,将会在未来版本中移除
*/
public hiddenChildNodeInfo?: HiddenColumnsInfo | null;

public extra?: Record<string, any>;
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export class PivotFacet extends BaseFacet {
leafNodes.push(parentNode);

const firstVisibleChildNode = parentNode.children?.find(
(childNode) => !childNode.hiddenChildNodeInfo,
(childNode) => childNode.width,
);
// 父节点 x 坐标 = 第一个未隐藏的子节点的 x 坐标
// 父节点 x 坐标 = 第一个正常布局处理过的子节点 x 坐标(width 有值认为是正常布局过)
const parentNodeX = firstVisibleChildNode?.x;
// 父节点宽度 = 所有子节点宽度之和
const parentNodeWidth = sumBy(parentNode.children, 'width');
Expand Down
21 changes: 12 additions & 9 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
getFrozenRowsForGrid,
getRowsForGrid,
} from '../utils/grid';
import type { PanelIndexes } from '../utils/indexes';
import type { Indexes, PanelIndexes } from '../utils/indexes';
import { getValidFrozenOptions } from '../utils/layout/frozen';
import { BaseFacet } from './base-facet';
import { CornerBBox } from './bbox/cornerBBox';
Expand Down Expand Up @@ -1129,14 +1129,17 @@ export class TableFacet extends BaseFacet {
}
}

const indexes = calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);
// https://github.com/antvis/S2/issues/2255
const indexes = this.spreadsheet.dataSet.isEmpty()
? ([] as unknown as Indexes)
: calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);

this.panelScrollGroupIndexes = indexes;

Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/sheet-type/table-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class TableSheet extends SpreadSheet {
}
return new TableDataCell(facet, this);
};

return {
...this.options,
...fields,
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/utils/layout/generate-header-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const generateHeaderNodes = (params: HeaderNodesParams) => {
// 如果当前是隐藏节点, 给其父节点挂载相应信息 (兄弟节点, 当前哪个子节点隐藏了), 这样在 facet 层可以直接使用, 不用每次都去遍历
const hiddenColumnsInfo = spreadsheet?.facet?.getHiddenColumnsInfo(node);
if (hiddenColumnsInfo && parentNode) {
// hiddenChildNodeInfo 属性在 S2 中没有用到,但是没删怕外部有使用,已标记为废弃
parentNode.hiddenChildNodeInfo = hiddenColumnsInfo;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/s2-core/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ const calX = (
const getDrawStyle = (cell: S2CellType) => {
const { isTotals } = cell.getMeta();
const isMeasureField = (cell as ColCell).isMeasureField?.();
const cellStyle = cell.getStyle(
isMeasureField ? CellTypes.COL_CELL : CellTypes.DATA_CELL,
);
const cellStyle = cell.getStyle(cell.cellType || CellTypes.DATA_CELL);

let textStyle: TextTheme;
if (isMeasureField) {
Expand Down
Loading

0 comments on commit f61a961

Please sign in to comment.