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

Error: react-d3-graph :: Graph :: you have not provided enough data for react-d3-graph to render something. You need to provide at least one node #347

Closed
PraveenVutukuri opened this issue Jul 10, 2020 · 6 comments · Fixed by #381
Assignees
Labels
enhancement improving existent functionality or performance related Hacktoberfest Hacktoberfest label priority normal

Comments

@PraveenVutukuri
Copy link

I am fetching the data from backend, it is throwing error

@jadenmazzone
Copy link

Have you tried not rendering the component until the data is fetched? Ie have a "isLoading" (or something similar) state: if(!isLoading) -> render graph.

@danielcaldas
Copy link
Owner

danielcaldas commented Aug 7, 2020

@PraveenVutukuri please use the bug template when opening issues. Could you please add the version of react-d3-graph and other relevant details? Thanks!

Briefly looking into this, to avoid this kind of breaking behavior react-d3-graph could mute this in a production environment and simply console.error instead of actually throwing an error.

On the other hand, if you don't have data to render, then just don't mount the <Graph> component.

@danielcaldas danielcaldas added the enhancement improving existent functionality or performance related label Aug 7, 2020
@mailuesp
Copy link

I think it should just draw an empty canvas if you provide a data object like following:

{
nodes: [],
links: []
}

instead of throwing an error.

@gokul112
Copy link

gokul112 commented Oct 7, 2020

Hi,
Shall i work on this issue?

@danielcaldas
Copy link
Owner

Hey @gokul112 thanks for your interest. I think @LonelyPrincess might be looking into the same issue. Just to make sure we don't have two people working on this, I'll put this one on hold until we hear back from @LonelyPrincess. The solution we want to go with is to provide default data in case the client does not provide it. Just like pointed by @mailuesp above.

@danielcaldas danielcaldas added the Hacktoberfest Hacktoberfest label label Oct 7, 2020
@LonelyPrincess
Copy link
Collaborator

Yeah, I agree in that it's best that we default the node list to an empty array and show a warning instead of throwing an error in these cases. It's true that the scenario in which someone uses the library to display an empty canvas is rare, but this is not really an error per se. A warning to tell the user that they forgot to pass down some data is enough to make them aware in case they didn't intend to leave that to happen. I'll upload a PR for this in a few minutes. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improving existent functionality or performance related Hacktoberfest Hacktoberfest label priority normal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants