Upon the initial loading of GoJS and Angular Links, nodes are not bypassed

Hey there, I'm currently working on a workflow editor and renderer using Angular and GoJS. Everything seems to be in order, except for this one pesky bug that's bothering me. When the page first loads, the links don't avoid nodes properly. However, as soon as you interact with the diagram or navigate back and forth between pages, the links start behaving as expected. Any ideas why this is happening?

Check out the issue with links not avoiding nodes correctly here

Below is the portion of the code that I think might be causing this problem. If anyone has any insights or solutions, I would really appreciate the help.

constructor(private templatesService: TemplatesService,
   private router: Router,
   private route: ActivatedRoute,
   private projectsService: ProjectsService) { this.initDiagram(); }

...

ngOnInit() {
   // Fetch data
   this.load();
   setTimeout(() => { this.load(); });

 }

 ngAfterViewInit() {
   // Data loaded, show graph on page
   this._diagram.div = this._diagramRef.nativeElement;

   this.scaleDiagramDivToHeightOf(window, -50);
   if (this.route.data['value']['label'] === 'design' ||
       this.route.data['value']['label'] === 'design-proto') {
     this.initDiagramDesign();
     this.initPalette();
   }


   this._diagram.requestUpdate();


 }

 initDiagram() {
   this._diagram.commandHandler.defaultScale = 1.0;
   const that = this;
   this._diagram = new go.Diagram();
   this._diagram.initialContentAlignment = go.Spot.TopCenter;
   this._diagram.allowDrop = this.editMode;
   this._diagram.isReadOnly = !this.editMode;
   this._diagram.toolManager.draggingTool = new GuidedDraggingTool();
   this._diagram.undoManager.isEnabled = true;
   this._diagram.layout = $(go.TreeLayout, {
     angle: 90,
     nodeSpacing: 10,
     layerSpacing: 25,
     layerStyle: go.TreeLayout.LayerUniform, 
     arrangement: go.TreeLayout.ArrangementHorizontal
   });

   this._diagram.nodeTemplateMap.add(""...
   this._diagram.linkTemplate =
     $(go.Link,  
       {
         routing: go.Link.AvoidsNodes,
         curve: go.Link.JumpOver,
         corner: 10, toShortLength: 4,
         relinkableFrom: true,
         relinkableTo: true,
         reshapable: true,
         resegmentable: true,
         selectionAdorned: false,
       },
       
       $(go.Shape,  
         { isPanelMain: true, strokeWidth: 8, stroke: "transparent", name: "HIGHLIGHT" }),
       $(go.Shape,  
         { isPanelMain: true, stroke: "gray", strokeWidth: 2 },
         new go.Binding("stroke", "isSelected", function (sel) { return sel ? "dodgerblue" : "gray"; }).ofObject()),
       $(go.Shape,  
         { toArrow: "standard", strokeWidth: 0, fill: "gray" }),
       $(go.Panel, "Auto",  
         { visible: false, name: "LABEL", segmentIndex: 2, segmentFraction: 0.5 },
         new go.Binding("visible", "visible").makeTwoWay(),
         $(go.Shape, "RoundedRectangle",  
           { fill: "#F8F8F8", strokeWidth: 0 }),
         $(go.TextBlock, "Yes",  
           {
             textAlign: "center",
             font: "10pt helvetica, arial, sans-serif",
             stroke: "#333333",
             editable: true
           },
           new go.Binding("text").makeTwoWay())
       )
     );   
   this._diagram.layout.invalidateLayout();
 }


 load() {
    ...fetch data from backend...
 }

Answer №1

I finally cracked the code, it just needed a small tweak in

constructor(private templatesService: TemplatesService,
   private router: Router,
   private route: ActivatedRoute,
   private projectsService: ProjectsService) { this.initDiagram(); }

ngOnInit() {

 }

 ngAfterViewInit() {
   // Once the page is loaded with data, display the graph
   this._diagram.div = this._diagramRef.nativeElement;

   this.scaleDiagramDivToHeightOf(window, -50);
   if (this.route.data['value']['label'] === 'design' ||
       this.route.data['value']['label'] === 'design-proto') {
     this.initDiagramDesign();
     this.initPalette();
   }


   this.load();
 }

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

Unable to determine model dependency in Nest

I encountered an issue where Nest is unable to resolve dependencies. The error message from the logger reads as follows: [Nest] 39472 - 17.08.2023, 05:45:34 ERROR [ExceptionHandler] Nest can't resolve dependencies of the UserTransactionRepository ( ...

A method for performing precise division on numbers in JavaScript, allowing for a specific precision level (such as 28 decimal places)

I've searched extensively for a library that can handle division operations with more than 19 decimal places, but to no avail. Despite trying popular libraries like exact-math, decimal.js, and bignumber.js, I have not found a solution. How would you ...

Discover the best way to showcase items within an arrayList using dual CSS styles!

I'm currently working on a project that involves an arrayList with two names: Bob and Steve. I have the requirement to display them in different colors, where Bob should be displayed in green and Steve in red. Component.CSS .Bob{ font-weight:bold; ...

sending arguments to angular directive

It was causing me some concern to see the number of global Angular change detections triggered every time an event occurs. That's why I stumbled upon Angular 2 runOutsideAngular still change the UI and decided to implement the 'OutSideEventHandle ...

How can we transform the `toUSD(amount)` function into a prototype function?

This function is functioning perfectly as intended. function toUSD(amount): string { // CONVERT number to $0.00 format return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(amount); }; Here is how I currently i ...

Collaborative spreadsheet feature within a browser-based software platform

I am using an Angular-based SPA for my web application. My goal is to be able to open an Excel file within the application itself. Currently, I have a menu button or link that is linked to a specific path, for example //192.168.10.10/sharedExcels/myExcel. ...

Adding a blank line in an Angular table using primeNG to display database information requires a specific method

In my Angular application, I am utilizing primeNG table to display data fetched from a database. The table comes with 'add' and 'delete' buttons for user interaction. To view the interface, click on this link: https://i.stack.imgur.com/ ...

parsing a TypeScript query

Is there a simpler way to convert a query string into an object while preserving the respective data types? Let me provide some context: I utilize a table from an external service that generates filters as I add them. The challenge arises when I need to en ...

implement a solution in Ionic 4 Angular 6 that triggers a function only when all the observables in a loop have

In my code, I have a function named getDevices(). This function is responsible for fetching an array of devices. After getting this array, the code iterates through each device and calls another function called updateToServer(). The purpose of updateToServ ...

Issue with loading the schema in the angular.json configuration file

Encountering an issue within the angular.json file that needs attention. { "resource": "/e:/P dev/project/Resume_generator/front/angular.json", "owner": "_generated_diagnostic_collection_name_#1", "c ...

Is it Mission Impossible to Combine NodeJs, Restify, SQL Server, TypeScript, and IIS?

Starting a Rest API project using NodeJS with Restify on a Windows environment (local server with IIS and SQLServer) while also using Typescript may seem like a difficult task. Is it an impossible mission? Does anyone have any helpful guides, documentatio ...

An analysis of Universal Angular.io and Prerender.io from the viewpoint of Googlebot

Currently, my website is set up with Angular 1.4.x and prerender.io, which delivers static cached pages to Googlebot. Googlebot visits each page twice - once by hitting the URL directly, and then again by appending ?_escaped_fragment_ to the URL to access ...

"Organizing Data with Angular 2's Sorting Pipe for Arrays of

Guide to Creating a Sorting Pipe in Angular 2 Using an Array of Objects Initial Challenge: I am working with a TODOs list (Todo[ ]), and I need to sort it every time modifications are made. The desired outcome is to have completed todos appear at the bot ...

Utilizing an AwsCustomResource in AWS CDK to access JSON values from a parameter store

I found a solution on Stack Overflow to access configurations stored in an AWS parameter. The implementation involves using the code snippet below: export class SSMParameterReader extends AwsCustomResource { constructor(scope: Construct, name: string, pr ...

Angular Binding issue - Unable to bind to 'ngModel' as it is not recognized as a valid property of 'input' element, despite the property being present

I have developed a component class like the one below and I am attempting to link the class fields to the template, but encountered the following error: ERROR in src/app/admin/projects/projects.component.html: 41:34 - error NG8002: Can't bind to &ap ...

Guide to implementing ES2022 modules within an extension

After making changes in my extension code to test various module types, I decided to modify my tsconfig.json file as follows: { "compilerOptions": { "declaration": true, "module": "ES2022", ...

What is the best way to initialize elements once the data has finished loading?

I am currently working with a service class that retrieves data through HTTP in several methods. For example: filesPerWeek(login: string): Observable<FilesLastActivity[]> { return this.http.get('api/report/user_files_by_week?userId=' + ...

How come the variable `T` has been assigned two distinct types?

Consider the following code snippet: function test<T extends unknown[]>(source: [...T], b: T) { return b; } const arg = [1, 'hello', { a: 1 }] const res = test(arg, []) const res1 = test([1, 'hello', { a: 1 }], []) The variabl ...

Encountering a Typescript issue when trying to access props.classes in conjunction with material-ui, react-router-dom

I could really use some help with integrating material-ui's theming with react-router-dom in a Typescript environment. I'm running into an issue where when trying to access classes.root in the render() method, I keep getting a TypeError saying &a ...

The information retrieved from the API is not appearing as expected within the Angular 9 ABP framework

I am facing an issue with populating data in my select control, which is located in the header child component. The data comes from an API, but for some reason, it is not displaying correctly. https://i.stack.imgur.com/6JMzn.png. ngOnInit() { thi ...