Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/word-cloud/basic/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/world-population.jso
data,
width: 600,
height: 500,
autoFit: false,
wordField: 'x',
weightField: 'value',
color: '#6262ff',
Expand Down
1 change: 0 additions & 1 deletion examples/word-cloud/basic/demo/image-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ imageMask.onload = () => {
// 宽高设置最好根据 imageMask 做调整
width: 600,
height: 400,
autoFit: false,
wordField: 'name',
weightField: 'value',
imageMask,
Expand Down
47 changes: 31 additions & 16 deletions src/core/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,10 @@ export abstract class Plot<O extends PickOptions> extends EE {
public render() {
// 暴力处理,先清空再渲染,需要 G2 层自行做好更新渲染
this.chart.clear();

const adaptor = this.getSchemaAdaptor();

const { padding } = this.options;
// 更新 padding
this.chart.padding = padding;

// 转化成 G2 API
adaptor({
chart: this.chart,
options: this.options,
});

// 执行 adaptor
this.execAdaptor();
// 渲染
this.chart.render();

// 绑定
this.bindSizeSensor();
}
Expand Down Expand Up @@ -219,16 +208,42 @@ export abstract class Plot<O extends PickOptions> extends EE {
this.off();
}

/**
* 执行 adaptor 操作
*/
protected execAdaptor() {
const adaptor = this.getSchemaAdaptor();

const { padding } = this.options;
// 更新 padding
this.chart.padding = padding;

// 转化成 G2 API
adaptor({
chart: this.chart,
options: this.options,
});
}

/**
* 当图表容器大小变化的时候,执行的函数
*/
protected triggerResize() {
this.chart.forceFit();
}

/**
* 绑定 dom 容器大小变化的事件
*/
private bindSizeSensor() {
this.unbindSizeSensor();
if (this.unbind) {
return;
}

const { autoFit = true } = this.options;
if (autoFit) {
this.unbind = bind(this.container, () => {
this.chart.forceFit();
this.triggerResize();
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/plots/word-cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ export class WordCloud extends Plot<WordCloudOptions> {
protected getSchemaAdaptor(): Adaptor<WordCloudOptions> {
return adaptor;
}

/**
* 覆写父类的方法,因为词云图使用 data-set 进行布局,原理上有些不一样
*/
protected triggerResize() {
// 重新做一遍 data-set 的处理逻辑,这个适和其他图形不一样的地阿芳
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释错别字。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

啊啊啊,你一会帮忙改掉。

this.execAdaptor();
// 执行父类的方法
super.triggerResize();
}
}