Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setText(text : string) {
- this.wordService.GetWordsCount(text).then((list) => {
- // Give exponential weight to each word count to emphasize
- // small differences. A better algorithm could find the best power
- // based on the variance.
- let scale = list.map((ww) => new WordWeight(ww.word, Math.pow(ww.count,2)));
- // find maximum weight in the array.
- let max = scale.map((ww) => ww.count).
- reduce((max, cur) => {
- return Math.max(max, cur);
- }, 0);
- // scale each word to a fixed size (this.maxSize) so the more
- // important word will be this.maxSize and the others will be smaller
- // accordingly.
- scale = scale.map((ww) => new WordWeight(ww.word, (ww.count / max) * this.maxSize));
- // prepare the array required by WordCloud.
- let outarray = scale.map((ww) => [ww.word, ww.count]);
- // Call WordCloud pointing it to our canvas.
- WordCloud(document.getElementById("my_canvas"), {
- list: outarray,
- gridSize: 1,
- minSize: 0,
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement