From b5993b74f596ccd9f2dc8de4b1a256619a23f37d Mon Sep 17 00:00:00 2001 From: zhangzhonghe <958414905@qq.com> Date: Tue, 27 Oct 2020 17:39:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(word-cloud):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/manual/plots/word-cloud.en.md | 2 +- docs/manual/plots/word-cloud.zh.md | 2 +- examples/word-cloud/basic/API.en.md | 2 +- examples/word-cloud/basic/API.zh.md | 2 +- examples/word-cloud/basic/demo/meta.json | 2 +- .../demo/{custom-placement.ts => placement-strategy.ts} | 2 +- src/plots/word-cloud/types.ts | 2 +- src/plots/word-cloud/utils.ts | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) rename examples/word-cloud/basic/demo/{custom-placement.ts => placement-strategy.ts} (89%) diff --git a/docs/manual/plots/word-cloud.en.md b/docs/manual/plots/word-cloud.en.md index 5c13a2248a..4878012176 100644 --- a/docs/manual/plots/word-cloud.en.md +++ b/docs/manual/plots/word-cloud.en.md @@ -61,7 +61,7 @@ order: 0 默认配置: _'archimedean'_ -#### customPlacement +#### placementStrategy **可选**, _function_ diff --git a/docs/manual/plots/word-cloud.zh.md b/docs/manual/plots/word-cloud.zh.md index a3be380856..989ba940ed 100644 --- a/docs/manual/plots/word-cloud.zh.md +++ b/docs/manual/plots/word-cloud.zh.md @@ -61,7 +61,7 @@ order: 0 默认配置: _'archimedean'_ -#### customPlacement +#### placementStrategy **可选**, _function_ diff --git a/examples/word-cloud/basic/API.en.md b/examples/word-cloud/basic/API.en.md index ec76378c70..82f46c2fa5 100644 --- a/examples/word-cloud/basic/API.en.md +++ b/examples/word-cloud/basic/API.en.md @@ -56,7 +56,7 @@ 默认配置: _'archimedean'_ -#### customPlacement +#### placementStrategy **可选**, _function_ diff --git a/examples/word-cloud/basic/API.zh.md b/examples/word-cloud/basic/API.zh.md index 65f35a6721..6a09410c3a 100644 --- a/examples/word-cloud/basic/API.zh.md +++ b/examples/word-cloud/basic/API.zh.md @@ -56,7 +56,7 @@ 默认配置: _'archimedean'_ -#### customPlacement +#### placementStrategy **可选**, _function_ diff --git a/examples/word-cloud/basic/demo/meta.json b/examples/word-cloud/basic/demo/meta.json index 54803cf617..40d6234b66 100644 --- a/examples/word-cloud/basic/demo/meta.json +++ b/examples/word-cloud/basic/demo/meta.json @@ -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" diff --git a/examples/word-cloud/basic/demo/custom-placement.ts b/examples/word-cloud/basic/demo/placement-strategy.ts similarity index 89% rename from examples/word-cloud/basic/demo/custom-placement.ts rename to examples/word-cloud/basic/demo/placement-strategy.ts index 7c8b609d29..954b1f0f50 100644 --- a/examples/word-cloud/basic/demo/custom-placement.ts +++ b/examples/word-cloud/basic/demo/placement-strategy.ts @@ -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; diff --git a/src/plots/word-cloud/types.ts b/src/plots/word-cloud/types.ts index aeccf9d550..c29e5c13b9 100644 --- a/src/plots/word-cloud/types.ts +++ b/src/plots/word-cloud/types.ts @@ -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 & { x: number; y: number }; readonly wordStyle?: WordStyle; } diff --git a/src/plots/word-cloud/utils.ts b/src/plots/word-cloud/utils.ts index e855c82291..0f2f587a4d 100644 --- a/src/plots/word-cloud/utils.ts +++ b/src/plots/word-cloud/utils.ts @@ -22,7 +22,7 @@ export function transform(params: Params): Tag[] { timeInterval, random, spiral, - customPlacement, + placementStrategy, } = rawOptions; if (!data || !data.length) { return []; @@ -56,7 +56,7 @@ export function transform(params: Params): Tag[] { }; // 自定义布局函数 - if (isFunction(customPlacement)) { + if (isFunction(placementStrategy)) { return words.map((word: Word, index: number, words: Word[]) => ({ ...word, hasText: !!word.text, @@ -65,7 +65,7 @@ export function transform(params: Params): 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), })); }