Skip to content

Commit c26ec95

Browse files
authored
fix(word-cloud): word cloud should exec data-set transform when resize (#1607)
1 parent f7a17ed commit c26ec95

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

examples/word-cloud/basic/demo/basic.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/world-population.jso
77
data,
88
width: 600,
99
height: 500,
10-
autoFit: false,
1110
wordField: 'x',
1211
weightField: 'value',
1312
color: '#6262ff',

examples/word-cloud/basic/demo/image-mask.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ imageMask.onload = () => {
1414
// 宽高设置最好根据 imageMask 做调整
1515
width: 600,
1616
height: 400,
17-
autoFit: false,
1817
wordField: 'name',
1918
weightField: 'value',
2019
imageMask,

src/core/plot.ts

+31-16
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,10 @@ export abstract class Plot<O extends PickOptions> extends EE {
122122
public render() {
123123
// 暴力处理,先清空再渲染,需要 G2 层自行做好更新渲染
124124
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+
// 渲染
138128
this.chart.render();
139-
140129
// 绑定
141130
this.bindSizeSensor();
142131
}
@@ -219,16 +208,42 @@ export abstract class Plot<O extends PickOptions> extends EE {
219208
this.off();
220209
}
221210

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+
222235
/**
223236
* 绑定 dom 容器大小变化的事件
224237
*/
225238
private bindSizeSensor() {
226-
this.unbindSizeSensor();
239+
if (this.unbind) {
240+
return;
241+
}
227242

228243
const { autoFit = true } = this.options;
229244
if (autoFit) {
230245
this.unbind = bind(this.container, () => {
231-
this.chart.forceFit();
246+
this.triggerResize();
232247
});
233248
}
234249
}

src/plots/word-cloud/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ export class WordCloud extends Plot<WordCloudOptions> {
4141
protected getSchemaAdaptor(): Adaptor<WordCloudOptions> {
4242
return adaptor;
4343
}
44+
45+
/**
46+
* 覆写父类的方法,因为词云图使用 data-set 进行布局,原理上有些不一样
47+
*/
48+
protected triggerResize() {
49+
// 重新做一遍 data-set 的处理逻辑,这个适和其他图形不一样的地阿芳
50+
this.execAdaptor();
51+
// 执行父类的方法
52+
super.triggerResize();
53+
}
4454
}

0 commit comments

Comments
 (0)