Skip to content

Commit

Permalink
refactor(word-cloud): 优化变量命名
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhonghe committed Oct 27, 2020
1 parent daee178 commit b5993b7
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/manual/plots/word-cloud.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ order: 0

默认配置: _'archimedean'_

#### customPlacement
#### placementStrategy

**可选**, _function_

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/plots/word-cloud.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ order: 0

默认配置: _'archimedean'_

#### customPlacement
#### placementStrategy

**可选**, _function_

Expand Down
2 changes: 1 addition & 1 deletion examples/word-cloud/basic/API.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

默认配置: _'archimedean'_

#### customPlacement
#### placementStrategy

**可选**, _function_

Expand Down
2 changes: 1 addition & 1 deletion examples/word-cloud/basic/API.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

默认配置: _'archimedean'_

#### customPlacement
#### placementStrategy

**可选**, _function_

Expand Down
2 changes: 1 addition & 1 deletion examples/word-cloud/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"screenshot": "https://gw.alipayobjects.com/mdn/rms_f5c722/afts/img/A*id4CSZIMCtsAAAAAAAAAAABkARQnAQ"
},
{
"filename": "custom-placement.ts",
"filename": "placement-strategy.ts",
"title": {
"zh": "词云图-自定义每个词语位置",
"en": "Word Cloud chart - custom placement"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const wordCloud = new WordCloud('container', {
fontSize: 16,
rotation: 0,
},
customPlacement(word, index, words) {
placementStrategy(word, index, words) {
const width = this.ele.clientWidth;
const height = this.ele.clientHeight;
const length = words.length;
Expand Down
2 changes: 1 addition & 1 deletion src/plots/word-cloud/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ export interface WordCloudOptions extends Options {
* 自定义每个词语的坐标。
* 注意:使用该选项时,应配合 `wordStyle` 中的其它选项同时使用。
*/
readonly customPlacement?: (word: Word, index?: number, words?: Word[]) => { x: number; y: number };
readonly placementStrategy?: (word: Word, index?: number, words?: Word[]) => Partial<Tag> & { x: number; y: number };
readonly wordStyle?: WordStyle;
}
6 changes: 3 additions & 3 deletions src/plots/word-cloud/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function transform(params: Params<WordCloudOptions>): Tag[] {
timeInterval,
random,
spiral,
customPlacement,
placementStrategy,
} = rawOptions;
if (!data || !data.length) {
return [];
Expand Down Expand Up @@ -56,7 +56,7 @@ export function transform(params: Params<WordCloudOptions>): Tag[] {
};

// 自定义布局函数
if (isFunction(customPlacement)) {
if (isFunction(placementStrategy)) {
return words.map((word: Word, index: number, words: Word[]) => ({
...word,
hasText: !!word.text,
Expand All @@ -65,7 +65,7 @@ export function transform(params: Params<WordCloudOptions>): Tag[] {
rotate: functor(options.rotate)(word, index, words),
size: functor(options.fontSize)(word, index, words),
style: 'normal',
...customPlacement.call(chart, word, index, words),
...placementStrategy.call(chart, word, index, words),
}));
}

Expand Down

0 comments on commit b5993b7

Please sign in to comment.