ngx-graph: 8.0.3 breaks line rendering with d3-transition

Describe the bug When updating to 8.0.3, some edges do not render and the following error is produced.

ERROR TypeError: linkSelection.attr(...).transition is not a function
    at swimlane-ngx-graph.mjs:1785:22
    at Array.map (<anonymous>)
    at QueryList.map (core.mjs:22857:30)
    at GraphComponent.redrawLines (swimlane-ngx-graph.mjs:1779:27)
    at NodeComponent.updateGraph (node.component.ts:116:13)
    at node.component.ts:81:12
    at timer (zone.js:2405:41)
    at _ZoneDelegate.invokeTask (zone.js:406:31)
    at Object.onInvokeTask (core.mjs:26218:33)
    at _ZoneDelegate.invokeTask (zone.js:405:60)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 9
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

This happens if you have multiple versions of d3-selection installed. The d3-transition package is attaching itself to a different version than what ngx is using. In my opinion, ngx-graph should list the d3 dependencies as peer dependencies to avoid this issue. However, we were able to work around it by “pinning” a single version of d3-selection. This can be done with npm or yarn. Here’s what we did in package.json to get npm to pin a version:

"overrides": {
    "d3-selection": "3.0.0"
}

You can list the version that ngx-graph specifies, but 3.0.0 seems to work fine.

Here’s an issue filed for d3 that kind of talks about the problem:

https://github.com/d3/d3/issues/3262

Same error here (Angular 14). Had to rollback to ngx 8.0.2…

After a long night trying to get all the connections to draw correctly, I’ll share how I managed to do it. Basically, the issue occurs when creating the path, which should set the d attribute ([attr.d]=“link.line” ) like this:

<path class="edge" [attr.d]="link.line" marker-end="url(#arrow)"></path>

A short response on the topic, and here’s an example of how the #linkTemplate would look:

<ng-template #linkTemplate let-link>
  <svg:g class="edge">
  
    <path class="edge" [attr.d]="link.line" marker-end="url(#arrow)"></path>

    <svg:text class="edge-label" text-anchor="middle">
      <textPath
        class="text-path"
        [attr.href]="'#' + link.id"
        [style.dominant-baseline]="link.dominantBaseline"
        startOffset="50%"
      >
        {{ link.label }}
      </textPath>
    </svg:text>
  </svg:g>
</ng-template>

I use this version @swimlane/ngx-graph 8.4.0

me too

I have the same issue

I have the same issue

Same error here (Angular 14). Had to rollback to ngx 8.0.2…

this solved the issue… it works

This happens if you have multiple versions of d3-selection installed. The d3-transition package is attaching itself to a different version than what ngx is using. In my opinion, ngx-graph should list the d3 dependencies as peer dependencies to avoid this issue. However, we were able to work around it by “pinning” a single version of d3-selection. This can be done with npm or yarn. Here’s what we did in package.json to get npm to pin a version:

"overrides": {
    "d3-selection": "3.0.0"
}

You can list the version that ngx-graph specifies, but 3.0.0 seems to work fine.

Here’s an issue filed for d3 that kind of talks about the problem:

d3/d3#3262

@neodescis this solution works for me in Angular 16. Thank u.

We are also facing similar issue in using 8.0.3 with angular 15. Thanks @neodescis for suggesting a workaround, but unfortunately it did not resolved the issue for us. Greatly appreciate any additional recommendations.