-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(word-cloud): imageMask选项支持url字符串格式 #1617
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { WordCloud } from '@antv/g2plot'; | ||
|
||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/antv-keywords.json') | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const wordCloud = new WordCloud('container', { | ||
data, | ||
width: 600, | ||
height: 400, | ||
wordField: 'name', | ||
weightField: 'value', | ||
imageMask: | ||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcoAAADHCAIAAAAWF4ThAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAA5GSURBVHhe7d1teuOoFkXhO5+MJ/PxeDyezKcvyKTixLYEnLMPIK/3Vz9dHxYCluRUrPzvPwCAAHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFeAUCCvAKABHkFAAnyCgAS5BUAJMgrAEiQVwCQIK8AIEFegR7Xz/91+bh8lb8Bp0degR7kFYfIK9CDvOLQafP6daD8tmWVYTwqvw4x8opDJ8hrSsr1erl8fn5+JGUR18t/6CP94c/L5Xq9Ttmn2wjbBngbVRoSwd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FAgrwCgAR5BQAJ8goAEuQVACTIKwBIkFcAkCCvACBBXgFAgrwCgAR5BQAJ8goAEuQVAAT+++//CT3TAOpn61kAAAAASUVORK5CYII=', | ||
wordStyle: { | ||
fontFamily: 'Verdana', | ||
fontSize: [8, 32], | ||
}, | ||
}); | ||
|
||
wordCloud.render(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
import { WordCloud } from '@antv/g2plot'; | ||
|
||
const imageMask = new Image(); | ||
imageMask.crossOrigin = ''; | ||
imageMask.src = 'https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*07tdTIOmvlYAAAAAAAAAAABkARQnAQ'; | ||
|
||
// 等待图片加载完成 | ||
imageMask.onload = () => { | ||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/antv-keywords.json') | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const wordCloud = new WordCloud('container', { | ||
data, | ||
// 宽高设置最好根据 imageMask 做调整 | ||
width: 600, | ||
height: 400, | ||
wordField: 'name', | ||
weightField: 'value', | ||
imageMask, | ||
wordStyle: { | ||
fontFamily: 'Verdana', | ||
fontSize: [8, 32], | ||
}, | ||
}); | ||
|
||
wordCloud.render(); | ||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/antv-keywords.json') | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const wordCloud = new WordCloud('container', { | ||
data, | ||
width: 600, | ||
height: 400, | ||
wordField: 'name', | ||
weightField: 'value', | ||
imageMask: 'https://gw.alipayobjects.com/mdn/rms_2274c3/afts/img/A*07tdTIOmvlYAAAAAAAAAAABkARQnAQ', | ||
wordStyle: { | ||
fontFamily: 'Verdana', | ||
fontSize: [8, 32], | ||
}, | ||
}); | ||
}; | ||
|
||
wordCloud.render(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { Plot } from '../../core/plot'; | |
import { Adaptor } from '../../core/adaptor'; | ||
import { WordCloudOptions } from './types'; | ||
import { adaptor } from './adaptor'; | ||
import { processImageMask } from './utils'; | ||
// 注册的shape | ||
import './shapes/word-cloud'; | ||
|
||
|
@@ -18,7 +19,6 @@ export class WordCloud extends Plot<WordCloudOptions> { | |
protected getDefaultOptions(): Partial<WordCloudOptions> { | ||
return deepMix({}, super.getDefaultOptions(), { | ||
timeInterval: 2000, | ||
autoFit: true, | ||
tooltip: { | ||
showTitle: false, | ||
showMarkers: false, | ||
|
@@ -36,6 +36,29 @@ export class WordCloud extends Plot<WordCloudOptions> { | |
}); | ||
} | ||
|
||
/** | ||
* 覆写父类方法,词云图需要加载图片资源,所以需要异步渲染 | ||
*/ | ||
public render() { | ||
const { imageMask } = this.options; | ||
|
||
if (!imageMask) { | ||
// 调用父类渲染函数 | ||
super.render(); | ||
return; | ||
} | ||
|
||
processImageMask(imageMask, (img) => { | ||
this.options = { | ||
...this.options, | ||
imageMask: img || null, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个可以在 adaptor 中处理吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1,现在 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 效果主要取决于图表的加载时间,我觉得目前的方式也可以,但文档里面给个建议,URL 方式不要使用过大的图片。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前来看,用base64效果最好。 |
||
|
||
// 调用父类渲染函数 | ||
super.render(); | ||
}); | ||
} | ||
|
||
/** | ||
* 获取 词云图 的适配器 | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里赞