Skip to content

Commit

Permalink
fix: try to change the map to a reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Mar 10, 2023
1 parent ecd6aff commit df340bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const futurPosition = (

while (!isCollision) {
const netForceW = netForce(word, passRect);

const rightAnglePoint = getTriangleFromNetForce(word, netForceW);

const futurWPosition = moveWordOnHypotenuse(
Expand Down

0 comments on commit df340bd

Please sign in to comment.