Skip to content

Commit

Permalink
Merge branch 'master' into latest
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Oct 13, 2023
2 parents c267748 + 4953b4e commit f37eecc
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 28 deletions.
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
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
1 change: 1 addition & 0 deletions s2-site/docs/api/basic-class/base-data-set.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ s2.dataSet.getFieldName('type')
| getCellData | 获取单个的单元格数据 | (params: [CellDataParams](#celldataparams)) => [DataType[]](#datatype) | |
| getMultiData | 获取批量的单元格数据 | (query: [DataType](#datatype), isTotals?: boolean, isRow?: boolean, drillDownFields?: string[]) => [DataType[]](#datatype) | |
| moreThanOneValue | 是否超过 1 个数值 | () => [ViewMeta](#viewmeta) | |
| isEmpty | 是否为空数据集 | () => `boolean` | `@antv/s2-v1.51.1` |

### DataType

Expand Down
18 changes: 9 additions & 9 deletions s2-site/docs/common/header-action-icon.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
| 参数 | 说明 | 类型 | 默认值 | 必选 | 取值 | 版本 |
| ---------------- | ----------- | ----------- | ------ | ---- | ----------- | --- |
| iconNames | 已经注册的 icon 名称,或用户通过 customSVGIcons 注册的 icon 名称 | `string[]` | || | |
| belongsCell | 需要增加操作图标的单元格名称 | `string[]` | || 角头:'cornerCell';<br>列头:'colCell';<br>行头:'rowCell' | |
| defaultHide | 控制是否 hover 才展示 icon | `boolean | (meta: Node, iconName: string) => boolean` | false | | true | `1.26.0` 支持配置为一个函数 |
| displayCondition | 展示的过滤条件,可以通过该回调函数用户自定义行列头哪些层级或单元格需要展示 icon。 所有返回值为 true 的 icon 会展示给用户。 | `(mete: Node, iconName: string) => boolean;` | | | | `1.26.0` 回传 `iconName` 并按单个 icon 控制显隐 |
| action | icon 点击之后的执行函数 | `(headerActionIconProps: HeaderActionIconProps) => void;` | | | | 已废弃,请使用 `onClick` |
| onClick | icon 点击之后的执行函数 | `(headerIconClickParams: HeaderIconClickParams) => void;` | | | | `1.26.0` |
| onHover | icon hover 开始及结束之后的执行函数 | `(headerIconHoverParams: HeaderIconHoverParams) => void;` | | | | `1.26.0` |
| belongsCell | 需要增加操作图标的单元格名称 | `string` | || 角头:`cornerCell`;<br>列头:`colCell`;<br>行头:`rowCell` | |
| defaultHide | 控制是否 hover 在对应单元格时才展示 icon, 默认始终展示 | `boolean \| (meta: Node, iconName: string) => boolean` | false | | | `1.26.0` 支持配置为一个函数 |
| displayCondition | 自定义展示条件,可根据当前单元格信息动态控制 icon 是否展示 | `(mete: Node, iconName: string) => boolean` | | | | `1.26.0` 回传 `iconName` 并按单个 icon 控制显隐 |
| action | icon 点击之后的执行函数 (已废弃,请使用 `onClick`) | `(headerActionIconProps: HeaderActionIconProps) => void` | | | | |
| onClick | icon 点击之后的执行函数 | `(headerIconClickParams: HeaderIconClickParams) => void` | | | | `1.26.0` |
| onHover | icon hover 开始及结束之后的执行函数 | `(headerIconHoverParams: HeaderIconHoverParams) => void` | | | | `1.26.0` |


Expand All @@ -24,9 +24,9 @@

| 参数 | 功能描述 | 类型 | 默认值 | 必选 |
| --- | --- | --- | --- | --- |
| iconName | 当前点击的 icon 名称 | string | ||
| meta |当前 cell 的 meta 信息| Node | ||
| event |当前点击事件信息| Event |false||
| iconName | 当前 icon 名称 | string | ||
| meta |当前 cell 的 meta 信息| [Node](/api/basic-class/node) | ||
| event |当前点击事件信息| Event | false ||

## CustomSVGIcon

Expand Down
10 changes: 5 additions & 5 deletions s2-site/docs/common/icon.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ order: 3

| icon 名称 | icon 图标 | 功能描述 | icon 名称 | icon 图标 | 功能描述 |
| ------------- | --------------------- | ---------- | ---------------- | ----------- | ------------------ |
| CellDown | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471683806-41687600-9f55-49f7-8210-25c438b8152e.png" height=30> | 同环比下降 | ExpandColIcon | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472462583-40f32d2a-0a26-4e4f-8ebf-39603c3b8939.png" height=30> | 明细表隐藏展开 |
| CellDown | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471683806-41687600-9f55-49f7-8210-25c438b8152e.png" height=30> | 同环比下降 | ExpandColIcon | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472462583-40f32d2a-0a26-4e4f-8ebf-39603c3b8939.png" height=30> | 展开列头 |
| CellUp | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471716079-9bc714c4-0b4e-4176-a2b9-d620251d30d6.png" height=30> | 同环比上升 | Plus | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632475581023-4a53ecff-942c-45ff-8dc5-1c5b08e7b157.png" height=30> | 树状表格展开 |
| GlobalAsc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471780679-5a7ee62d-73be-4713-945d-6b03f2786e8d.png" height=30> | 全局升序 | Minus | <img alt="icon" src="https://gw.alipayobjects.com/zos/antfincdn/dKGwptOOB9/34d9064e-eaee-4160-ad84-a08f4ef1fee4.png" height=30> | 树状表格收起 |
| GlobalDesc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471882478-bdbe6981-ce4b-4082-b6ad-f13577329147.png" height=30> | 全局降序 | SortDown | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473030451-4aed635f-d192-470b-91e6-5bfed9fac595.png" height=30> | 明细表降序 |
| GroupAsc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471962652-722d8fec-9bee-4a85-9cc1-ac4f51f483c6.png" height=30> | 组内升序 | SortDownSelected | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472951651-80c2949e-7b03-4a64-a283-1c4e37fc5e60.png" height=30> | 明细表降序选择状态 |
| GroupDesc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472173126-d751f07a-10c4-44fb-a916-362f2ba611e6.png" height=30> | 组内降序 | SortUp | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473083059-12d7b39e-1a59-4584-b2f6-4608ee9e04fb.png" height=30> | 明细表升序 |
| Trend | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473312620-593aeff4-c618-4b2e-bc26-136a751efff9.png" height=30> | 趋势图 | SortUpSelected | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473154460-1a7c66bc-7f3f-4c46-a6e1-a586d566b94c.png" height=30> | 明细表升序选择状态 |
| GlobalDesc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471882478-bdbe6981-ce4b-4082-b6ad-f13577329147.png" height=30> | 全局降序 | SortDown | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473030451-4aed635f-d192-470b-91e6-5bfed9fac595.png" height=30> | 降序 |
| GroupAsc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632471962652-722d8fec-9bee-4a85-9cc1-ac4f51f483c6.png" height=30> | 组内升序 | SortDownSelected | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472951651-80c2949e-7b03-4a64-a283-1c4e37fc5e60.png" height=30> | 降序选中状态 |
| GroupDesc | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632472173126-d751f07a-10c4-44fb-a916-362f2ba611e6.png" height=30> | 组内降序 | SortUp | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473083059-12d7b39e-1a59-4584-b2f6-4608ee9e04fb.png" height=30> | 升序 |
| Trend | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473312620-593aeff4-c618-4b2e-bc26-136a751efff9.png" height=30> | 趋势图 | SortUpSelected | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473154460-1a7c66bc-7f3f-4c46-a6e1-a586d566b94c.png" height=30> | 升序选中状态 |
| ArrowUp | <img alt="icon" src="https://gw.alipayobjects.com/zos/antfincdn/g9lTlN2xG/84042923-69b2-4ccc-89b4-1b2b5aa45d68.png" height=30> | 指标上升 |ArrowDown | <img alt="icon" src="https://gw.alipayobjects.com/zos/antfincdn/OjQEFxclz/c7f5cce0-16e4-4522-987a-ae21ab9f24fa.png" height=30> | 指标下降 |
| DrillDownIcon | <img alt="icon" src="https://intranetproxy.alipay.com/skylark/lark/0/2021/png/315626/1632473411428-4959bde8-ead3-4c81-921d-26035bee21ae.png" height=30> | 下钻 | | | |

0 comments on commit f37eecc

Please sign in to comment.