Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(wordcloud): add @visx/wordcloud #1311

Merged
merged 23 commits into from Aug 17, 2021

Conversation

craciuncezar
Copy link
Contributor

@craciuncezar craciuncezar commented Aug 13, 2021

🚀 Enhancements

achimedean
rectangular and with rotation

Copy link
Collaborator

@kristw kristw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I left some comments.
Please make sure the unit tests are passed as well.

packages/visx-wordcloud/.npmrc Show resolved Hide resolved
packages/visx-wordcloud/package.json Outdated Show resolved Hide resolved
packages/visx-wordcloud/package.json Outdated Show resolved Hide resolved
packages/visx-wordcloud/package.json Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/index.ts Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/useWordcloud.ts Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/useWordcloud.ts Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/Wordcloud.tsx Show resolved Hide resolved
const [cloudWords, setCloudWords] = useState<d3Cloud.Word[]>([]);

useEffect(() => {
const layout = d3Cloud<Datum>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't have to do any of these layout thing at all if width === 0 || height === 0?

if (width === 0 || height === 0) {
  return;
}

packages/visx-wordcloud/src/useWordcloud.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@williaster williaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow thanks for the great contribution @craciuncezar 🙌 !!!

this looks really great, I had just a few comments which hopefully won't be too tricky to address. excited for this to land 🔜 !

packages/visx-wordcloud/.npmrc Show resolved Hide resolved
packages/visx-wordcloud/package.json Outdated Show resolved Hide resolved
packages/visx-wordcloud/package.json Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/useWordcloud.ts Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/useWordcloud.ts Outdated Show resolved Hide resolved
packages/visx-wordcloud/test/Wordcloud.test.tsx Outdated Show resolved Hide resolved
@williaster williaster changed the title Wordcloud visualizaion new(wordcloud): add @visx/wordcloud Aug 14, 2021
}: WordcloudConfig<Datum>) {
const [cloudWords, setCloudWords] = useState<d3Cloud.Word[]>([]);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook uses a useEffcect, otherwise the d3 wordcloud would recreate its view every render.

The example that uses this hook, passes as a prop an inline function declaration. I would have thought that mean a new reference in the deps array every render, causing the wordcloud to constantly change if the parent component rerenders.

Does that not happen? Or was this accounted for somehow?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^I had a similar question, I think it would for sure have called the wordcloud layout for each render with the inline function. In the example specifically I think that would only have happened with a size change of the parent, but probably best to implement the example with perf in mind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purely for curiousity sake, do you think theres a way to change it inside the hook not to be concerned about constant rerender? i think this is unique across most of the visx packages right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions however I don't see how we can avoid this 🤔, I know it's not ideal but, as usual in React, it's up to the consumer to memoize or wrap fn in useCallback.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think unfortunately there's probably not a clean way to remove this, as @craciuncezar said it's common in React for memoization logic to be pushed to the consumer. We have this same requirement in other layout code in visx, I would guess that many consumers don't optimize their usage, but if they don't see perf issues it's probably okay (wordcloud perf may present more of an issue since it's a more complex algorithm)

Copy link
Collaborator

@williaster williaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo looking great @craciuncezar ! Thanks for all of the iteration on this.

I had 2 more minor comments but otherwise lgtm!

packages/visx-wordcloud/src/Wordcloud.tsx Outdated Show resolved Hide resolved
packages/visx-wordcloud/src/Wordcloud.tsx Outdated Show resolved Hide resolved
@williaster
Copy link
Collaborator

New happo visual example looks good 📈 ✨
image

Copy link
Collaborator

@williaster williaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for all the work here @craciuncezar 🙌

@williaster
Copy link
Collaborator

I don't think we've released new packages with CI before so it might fail but ... yolo

@williaster williaster merged commit efab522 into airbnb:master Aug 17, 2021
@craciuncezar
Copy link
Contributor Author

Thanks again for all the work here @craciuncezar 🙌

I'm glad I could contribute to this awesome lib, thanks for all the work 🚀

@github-actions
Copy link

🎉 This PR is included in version v2.1.0 of the packages modified 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal with code - Word Cloud
4 participants