Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:53:25+00:00 2026-05-27T23:53:25+00:00

I am working on a force directed graph in D3. I want to highlight

  • 0

I am working on a force directed graph in D3. I want to highlight the mouseover’d node, its links, and its child nodes by setting all of the other nodes and links to a lower opacity.

In this example, http://jsfiddle.net/xReHA/, I am able to fade out all of the links and nodes then fade in the connected links, but, so far, I haven’t been able to elegantly fade in the connected nodes that are children of the currently mouseover’d node.

This is the key function from the code:

function fade(opacity) {
    return function(d, i) {
        //fade all elements
        svg.selectAll("circle, line").style("opacity", opacity);

        var associated_links = svg.selectAll("line").filter(function(d) {
            return d.source.index == i || d.target.index == i;
        }).each(function(dLink, iLink) {
            //unfade links and nodes connected to the current node
            d3.select(this).style("opacity", 1);
            //THE FOLLOWING CAUSES: Uncaught TypeError: Cannot call method 'setProperty' of undefined
            d3.select(dLink.source).style("opacity", 1);
            d3.select(dLink.target).style("opacity", 1);
        });
    };
}

I am getting a Uncaught TypeError: Cannot call method 'setProperty' of undefined error when I try to set the opacity on an element I loaded from the source.target. I suspect this is not the right way to load that node as a d3 object, but I can’t find another way to load it without iterating over all of the nodes again to find the ones that match the link’s target or source. To keep the performance reasonable, I don’t want to iterate over all the nodes more than necessary.

I took the example of fading the links from https://bl.ocks.org/mbostock/4062006:

enter image description here

However, that doesn’t show how to alter the connected child nodes.

Any good suggestions on how to solve or improve this will be furiously upvoted 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:53:26+00:00Added an answer on May 27, 2026 at 11:53 pm

    The error is because you are selecting the data objects (d.source and d.target) rather than the DOM elements associated with those data objects.

    You’ve got the line highlighting working, but I would probably combine your code into a single iteration, like this:

     link.style("opacity", function(o) {
       return o.source === d || o.target === d ? 1 : opacity;
     });
    

    Highlighting the neighboring nodes is harder because what you need to know the neighbors for each node. This information isn’t that easy to determine with your current data structures, since all you have as an array of nodes and an array of links. Forget the DOM for a second, and ask yourself how you would determine whether two nodes a and b are neighbors?

    function neighboring(a, b) {
      // ???
    }
    

    An expensive way to do that is to iterate over all of the links and see if there is a link that connects a and b:

    function neighboring(a, b) {
      return links.some(function(d) {
        return (d.source === a && d.target === b)
            || (d.source === b && d.target === a);
      });
    }
    

    (This assumes that links are undirected. If you only want to highlight forward-connected neighbors, then eliminate the second half of the OR.)

    A more efficient way of computing this, if you have to do it frequently, is to have a map or a matrix which allows constant-time lookup to test whether a and b are neighbors. For example:

    var linkedByIndex = {};
    links.forEach(function(d) {
      linkedByIndex[d.source.index + "," + d.target.index] = 1;
    });
    

    Now you can say:

    function neighboring(a, b) {
      return linkedByIndex[a.index + "," + b.index];
    }
    

    And thus, you can now iterate over the nodes and update their opacity correctly:

    node.style("opacity", function(o) {
      return neighboring(d, o) ? 1 : opacity;
    });
    

    (You may also want to special-case the mouseovered link itself, either by setting a self-link for every node in linkedByIndex, or by testing for d directly when computing the style, or by using a !important css :hover style.)

    The last thing I would change in your code is to use fill-opacity and stroke-opacity rather than opacity, because these offer much better performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on to create a undirected graph with force layout. In addition,
I'm working on a small app ... and I want to force pushviewcontroller. What
I'm working on a Flash project right now and I am having to force
I'm working with wxpython (2.8) with python 2.5. is it possible to force a
I'm now working on a challenge from website http://www.net-force.nl/challenges/ and I stand before an
I'm working on a PHP project where all files are given the extension '.shtml'.
is it possible to get this stuff working(some way to force Objectfactory create instances
When I add the ViewPagerIndicator library to a working android project, the project force
I'm currently working on a SalesForce.com tutorial entitled Force.com for Google App Engine for
how can I force a download to start using curl? I want it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.