This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit 44b1b751014f3454a69f867626ca3590ea97db0c Author: Sebb <[email protected]> AuthorDate: Thu Nov 18 01:37:22 2021 +0000 Simplify using for-of loops --- webui/js/wordcloud.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/webui/js/wordcloud.js b/webui/js/wordcloud.js index 9f99a38..8594012 100644 --- a/webui/js/wordcloud.js +++ b/webui/js/wordcloud.js @@ -59,8 +59,7 @@ async function wordCloud(hash, width, height, obj) { svg.setAttribute("width", width) svg.setAttribute("height", height) svg.setAttribute("class", "wordcloud") - for (let n = 0; n < hashSorted.length; n++) { - let word = hashSorted[n] + for (let word of hashSorted) { let size = 0; let expected_area = ( Math.sqrt(hash[word]) / total ) * (space*0.9) //console.log(expected_area) @@ -81,13 +80,11 @@ async function wordCloud(hash, width, height, obj) { break } } - - - + let popped = false - + // Try with random placement - + textBox = makeWord(word, size) textBox.setAttribute("id", "svg_wc_" + word) svg.appendChild(textBox) @@ -101,13 +98,13 @@ async function wordCloud(hash, width, height, obj) { } textBox.setAttribute("font-size", ss + "px") - let w = textBox.getBoundingClientRect() + w = textBox.getBoundingClientRect() for (let l = 0; l < 80; l++) { let nx = 4 + (Math.random() * (width-8-w.width)) let ny = 4 + w.height + ((l/80) * (height-8-w.height)) let it = false - for (let b = 0; b < boxes.length; b++) { - if (fastIntersect(textBox, boxes[b], nx, ny)) { + for (let box of boxes) { + if (fastIntersect(textBox, box, nx, ny)) { it = true break } @@ -136,8 +133,7 @@ async function wordCloud(hash, width, height, obj) { } // Try to size up texts a bit - for (let i =0; i < boxes.length; i++) { - let textBox = boxes[i] + for (let textBox of boxes) { let osize = parseFloat(textBox.getAttribute('font-size')) let psize = osize for (let n = 1; n < 1.4; n+=0.2) { @@ -145,8 +141,8 @@ async function wordCloud(hash, width, height, obj) { textBox.setAttribute("font-size", nsize + "px") let w = textBox.getBoundingClientRect() let good = true - for (let b =0; b < boxes.length; b++) { - if (fastIntersect(textBox, boxes[b])) { + for (let box of boxes) { + if (fastIntersect(textBox, box)) { good = false break }
