Skip to content

Commit 62e94af

Browse files
author
嘤嘤嘤
authored
fix: 修复行头为空无默认角头指标文字问题 (#1104)
* fix: 修复行头为空无默认角头指标文字问题 * test: 增加角头单元格文本单测 * style: 代码优化 * style: 代码优化
1 parent 66048c1 commit 62e94af

File tree

7 files changed

+81
-9
lines changed

7 files changed

+81
-9
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* custom-tree mode.
3+
*/
4+
import { get } from 'lodash';
5+
import { customTreeItems } from 'tests/data/custom-tree-items';
6+
import { dataCustomTrees } from 'tests/data/data-custom-trees';
7+
import { S2DataConfig } from '@/common/interface';
8+
import { EXTRA_FIELD, VALUE_FIELD } from '@/common/constant';
9+
import { PivotSheet } from '@/sheet-type';
10+
import { CornerCell, S2Options, transformCustomTreeItems } from '@/index';
11+
import { CustomTreePivotDataSet } from '@/data-set/custom-tree-pivot-data-set';
12+
13+
describe('test for corner text', () => {
14+
const values = [
15+
'measure-a',
16+
'measure-b',
17+
'measure-c',
18+
'measure-d',
19+
'measure-e',
20+
'measure-f',
21+
];
22+
const dataCfg: S2DataConfig = {
23+
meta: [],
24+
data: dataCustomTrees,
25+
totalData: [],
26+
fields: {
27+
rows: [],
28+
columns: ['type', 'sub_type'],
29+
values,
30+
customTreeItems: transformCustomTreeItems(customTreeItems),
31+
valueInCols: false,
32+
},
33+
};
34+
35+
const options: S2Options = {
36+
width: 600,
37+
height: 480,
38+
hierarchyType: 'customTree',
39+
};
40+
const container = document.createElement('div');
41+
42+
const mockSheet = new PivotSheet(container, dataCfg, options);
43+
mockSheet.render();
44+
45+
test('get correct default corner text when the corner label is empty.', () => {
46+
const cornerCells = get(
47+
mockSheet,
48+
'facet.cornerBBox.facet.cornerHeader.cfg.children',
49+
).filter((v) => v instanceof CornerCell);
50+
expect(cornerCells[0].actualText).toEqual('指标');
51+
expect(cornerCells[1].actualText).toEqual('type');
52+
});
53+
54+
test('get correct default corner text when set the cornerText.', () => {
55+
mockSheet.setOptions({ ...options, cornerText: 'test' });
56+
mockSheet.render();
57+
const cornerCells = get(
58+
mockSheet,
59+
'facet.cornerBBox.facet.cornerHeader.cfg.children',
60+
).filter((v) => v instanceof CornerCell);
61+
expect(cornerCells[0].actualText).toEqual('test');
62+
expect(cornerCells[1].actualText).toEqual('type');
63+
});
64+
});

packages/s2-core/__tests__/unit/cell/data-cell.spec.ts renamed to packages/s2-core/__tests__/unit/cell/data-cell-spec.ts

File renamed without changes.

packages/s2-core/src/cell/corner-cell.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import {
2020
CellTypes,
2121
EXTRA_FIELD,
22+
DEFAULT_CORNER_TEXT,
2223
KEY_GROUP_CORNER_RESIZE_AREA,
2324
ResizeAreaEffect,
2425
ResizeDirectionType,
@@ -73,17 +74,12 @@ export class CornerCell extends HeaderCell {
7374
protected drawCellText() {
7475
const { label } = this.meta;
7576

76-
if (isEqual(label, EXTRA_FIELD)) {
77-
// don't render extra node
78-
return;
79-
}
80-
8177
const { x } = this.getContentArea();
8278
const { y, height } = this.getCellArea();
8379

8480
const textStyle = this.getTextStyle();
85-
const { formattedValue } = this.getFormattedFieldValue();
86-
const cornerText = this.spreadsheet.options?.cornerText || formattedValue;
81+
82+
const cornerText = this.getCornerText(label);
8783

8884
// 当为树状结构下需要计算文本前收起展开的icon占的位置
8985

@@ -368,4 +364,13 @@ export class CornerCell extends HeaderCell {
368364
y: 0,
369365
};
370366
}
367+
368+
protected getCornerText(label: string): string {
369+
if (isEqual(label, EXTRA_FIELD)) {
370+
return this.spreadsheet.options?.cornerText || DEFAULT_CORNER_TEXT;
371+
}
372+
373+
const { formattedValue } = this.getFormattedFieldValue();
374+
return formattedValue;
375+
}
371376
}

packages/s2-core/src/common/constant/basic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { i18n } from '../i18n';
12
// 值字段的 id 是固定的!
23
export const VALUE_FIELD = '$$value$$';
34
export const EXTRA_FIELD = '$$extra$$';
45
export const TOTAL_VALUE = '$$total$$';
56
export const SERIES_NUMBER_FIELD = '$$series_number$$';
6-
// export const COLUMN_FIELD_KEY = '$$column_key$$';
7+
export const DEFAULT_CORNER_TEXT = i18n('指标');
78

89
export const BACK_GROUND_GROUP_CONTAINER_Z_INDEX = 0;
910

packages/s2-core/src/common/i18n/en_US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const EN_US = {
2828
选择下钻维度: 'Select drill down dimension',
2929
恢复默认: 'Restore default',
3030
搜索字段: 'Search field',
31+
指标: 'Measure',
3132
// switcher
3233
行列切换: 'Switch Dimensions',
3334
行头: 'Rows',

packages/s2-core/src/common/i18n/zh_CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const ZH_CN = {
2828
选择下钻维度: '选择下钻维度',
2929
恢复默认: '恢复默认',
3030
搜索字段: '搜索字段',
31+
指标: '指标',
3132

3233
// switcher
3334
行列切换: '行列切换',

packages/s2-react/playground/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const sliderOptions: SliderSingleProps = {
105105
export const strategyOptions: S2Options = {
106106
width: 1000,
107107
height: 400,
108-
cornerText: '时间',
108+
cornerText: '指标',
109109
headerActionIcons: [
110110
{
111111
iconNames: ['Trend'],

0 commit comments

Comments
 (0)