Skip to content

‼️ Hotfix: Allow graph creation with empty nodes and links ‼️ #560

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

krusche
Copy link

@krusche krusche commented Nov 9, 2024

What kind of change does this PR introduce? (check one with "x")

  • Bugfix

What is the current behavior? (You can also link to an open issue here)
At the moment, graphs with 0 nodes or 0 links crash the component with undefined errors, because the graph is not created and this.graph.nodes is still invoked

What is the new behavior?
Graphs with 0 nodes or 0 links can be used without undefined errors. Closes #559

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

Other information:
Please merge this PR asap and create a bugfix release 9.0.2 as we currently cannot upgrade to 9.x

@krusche krusche changed the title Allow graph creation with empty nodes and links ‼️ Hotfix: Allow graph creation with empty nodes and links ‼️ Nov 9, 2024
@krusche
Copy link
Author

krusche commented Nov 15, 2024

@steveblue any chance you merge this quickly and create a 9.0.2 release?

1 similar comment
@krusche
Copy link
Author

krusche commented Dec 7, 2024

@steveblue any chance you merge this quickly and create a 9.0.2 release?

@holomekc
Copy link

Hi @steveblue @fhayd
any updates on this?

@ktaganova
Copy link

Hi @steveblue @fhayd we would like to update to 9.x, any updates for this issue?

@Hazemmmm
Copy link

I quickly solved the issue by adding these:
in the HTML:

 <ngx-graph
        *ngIf="treeNodes?.length >= 0 && treeLinks?.length >= 0"

and in typescript file

  treeNodes: Array<RecipeStepNode> = [];
  treeLinks: Array<Edge> = [];

and make sure to initialize them as well in the onInit with empty values before add the actual data.

  this.treeNodes = [];
  this.treeLinks = [];

@bsarkadi
Copy link

I quickly solved the issue by adding these: in the HTML:

 <ngx-graph
        *ngIf="treeNodes?.length >= 0 && treeLinks?.length >= 0"

and in typescript file

  treeNodes: Array<RecipeStepNode> = [];
  treeLinks: Array<Edge> = [];

and make sure to initialize them as well in the onInit with empty values before add the actual data.

  this.treeNodes = [];
  this.treeLinks = [];

This doesn't solve our problem, as we want to display single nodes without any links :(
We'd need the official fix released asap, it is a showstopper for us.

@Hazemmmm
Copy link

I quickly solved the issue by adding these: in the HTML:

 <ngx-graph
        *ngIf="treeNodes?.length >= 0 && treeLinks?.length >= 0"

and in typescript file

  treeNodes: Array<RecipeStepNode> = [];
  treeLinks: Array<Edge> = [];

and make sure to initialize them as well in the onInit with empty values before add the actual data.

  this.treeNodes = [];
  this.treeLinks = [];

This doesn't solve our problem, as we want to display single nodes without any links :( We'd need the official fix released asap, it is a showstopper for us.

It shows the node without links, but the error will still appear in the browser console. But this is jus a workaround to make it work smoothly.

@bsarkadi
Copy link

I quickly solved the issue by adding these: in the HTML:

 <ngx-graph
        *ngIf="treeNodes?.length >= 0 && treeLinks?.length >= 0"

and in typescript file

  treeNodes: Array<RecipeStepNode> = [];
  treeLinks: Array<Edge> = [];

and make sure to initialize them as well in the onInit with empty values before add the actual data.

  this.treeNodes = [];
  this.treeLinks = [];

This doesn't solve our problem, as we want to display single nodes without any links :( We'd need the official fix released asap, it is a showstopper for us.

It shows the node without links, but the error will still appear in the browser console. But this is jus a workaround to make it work smoothly.

I ended up with this solution: if links array is empty then I push a link pointing to the single node itself, and setting the width to zero.

@Hazemmmm
Copy link

I quickly solved the issue by adding these: in the HTML:

 <ngx-graph
        *ngIf="treeNodes?.length >= 0 && treeLinks?.length >= 0"

and in typescript file

  treeNodes: Array<RecipeStepNode> = [];
  treeLinks: Array<Edge> = [];

and make sure to initialize them as well in the onInit with empty values before add the actual data.

  this.treeNodes = [];
  this.treeLinks = [];

This doesn't solve our problem, as we want to display single nodes without any links :( We'd need the official fix released asap, it is a showstopper for us.

It shows the node without links, but the error will still appear in the browser console. But this is jus a workaround to make it work smoothly.

I ended up with this solution: if links array is empty then I push a link pointing to the single node itself, and setting the width to zero.

Can u share the code itself?

@krusche
Copy link
Author

krusche commented May 23, 2025

you could also simply add a patch:

@swimlane+ngx-graph+10.0.0.patch

add patch-package to package.json and add patch-package to postinstall

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

Successfully merging this pull request may close these issues.

Graph crashes when no links or nodes are provided
6 participants