1
1
import { Column } from '../../../../src' ;
2
- import { salesByArea } from '../../../data/sales' ;
2
+ import { salesByArea , subSalesByArea } from '../../../data/sales' ;
3
3
import { createDiv } from '../../../utils/dom' ;
4
4
5
5
describe ( 'column label' , ( ) => {
6
- it ( 'position: top' , ( ) => {
7
- const column = new Column ( createDiv ( ) , {
6
+ it ( 'position top' , ( ) => {
7
+ const column = new Column ( createDiv ( 'position top' ) , {
8
8
width : 400 ,
9
9
height : 300 ,
10
10
data : salesByArea ,
@@ -36,8 +36,8 @@ describe('column label', () => {
36
36
} ) ;
37
37
} ) ;
38
38
39
- it ( 'label position middle' , ( ) => {
40
- const column = new Column ( createDiv ( ) , {
39
+ it ( 'position middle' , ( ) => {
40
+ const column = new Column ( createDiv ( 'position middle' ) , {
41
41
width : 400 ,
42
42
height : 300 ,
43
43
data : salesByArea ,
@@ -62,8 +62,8 @@ describe('column label', () => {
62
62
expect ( geometry . labelOption . cfg ) . toEqual ( { position : 'middle' } ) ;
63
63
} ) ;
64
64
65
- it ( 'label position bottom' , ( ) => {
66
- const column = new Column ( createDiv ( ) , {
65
+ it ( 'position bottom' , ( ) => {
66
+ const column = new Column ( createDiv ( 'position bottom' ) , {
67
67
width : 400 ,
68
68
height : 300 ,
69
69
data : salesByArea ,
@@ -87,4 +87,109 @@ describe('column label', () => {
87
87
// @ts -ignore
88
88
expect ( geometry . labelOption . cfg ) . toEqual ( { position : 'bottom' } ) ;
89
89
} ) ;
90
+
91
+ it ( 'group column position top' , ( ) => {
92
+ const column = new Column ( createDiv ( 'group column position top' ) , {
93
+ width : 400 ,
94
+ height : 300 ,
95
+ data : subSalesByArea ,
96
+ xField : 'area' ,
97
+ yField : 'sales' ,
98
+ colorField : 'series' ,
99
+ meta : {
100
+ sales : {
101
+ nice : true ,
102
+ formatter : ( v ) => `${ Math . floor ( v / 10000 ) } 万` ,
103
+ } ,
104
+ } ,
105
+ label : {
106
+ position : 'top' ,
107
+ } ,
108
+ } ) ;
109
+
110
+ column . render ( ) ;
111
+
112
+ const geometry = column . chart . geometries [ 0 ] ;
113
+ const labelGroups = geometry . labelsContainer . getChildren ( ) ;
114
+
115
+ // @ts -ignore
116
+ expect ( geometry . labelOption . cfg ) . toEqual ( {
117
+ position : 'top' ,
118
+ } ) ;
119
+ expect ( labelGroups ) . toHaveLength ( subSalesByArea . length ) ;
120
+ labelGroups . forEach ( ( label ) => {
121
+ const origin = label . get ( 'origin' ) . _origin ;
122
+ expect ( label . get ( 'children' ) [ 0 ] . attr ( 'text' ) ) . toBe ( `${ Math . floor ( origin . sales / 10000 ) } 万` ) ;
123
+ } ) ;
124
+ } ) ;
125
+
126
+ it ( 'group column position middle' , ( ) => {
127
+ const column = new Column ( createDiv ( 'group column position middle' ) , {
128
+ width : 400 ,
129
+ height : 300 ,
130
+ data : subSalesByArea ,
131
+ xField : 'area' ,
132
+ yField : 'sales' ,
133
+ colorField : 'series' ,
134
+ meta : {
135
+ sales : {
136
+ nice : true ,
137
+ formatter : ( v ) => `${ Math . floor ( v / 10000 ) } 万` ,
138
+ } ,
139
+ } ,
140
+ label : {
141
+ position : 'middle' ,
142
+ } ,
143
+ } ) ;
144
+
145
+ column . render ( ) ;
146
+
147
+ const geometry = column . chart . geometries [ 0 ] ;
148
+ const labelGroups = geometry . labelsContainer . getChildren ( ) ;
149
+
150
+ // @ts -ignore
151
+ expect ( geometry . labelOption . cfg ) . toEqual ( {
152
+ position : 'middle' ,
153
+ } ) ;
154
+ expect ( labelGroups ) . toHaveLength ( subSalesByArea . length ) ;
155
+ labelGroups . forEach ( ( label ) => {
156
+ const origin = label . get ( 'origin' ) . _origin ;
157
+ expect ( label . get ( 'children' ) [ 0 ] . attr ( 'text' ) ) . toBe ( `${ Math . floor ( origin . sales / 10000 ) } 万` ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ it ( 'group column position bottom' , ( ) => {
162
+ const column = new Column ( createDiv ( 'group column position bottom' ) , {
163
+ width : 400 ,
164
+ height : 300 ,
165
+ data : subSalesByArea ,
166
+ xField : 'area' ,
167
+ yField : 'sales' ,
168
+ colorField : 'series' ,
169
+ meta : {
170
+ sales : {
171
+ nice : true ,
172
+ formatter : ( v ) => `${ Math . floor ( v / 10000 ) } 万` ,
173
+ } ,
174
+ } ,
175
+ label : {
176
+ position : 'bottom' ,
177
+ } ,
178
+ } ) ;
179
+
180
+ column . render ( ) ;
181
+
182
+ const geometry = column . chart . geometries [ 0 ] ;
183
+ const labelGroups = geometry . labelsContainer . getChildren ( ) ;
184
+
185
+ // @ts -ignore
186
+ expect ( geometry . labelOption . cfg ) . toEqual ( {
187
+ position : 'bottom' ,
188
+ } ) ;
189
+ expect ( labelGroups ) . toHaveLength ( subSalesByArea . length ) ;
190
+ labelGroups . forEach ( ( label ) => {
191
+ const origin = label . get ( 'origin' ) . _origin ;
192
+ expect ( label . get ( 'children' ) [ 0 ] . attr ( 'text' ) ) . toBe ( `${ Math . floor ( origin . sales / 10000 ) } 万` ) ;
193
+ } ) ;
194
+ } ) ;
90
195
} ) ;
0 commit comments