Skip to content

Commit c15f8c8

Browse files
wywppkdlijinke666
andauthored
fix: 明细表存在横向滚动条时多列头文本不居中 close #2199 (#2200)
Co-authored-by: Jinke Li <[email protected]>
1 parent 83b8e4d commit c15f8c8

File tree

4 files changed

+179
-18
lines changed

4 files changed

+179
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @description spec for issue #2199
3+
* https://github.com/antvis/S2/issues/2199
4+
* 明细表: 当有冻结列 + 列分组的情况下, 会出现列头文本不居中现象
5+
*/
6+
import { getContainer } from 'tests/util/helpers';
7+
import dataCfg from '../data/data-issue-2199.json';
8+
import { TableSheet } from '@/sheet-type';
9+
import type { S2Options } from '@/common/interface';
10+
11+
const s2Options: S2Options = {
12+
width: 300,
13+
height: 480,
14+
showSeriesNumber: true,
15+
frozenColCount: 1,
16+
};
17+
18+
describe('ColCell Text Center Tests', () => {
19+
test('should draw text centered in cell', () => {
20+
const s2 = new TableSheet(getContainer(), dataCfg, s2Options);
21+
s2.render();
22+
23+
s2.facet.updateScrollOffset({ offsetX: { value: 500, animate: false } });
24+
25+
const node = s2.getColumnNodes(0).slice(-1)?.[0];
26+
const cell = node?.belongsCell;
27+
const { width: nodeWidth, x: nodeX } = node;
28+
const { width: textWidth, x: textXActual } = cell.getContentArea();
29+
const textXCalc = nodeX + (nodeWidth - textWidth) / 2;
30+
expect(textXCalc).toBeCloseTo(textXActual);
31+
});
32+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"fields": {
3+
"columns": [
4+
{
5+
"key": "area",
6+
"children": ["province", "city"]
7+
},
8+
"type",
9+
{
10+
"key": "money",
11+
"children": [
12+
{
13+
"key": "price"
14+
}
15+
]
16+
}
17+
]
18+
},
19+
"meta": [
20+
{
21+
"field": "province",
22+
"name": "省份"
23+
},
24+
{
25+
"field": "city",
26+
"name": "城市"
27+
},
28+
{
29+
"field": "type",
30+
"name": "商品类别"
31+
},
32+
{
33+
"field": "price",
34+
"name": "价格"
35+
},
36+
{
37+
"field": "cost",
38+
"name": "成本"
39+
},
40+
{
41+
"field": "area",
42+
"name": "位置"
43+
},
44+
{
45+
"field": "money",
46+
"name": "金额"
47+
}
48+
],
49+
"data": [
50+
{
51+
"province": "浙江",
52+
"city": "杭州",
53+
"type": "",
54+
"price": 1
55+
},
56+
{
57+
"province": "浙江",
58+
"city": "杭州",
59+
"type": "纸张",
60+
"price": 2
61+
},
62+
{
63+
"province": "浙江",
64+
"city": "舟山",
65+
"type": "",
66+
"price": 17
67+
},
68+
{
69+
"province": "浙江",
70+
"city": "舟山",
71+
"type": "纸张",
72+
"price": 6
73+
},
74+
{
75+
"province": "吉林",
76+
"city": "长春",
77+
"type": "",
78+
"price": 8
79+
},
80+
{
81+
"province": "吉林",
82+
"city": "白山",
83+
"type": "",
84+
"price": 12
85+
},
86+
{
87+
"province": "吉林",
88+
"city": "长春",
89+
"type": "纸张",
90+
"price": 3
91+
},
92+
{
93+
"province": "吉林",
94+
"city": "白山",
95+
"type": "纸张",
96+
"price": 25
97+
},
98+
{
99+
"province": "浙江",
100+
"city": "杭州",
101+
"type": "",
102+
"price": 20
103+
},
104+
{
105+
"province": "浙江",
106+
"city": "杭州",
107+
"type": "纸张",
108+
"price": 10
109+
},
110+
{
111+
"province": "浙江",
112+
"city": "舟山",
113+
"type": "",
114+
"price": 15
115+
},
116+
{
117+
"province": "浙江",
118+
"city": "舟山",
119+
"type": "纸张",
120+
"price": 2
121+
},
122+
{
123+
"province": "吉林",
124+
"city": "长春",
125+
"type": "",
126+
"price": 15
127+
},
128+
{
129+
"province": "吉林",
130+
"city": "白山",
131+
"type": "",
132+
"price": 30
133+
},
134+
{
135+
"province": "吉林",
136+
"city": "长春",
137+
"type": "纸张",
138+
"price": 40
139+
},
140+
{
141+
"province": "吉林",
142+
"city": "白山",
143+
"type": "纸张",
144+
"price": 50
145+
}
146+
]
147+
}

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

-11
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ export class ColCell extends HeaderCell {
202202
width: width + (scrollContainsRowHeader ? cornerWidth : 0),
203203
};
204204

205-
this.handleViewport(viewport);
206-
207205
const { textAlign } = this.getTextStyle();
208206
const adjustedViewport = adjustColHeaderScrollingViewport(
209207
viewport,
@@ -521,13 +519,4 @@ export class ColCell extends HeaderCell {
521519
protected isLastColumn() {
522520
return isLastColumnAfterHidden(this.spreadsheet, this.meta.id);
523521
}
524-
525-
/**
526-
* 计算文本位置时候需要,留给后代根据情况(固定列)覆盖
527-
* @param viewport
528-
* @returns viewport
529-
*/
530-
protected handleViewport(viewport: AreaRange): AreaRange {
531-
return viewport;
532-
}
533522
}

packages/s2-core/src/cell/table-col-cell.ts

-7
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,4 @@ export class TableColCell extends ColCell {
137137
fill: backgroundColor,
138138
});
139139
}
140-
141-
protected handleViewport(viewport: AreaRange): AreaRange {
142-
if (this.isFrozenCell()) {
143-
viewport.start = 0;
144-
}
145-
return viewport;
146-
}
147140
}

0 commit comments

Comments
 (0)