Personalizing the Node Template and Edge Template with NGX-GRAPH is not functioning as expected

Welcome to the world of NGX-GRAPH! I am currently working on creating a directed graph using this library. Below is the code snippet that I have implemented:

ngx-graph.component.html:

<ngx-graph *ngIf="nodes?.length > 0 && links?.length > 0"
          [links]="links"
          [nodes]="nodes"></ngx-graph>

ngx-graph.component.ts:

import { Component, OnInit } from '@angular/core';
import { ServerService } from '../server.service';
import { ActivatedRoute, Router } from '@angular/router';
import { Edge, Node} from '@swimlane/ngx-graph';

@Component({
  selector: 'app-ngx-graph',
  templateUrl: './ngx-graph.component.html',
  styleUrls: ['./ngx-graph.component.scss']
})
export class NgxGraphComponent implements OnInit {
  id: number;
  constructor(private serverService: ServerService, private route: ActivatedRoute) { }
  nodes: Node[] = [];
  links: Edge[] = [];

  ngOnInit() {
    this.id = +this.route.snapshot.params.id;
    this.serverService.getGraphGivenEndpointId(this.id).subscribe(
      response => { this.nodes = response[0];
                    this.links = response[1];
                    console.log(this.nodes);

      }
    );
  }
}

The JSON data returned by my service looks like this:

(2) [{…}, {…}]
0: {id: "first", label: "A", meta: {…}, dimension: {…}, position: {…}, …}
1: {id: "second", label: "B", meta: {…}, dimension: {…}, position: {…}, …}
2: {id: "first", label: "A", meta: {…}, dimension: {…}, position: {…}, …}
length: 3
__proto__: Array(0)

ServerService.ts:

@Injectable()
export class ServerService {
    constructor(private http: HttpClient, private elencoEndpointService: ElencoEndpointService) {}

    getGraphGivenEndpointId(id: number) {
       return this.http.get('http://localhost:8080/app/endpoint?id=' + id);
    }
}


While initially the graph displays successfully similar to the one on the "quickstart" page here, adding customizations as shown below causes the nodes to disappear while the edges remain visible:

<ng-template #nodeTemplate let-node>
        <svg:g class="node">
            <svg:rect [attr.width]="node.dimension.width" [attr.height]="node.dimension.height"
                [attr.fill]="node.data.color" />
            <svg:text alignment-baseline="central" [attr.x]="10" [attr.y]="node.dimension.height / 2">{{node.label}}
            </svg:text>
        </svg:g>
    </ng-template>

This results in no error messages being displayed. Additionally, adding an update trigger in ngx-graph.component.ts did not resolve the issue:


this.nodes.forEach(element => {
                      this.nodes.push(element);
                      this.nodes = [...this.nodes];
                    });

My app.module.ts contains the necessary imports and configurations for NGX-GRAPH:


import { BrowserModule } from '@angular/platform-browser';
...
const appRoutes: Routes = [
  ...
];

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
  ],
  providers: [ElencoEndpointService, ServerService],
  bootstrap: [AppComponent]
})
export class AppModule { }

I followed the quick start guide provided on the official documentation but encountered this issue. Could there be additional steps or imports required?

Thank you for your assistance.

Answer №1

If you are using Angular 9, be aware that ngx-graph version 6.2.0 is not compatible with it.

When installing with NPM or Yarn, make sure to watch out for any missing peer dependency warnings.

To ensure compatibility with Angular 9, consider upgrading to the next version of ngx-graph (7.0.0-rc.1 instead of 6.2.0). It seems that Angular 9.0.3 works best with ngx-graph version 7.0.0-rc.1.

You can use one of the following commands to install the newer version:

yarn add @swimlane/ngx-graph@next

npm i @swimlane/ngx-graph@next

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Disabling the scrollbar within angular elements

Trying to remove the two scrollbars from this code, but so far unsuccessful. Attempted using overflow:hidden without success filet.component.html <mat-drawer-container class="example-container" autosize> <button type="button&qu ...

The issue of transforming a circular structure into JSON arises while using tRPC

While using the t3-stack (Next, tRPC, Prisma, Next-auth, Typescript) tRPC encountered an error on undefined: TRPCError: Converting circular structure to JSON --> starting at object with constructor 'RequestHandler' | property &apos ...

I'm experiencing an issue in Angular 2 where I am unable to call a function within another function

I am working with an Angular 2 client and have created an ngOnInit function in the component.ts file. ngOnInit(){ var grid = document.getElementById('devpro'); grid.addEventListener('selected-items-changed', function() ...

Angular 6: A class with no 'default' modifier must explicitly specify a name

I am encountering this error in my ts.file, as I delve into the world of Angular/Ionic. Can anyone help identify the possible reasons for this? I have attempted multiple solutions to address it, but unfortunately, none have proven successful. import { Co ...

What is the process for retrieving the API configuration for my admin website to incorporate into the Signin Page?

My admin website has a configuration set up that dynamically updates changes made, including the API. However, I want to avoid hardcoding the base URL for flexibility. How can I achieve this? Please see my admin page with the config settings: https://i.st ...

After adding the exclude property to angular-cli.json, the spec files are now being linted

I am working on an Angular 4 application and have manually created two .spec files for a specific class. When I use the nglint command, it successfully lints these two files. However, the spec files that were automatically generated when I created a compon ...

Using Typescript in the browser with Babel and Webpack: Step-by-Step Guide

I've been exploring the use of Typescript in my browser with a specific architecture: Typescript in browser architecture However, I'm facing an issue with the import/export functionality when running this command: tsc && babel build-ts -d lib && ...

Take out a specific element from an array consisting of multiple objects

I have a specific array structure and I need to remove elements that match a certain criteria. Here is the initial array: const updatedUsersInfo = [ { alias: 'ba', userId: '0058V00000DYOqsQAH', username: '<a href=" ...

Combining objects in JavaScript

I am currently working on converting the object received from the server into a format compatible with the backend system. I have a received object that looks like this { 'User.permissions.user.view.dashboard': true, 'Admin.permissio ...

Tips for dynamically accessing object properties in TypeScript

I've been going through the process of converting existing Node.js projects to TypeScript. As part of this, I am utilizing the http-status package (https://www.npmjs.com/package/http-status) for handling HTTP status codes. While trying to pass varia ...

Preventing Repeated Form Submissions in Angular: A Helpful Guide

`Hello, I am new to Angular and I am struggling with a specific part of the form. People have been clicking the submit button multiple times quickly, causing the same information to be added repeatedly before it can be sent to the API. I have searched onl ...

Tips on displaying hyperlinks within a text area in an Angular application

In my Angular application, I am facing an issue with displaying hyperlinks within a text area box for dynamic content. The hyperlinks are not recognized and therefore cannot be clicked. Can someone please advise on how to properly display hyperlinks with ...

Efficient loading of services in Angular for increased performance

I recently developed a module using Angular 4 and also created a service using @Injectable which I then added to the module. However, my current requirement is that the service should not load during the initial module loading process. Instead, I want the ...

Leveraging the @Input decorator to send external data into the Angular component

In my Ionic app, I am utilizing an Angular component. Within this component, there is a variable called headerText that is supposed to be initialized from the page where the component is being used. The issue arises when the headerText variable is always ...

What is the best way to organize imports in an individual Angular component?

Is there a way to order the imports in a standalone component according to the same rules as the file imports? Let me explain. In my *.ts files, I use eslint rules to sort and group the imports at the top of the file. import/order": [ " ...

Disabling Autocomplete on Angular Date Picker Directive

Recently, I inherited a JQuery Date picker directive that adds date pickers to input HTML controls. As a newcomer to Angular, I have been struggling with modifying this functionality created by a previous developer. I am specifically looking for a way to ...

No overload error encountered with TypeScript function call

I am working on an async function that communicates with the backend and I need it to handle axios error messages. My goal is to display these messages in a form. export async function register( prevState: string | undefined, formData: FormData ) { t ...

Having trouble with Angular router.navigate not functioning properly with route guard while already being on a component?

I am currently troubleshooting an issue with the router.navigate(['']) code that is not redirecting the user to the login component as expected. Instead of navigating to the login component, I find myself stuck on the home component. Upon adding ...

My Angular2 pipe is not working as expected

I have developed a custom pipe to search through a table based on ID. Below is the example JSON data that I am utilizing to populate the tables: [ { "id": "59247cd5a05cfa4966af706d", "lease": { "client": { "client_id": 1, ...

What is the correct way to effectively integrate react-hook-form with redux and typescript?

After tirelessly searching for a comprehensive guide that could demonstrate all these requirements in one example, I eventually resorted to brute force to make something functional. However, I am well aware that this approach is not the correct way to achi ...