programmatically convert a solid link to a specific node into a dashed one using d3

Graph Type

Radial Tidy Tree

Current Output

Initially, I receive a JSON response from the server and use recursion to flatten the JSON. I then utilize d3.tree to visualize the graph displayed below.

The Legislation node is designed so that upon double-clicking, it communicates with the backend to fetch a new JSON, triggering a re-render of the graph. https://i.sstatic.net/HxWlF.png

After rerendering, the node transforms into Manufacturer/Legislation as illustrated here: https://i.sstatic.net/8qLIY.png

In the illustration, I aim to distinguish the link by making it strokedashed, indicating that the particular node has been altered.

code

To keep this concise, I am excluding the code snippet:

ngAfterViewInit(): void {
        const self = this;
        const svg = d3.select('svg'),
            width = +svg.attr('width'),
            height = +svg.attr('height'),
            g = svg.append('g').attr('transform', 'translate(' + (width / 3 + 240) + ',' + (height / 3 + 140) + ')');

        const tree = d3.tree()
            .size([2 * Math.PI, 375])
            .separation(function(a, b) { return (a.parent === b.parent ? 1 : 2) / a.depth; });
        const root = tree(d3.hierarchy(this.parse_node(this.config['viewStructure'])));
        this.root = root; // store this is private variable
        // Code for links and nodes...
    }

Rerendering function

getProperties() {
  // .... Some logic
  const self = this;
  function askExtension() {
            // call the backend, get the json response
            // rerender with some latency here..
            setTimeout(() => {
                d3.selectAll('svg > *').remove();
                self.ngAfterViewInit();
                console.log(nodeInfo.parent.data.name + '/' + nodeInfo.data.name); // `Manufacturer/Legislation`

               // Logic for changing the link goes here
              
            }, 1000);
        }
}

I attempted using .forEach() on self.root.descendants() to locate Manufacturer/Legislation and modify the link using .links(), but it did not meet my requirements.

How can I dynamically alter a specific link to be dashed after rendering?

Answer №1

It seems that your issue can be solved by implementing a style function similar to the one you are currently using for node color.

Basically, when merging nodes, assign a class or attribute that distinguishes them. Then apply the style conditionally based on this classification.

link.style('stroke-dasharray', function(d){ if(d.data['someprop'] === 'valueForMerged'){
  return ("10,3");
}
else{
  return undefined;
}

Read more about this concept in this article.

You can also explore stroke-dasharray further in this resource. In essence, dasharray format is "# pixels on, # pixels off".

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

The Angular @Input directive may be prone to receiving inaccurate model data

I am currently working on setting up @Input for my component using a model that resembles the following: interface Car { sail?: never tires: number weight: number } interface Boat { tires?: never sail: boolean weight: number } exp ...

How to locate the position of an element within a multi-dimensional array using TypeScript

My data structure is an array that looks like this: const myArray: number[][] = [[1,2,3],[4,5,6]] I am trying to find the index of a specific element within this multidimensional array. Typically with a 1D array, I would use [1,2,3].indexOf(1) which would ...

react-query: QueryOptions not functioning as expected when utilizing userQueries()

When passing certain "query options" while using useQueries() to fetch multiple queries simultaneously, these specified "query options" do not get applied during query executions (e.g. refetchOnWindowFocus has a value of true but I want it to be false). F ...

The Angular 2 view will remain unchanged until the user interacts with a different input box

I am currently working on implementing form validation using Reactive Forms in Angular 2. Here is the scenario: There are two input fields Here are image examples for step 1 and step 2: https://i.stack.imgur.com/nZlkk.png https://i.stack.imgur.com/jNIFj ...

``There is an issue with Cross-Origin Resource Sharing (CORS) in a Node.js application utilizing TypeScript

I've encountered some issues with my application, specifically regarding CORS. I suspect it may be due to a misconfiguration on my server. The problem arises when I attempt to create a user in my PostgreeSQL database via the frontend. I have a tsx com ...

The validation of pre-filled input fields in Angular Material dialogs is not working as expected

I am encountering an issue with a mat-dialog that opens through an edit button within a (mat-)table. Upon opening the dialog, data is passed to populate certain input fields. One of these inputs has validation requiring that it cannot be left empty. The ...

What is the best way to toggle a d3 svg overlay using a leaflet layer control?

I am looking for a solution to place 3 d3 svgs on a leaflet map and control them as easily as leaflet layers. Check out this code example, which works but is not ideal. The key part is from line 75 onwards, where I create a custom layer control linked to ...

Is it possible to load components lazily without lazy loading modules in Angular?

Lazy loading is a widely used strategy, especially in Angular where it typically applies at the module level. However, can components be lazily loaded as well? Most web tutorials explain how lazy loading works with modules, such as having a main module in ...

Unable to upload file in angular2 due to empty Body (FormData)

Attempting to upload a photo with Angular2 to my REST Service (Loopback). The Loopback service has been successfully tested using Postman and is able to accept files with the x-www-form-urlencoded header. Below is a simplified version of the service metho ...

Solidjs: Implementing a Map in createStore does not trigger updates upon changes

As a beginner in solidjs, I might have missed something important. In the code snippet below, I am trying to understand an issue: const [state, setState] = createStore({ items: new Map() }); // e.g. Map<number, string> In a component, suppose I want ...

Using regular expressions in TypeScript to declare modules

Is there a more efficient method to declare multiple modules in TypeScript? An example of the code I am trying to simplify is: declare module '*.png'; declare module '*.jpg'; declare module '*.gif'; declare module '*.svg ...

Angular does not display HTML content until the requested http data has been fully loaded

I am experiencing an issue where certain HTML content does not load until the component has received data from an API call through a service. Below is the relevant code snippet: import { ApiService } from './services/api.service'; @Component({ ...

routerLinkActive maintains its active state even after another link has been clicked

<ul> <li routerLinkActive="active"><a routerLink="/">One</a></li> <li routerLinkActive="active"><a routerLink="/somewhere">Two</a></li> </ul> Upon clicking the link Two, both links are being hi ...

Spring Boot - The Cross-Origin Resource Sharing filter is effective for handling GET requests, however it does not properly handle other

In my current project, I am working on a Spring Boot 2.2.5 application paired with an Angular 9 frontend. One of the challenges I have faced is configuring a CORS filter in the Spring Boot backend to allow any origin, headers, and requests. After thoroug ...

Angular9 integrated with Firebase to enhance the capabilities of

I am facing an issue with displaying a specific element from the database. //component.html <section class="firee"> <figure class="snip1208"> <div *ngFor="let scholarship of scholarships" > <h3>{{scholarshi ...

How to access the Parent ViewContainerRef within a projected child component in Angular 5

I have a unique application structure where the App component contains dynamically created components. The Parent component utilizes an <ng-content> element for projecting child components inside itself. App Component: @Component({ selector: &apo ...

Error message appears when trying to render a shallow mock of a React.Component that extends MyInterface with any type

Encountering an Issue with Component Mocking When attempting to mock a component, I am receiving the following error message: "Conversion of type '{ props: { index: number; AssignmentTitle: string; AssignmentDescription: string; AssignmentUtilizedHou ...

Upgrading host and ComponentResolver from AngularDart version 4 to version 5

I'm currently in the process of transitioning a large Angular4 application (recently upgraded from Angular2) to Angular5. Within various sections of the application, we employ a directive to mark a div or other html element for generation inside that ...

Employing a boolean constant to verify if a parameter has been specified

Struggling with TypeScript version 2.8.3, I'm confused as to why the code below is failing to recognize that params is defined inside the if block. const testFunction = (params?: string) => { const paramIsDefined = typeof params !== 'undefi ...

Modify the color of the designated Tab in the PRIMENG TabMenu - customize the style

Currently, I am utilizing the Primeng tab menu component and facing an issue. Unfortunately, I seem to be unable to identify a method to alter the color of the selected tab to a different shade. If anyone has any insights or suggestions on how to achieve ...