Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. setText(text : string) {
  2. this.wordService.GetWordsCount(text).then((list) => {
  3.  
  4. // Give exponential weight to each word count to emphasize
  5. // small differences. A better algorithm could find the best power
  6. // based on the variance.
  7. let scale = list.map((ww) => new WordWeight(ww.word, Math.pow(ww.count,2)));
  8.  
  9. // find maximum weight in the array.
  10. let max = scale.map((ww) => ww.count).
  11. reduce((max, cur) => {
  12. return Math.max(max, cur);
  13. }, 0);
  14.  
  15. // scale each word to a fixed size (this.maxSize) so the more
  16. // important word will be this.maxSize and the others will be smaller
  17. // accordingly.
  18. scale = scale.map((ww) => new WordWeight(ww.word, (ww.count / max) * this.maxSize));
  19.  
  20. // prepare the array required by WordCloud.
  21. let outarray = scale.map((ww) => [ww.word, ww.count]);
  22.  
  23. // Call WordCloud pointing it to our canvas.
  24. WordCloud(document.getElementById("my_canvas"), {
  25. list: outarray,
  26. gridSize: 1,
  27. minSize: 0,
  28. });
  29.  
  30. });
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement