File tree 4 files changed +41
-18
lines changed
examples/word-cloud/basic/demo
4 files changed +41
-18
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/world-population.jso
7
7
data,
8
8
width : 600 ,
9
9
height : 500 ,
10
- autoFit : false ,
11
10
wordField : 'x' ,
12
11
weightField : 'value' ,
13
12
color : '#6262ff' ,
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ imageMask.onload = () => {
14
14
// 宽高设置最好根据 imageMask 做调整
15
15
width : 600 ,
16
16
height : 400 ,
17
- autoFit : false ,
18
17
wordField : 'name' ,
19
18
weightField : 'value' ,
20
19
imageMask,
Original file line number Diff line number Diff line change @@ -122,21 +122,10 @@ export abstract class Plot<O extends PickOptions> extends EE {
122
122
public render ( ) {
123
123
// 暴力处理,先清空再渲染,需要 G2 层自行做好更新渲染
124
124
this . chart . clear ( ) ;
125
-
126
- const adaptor = this . getSchemaAdaptor ( ) ;
127
-
128
- const { padding } = this . options ;
129
- // 更新 padding
130
- this . chart . padding = padding ;
131
-
132
- // 转化成 G2 API
133
- adaptor ( {
134
- chart : this . chart ,
135
- options : this . options ,
136
- } ) ;
137
-
125
+ // 执行 adaptor
126
+ this . execAdaptor ( ) ;
127
+ // 渲染
138
128
this . chart . render ( ) ;
139
-
140
129
// 绑定
141
130
this . bindSizeSensor ( ) ;
142
131
}
@@ -219,16 +208,42 @@ export abstract class Plot<O extends PickOptions> extends EE {
219
208
this . off ( ) ;
220
209
}
221
210
211
+ /**
212
+ * 执行 adaptor 操作
213
+ */
214
+ protected execAdaptor ( ) {
215
+ const adaptor = this . getSchemaAdaptor ( ) ;
216
+
217
+ const { padding } = this . options ;
218
+ // 更新 padding
219
+ this . chart . padding = padding ;
220
+
221
+ // 转化成 G2 API
222
+ adaptor ( {
223
+ chart : this . chart ,
224
+ options : this . options ,
225
+ } ) ;
226
+ }
227
+
228
+ /**
229
+ * 当图表容器大小变化的时候,执行的函数
230
+ */
231
+ protected triggerResize ( ) {
232
+ this . chart . forceFit ( ) ;
233
+ }
234
+
222
235
/**
223
236
* 绑定 dom 容器大小变化的事件
224
237
*/
225
238
private bindSizeSensor ( ) {
226
- this . unbindSizeSensor ( ) ;
239
+ if ( this . unbind ) {
240
+ return ;
241
+ }
227
242
228
243
const { autoFit = true } = this . options ;
229
244
if ( autoFit ) {
230
245
this . unbind = bind ( this . container , ( ) => {
231
- this . chart . forceFit ( ) ;
246
+ this . triggerResize ( ) ;
232
247
} ) ;
233
248
}
234
249
}
Original file line number Diff line number Diff line change @@ -41,4 +41,14 @@ export class WordCloud extends Plot<WordCloudOptions> {
41
41
protected getSchemaAdaptor ( ) : Adaptor < WordCloudOptions > {
42
42
return adaptor ;
43
43
}
44
+
45
+ /**
46
+ * 覆写父类的方法,因为词云图使用 data-set 进行布局,原理上有些不一样
47
+ */
48
+ protected triggerResize ( ) {
49
+ // 重新做一遍 data-set 的处理逻辑,这个适和其他图形不一样的地阿芳
50
+ this . execAdaptor ( ) ;
51
+ // 执行父类的方法
52
+ super . triggerResize ( ) ;
53
+ }
44
54
}
You can’t perform that action at this time.
0 commit comments