Skip to content

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

Open
krusche wants to merge 1 commit intoswimlane:masterfrom
krusche:patch-1
Open

‼️ Hotfix: Allow graph creation with empty nodes and links ‼️#560
krusche wants to merge 1 commit intoswimlane:masterfrom
krusche:patch-1

Conversation

@krusche
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
Author

krusche commented Dec 7, 2024

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

@holomekc
Copy link
Copy Markdown

Hi @steveblue @fhayd
any updates on this?

@ktaganova
Copy link
Copy Markdown

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

@Hazemmmm
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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

@krusche
Copy link
Copy Markdown
Author

krusche commented Sep 10, 2025

@MarkColeman1 can you please merge this PR?

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