Skip to content

Commit

Permalink
fix: bound of the word cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Mar 17, 2023
1 parent cb405fb commit 3f3af71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/Wordcloud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ const Wordcloud = ({
});
};

console.log("before", rectParent);

const parent = boundParent(
words.filter((w) => Boolean(w.rect)).map((w) => w.rect) as Rectangle[],
rectParent
);

console.log("after", parent);

React.useEffect(() => {
updateWords();
}, []);
Expand Down
8 changes: 2 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,11 @@ export const boundParent = (
y: rect.y - rect.height / 2,
};

// console.log(topLeftRect);

const bottomRightRect = {
x: rect.x + rect.width / 2,
y: rect.y + rect.height / 2,
};

// const distX = topLeftRect.x < bound.x;

// value on left
if (topLeftRect.x < bound.x) {
bound.x = topLeftRect.x;
Expand All @@ -273,13 +269,13 @@ export const boundParent = (
if (topLeftRect.y < bound.y) {
bound.y = topLeftRect.y;
}
// value on right

// value on right
if (bottomRightRect.x > bound.width) {
bound.width = bottomRightRect.x;
}
// value on bottom

// value on bottom
if (bottomRightRect.y > bound.height) {
bound.height = bottomRightRect.y;
}
Expand Down

0 comments on commit 3f3af71

Please sign in to comment.