File tree 4 files changed +179
-18
lines changed
4 files changed +179
-18
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -202,8 +202,6 @@ export class ColCell extends HeaderCell {
202
202
width : width + ( scrollContainsRowHeader ? cornerWidth : 0 ) ,
203
203
} ;
204
204
205
- this . handleViewport ( viewport ) ;
206
-
207
205
const { textAlign } = this . getTextStyle ( ) ;
208
206
const adjustedViewport = adjustColHeaderScrollingViewport (
209
207
viewport ,
@@ -521,13 +519,4 @@ export class ColCell extends HeaderCell {
521
519
protected isLastColumn ( ) {
522
520
return isLastColumnAfterHidden ( this . spreadsheet , this . meta . id ) ;
523
521
}
524
-
525
- /**
526
- * 计算文本位置时候需要,留给后代根据情况(固定列)覆盖
527
- * @param viewport
528
- * @returns viewport
529
- */
530
- protected handleViewport ( viewport : AreaRange ) : AreaRange {
531
- return viewport ;
532
- }
533
522
}
Original file line number Diff line number Diff line change @@ -137,11 +137,4 @@ export class TableColCell extends ColCell {
137
137
fill : backgroundColor ,
138
138
} ) ;
139
139
}
140
-
141
- protected handleViewport ( viewport : AreaRange ) : AreaRange {
142
- if ( this . isFrozenCell ( ) ) {
143
- viewport . start = 0 ;
144
- }
145
- return viewport ;
146
- }
147
140
}
You can’t perform that action at this time.
0 commit comments