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

@zooniverse/react-components now requires d3 to be installed #5979

Closed
1 of 6 tasks
eatyourgreens opened this issue Mar 16, 2024 · 5 comments · Fixed by #5987
Closed
1 of 6 tasks

@zooniverse/react-components now requires d3 to be installed #5979

eatyourgreens opened this issue Mar 16, 2024 · 5 comments · Fixed by #5987
Labels
bug Something isn't working

Comments

@eatyourgreens
Copy link
Contributor

eatyourgreens commented Mar 16, 2024

Package

Choose from the list:

  • app-content-pages
  • app-project
  • lib-classifier
  • lib-panoptes-js
  • lib-react-components
  • unknown

Describe the bug

The AnimatedNumber component uses d3. @zooniverse/react-components doesn't include d3 as a dependency.

To Reproduce

npm install @zooniverse/react-components in a project that doesn't use d3.

Expected behavior

@zooniverse/react-components should install without errors, or warn that d3 is a prerequisite.

Additional context

Either yarn add d3 or add it as a peer dependency (yarn add d3 --peer.)

d3 is modular now, so I'd also recommend only adding the modules that are used by the AnimatedNumber component.

Importing directly from d3 may also cause version conflicts with @visx packages (see #5324.) Where possible, I recommend importing d3 modules from @visx/vendor eg.

@eatyourgreens eatyourgreens added the bug Something isn't working label Mar 16, 2024
@goplayoutside3
Copy link
Contributor

It looks like the following definitely works:

import { format } from '@visx/vendor/d3-format'
import { interpolate } from '@visx/vendor/d3-interpolate'

But I can't figure out how to get d3.select from VisX 🤔

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Mar 20, 2024

@visx/vendor doesn’t include d3-selection, unfortunately.

https://github.com/airbnb/visx/blob/86a851cb3bf622b013b186f02f955bcd6548a87f/packages/visx-vendor/package.json#L25-L33

So I think you’ll need to add d3-selection as a dependency, or peer dependency.

@goplayoutside3
Copy link
Contributor

I tried to import select from d3-selection, but kept running into an error where d3.select.transition is "not a function" caused by different versions of d3-selection in the yarn.lock 🤷‍♀️ I added d3 v6 as a peer dependency for lib-react-components for now.

@eatyourgreens
Copy link
Contributor Author

I think I ran into something similar with the data-plotting components. The older components in the monorepo were built before @visx existed, so there's a mixture of older stuff built with d3 v6, and newer stuff built with @visx, which uses d3 v7.

@eatyourgreens
Copy link
Contributor Author

The selection.transition API is added by d3-transition. This is where working with d3 can get complicated: module APIs that extend other modules.

https://github.com/d3/d3-transition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants