From df340bda5d53e94867e354b17a83bc6fb46f3db3 Mon Sep 17 00:00:00 2001 From: RoxaneBurri Date: Fri, 10 Mar 2023 18:16:38 +0100 Subject: [PATCH] fix: try to change the map to a reduce --- src/App.tsx | 16 ++++++++++------ src/utils.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6a1ca6e..eef9c15 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,17 +23,20 @@ const Wordcloud = () => { console.log("start"); setWords((prevWords) => { - let passRect: WordArray = []; + let init: WordArray = []; - const newWords = prevWords.map((w) => { + const newWords = prevWords.reduce((passRect, w) => { const elem = document.getElementById(w.id); if (elem) { if (passRect.length === 0) { w = setFirstWordInCenterOfParent(w, PARENT_ID); + console.log("first elem"); + console.log("w", w); + passRect.push(w); - console.log(w); } else { + console.log("w before", w); // Get the height and width of the word const heightW = elem.getBoundingClientRect().height; const widthW = elem.getBoundingClientRect().width; @@ -48,11 +51,12 @@ const Wordcloud = () => { w = futurPosition(w, passRect, 1, PARENT_ID); passRect.push(w); + console.log("w after", w); } } - return w; - }); - + return passRect; + // return w; + }, init); return newWords; }); console.log("stop"); diff --git a/src/utils.ts b/src/utils.ts index fb06ffb..4023e2f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -157,6 +157,7 @@ export const futurPosition = ( while (!isCollision) { const netForceW = netForce(word, passRect); + const rightAnglePoint = getTriangleFromNetForce(word, netForceW); const futurWPosition = moveWordOnHypotenuse(