Skip to content

Commit

Permalink
Merge pull request #169 from yuhongda/gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
timdream authored Mar 17, 2021
2 parents e3b2528 + 05406f0 commit 2a63a00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ wordcloud2.js works around it by scaling the canvas, but you may be interested t

WordCloud.minFontSize

## Stop the renderring

Sometimes we need to stop wordcloud2.js renderring, to optimize the component renderring performance, especially in some FE libraries like 'React'.
In this scenario, you can just call the function below

WordCloud.stop

```js
useEffect(() => {
...
return () => {
// stop the renderring
WordCloud.stop();
};
}, [deps]);
```

## Usage

WordCloud(elements, options);
Expand Down
9 changes: 7 additions & 2 deletions src/wordcloud2.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ if (!window.clearImmediate) {
return arr
}

var timer;
var WordCloud = function WordCloud (elements, options) {
if (!isSupported) {
return
Expand Down Expand Up @@ -1168,8 +1169,7 @@ if (!window.clearImmediate) {
}

addEventListener('wordcloudstart', anotherWordCloudStart)

var timer = loopingFunction(function loop () {
timer = loopingFunction(function loop () {
if (i >= settings.list.length) {
stoppingFunction(timer)
sendEvent('wordcloudstop', false)
Expand Down Expand Up @@ -1202,6 +1202,11 @@ if (!window.clearImmediate) {

WordCloud.isSupported = isSupported
WordCloud.minFontSize = minFontSize
WordCloud.stop = function stop () {
if (timer) {
window.clearImmediate(timer)
}
}

// Expose the library as an AMD module
if (typeof define === 'function' && define.amd) { // eslint-disable-line no-undef
Expand Down

0 comments on commit 2a63a00

Please sign in to comment.