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 8734467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:50:48+00:00 2026-06-13T09:50:48+00:00

I would like to highlight the edges of a graph when the connected nodes

  • 0

I would like to highlight the edges of a graph when the connected nodes are hovered.
I took inspiration from the Bundle example:

enter image description here

However the on() function is not giving the d object to the onmouse function:

d3.json("graph_file.json", function(json) {
      force
          .nodes(json.nodes)
          .links(json.links)
          .start();

      var link = svg.selectAll("line.link")
          .data(json.links)
        .enter().append("line")
          .attr("class", function(d) { return "link source-" + d.source.key + " target-" + d.target.key; })
          .style("stroke-width", function(d) { return Math.sqrt(d.value); });

      var node = svg.selectAll("circle.node")
          .data(json.nodes)
        .enter().append("circle")
          .attr("class", "node")
          .attr("r", function(d) { return d.connec; })
          .style("fill", function(d) { return color(d.group); })
          .on("mouseover", mouseover)
          .on("mouseout", mouseout)
          .call(force.drag);

…

        function mouseover(d) {
      svg.selectAll("line.link.target-" + d.key)
          .classed("target", true);


      svg.selectAll("line.link.source-" + d.key)
          .classed("source", true);
    }

any help appreciated.

  • 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-06-13T09:50:49+00:00Added an answer on June 13, 2026 at 9:50 am

    Ultimately I was not able to reproduce your problem! The only thing that caught me at first was when I defined my mouseover and mouseout functions after setting them in .on(…) In that case they were undefined for the call and no mouse handlers were set – so the functions were simply never called.

    Anyway, you can see what I tried here. The code:

    var w = 400,
        h = 400;
    var vis = d3.select("svg").attr("width", 800).attr("height", 800);
    
    var nodes = [];
    var links = [];
    
    for (var i = 0; i < 30; i++) {
        var node = {
            label: "node " + i,
            value: Math.random(),
            key: i
        };
        nodes.push(node);
    };
    
    for (var i = 0; i < nodes.length; i++) {
        for (var j = 0; j < i; j++) {
            if (Math.random() > .95) links.push({
                source: nodes[i],
                target: nodes[j],
                weight: Math.random()
            });
        }
    };
    
    var force = d3.layout.force().size([w, h]).nodes(nodes).links(links);
    
    force.start();
    
    var link = vis.selectAll("line.link").data(links).enter().append("line").style("stroke", "#CCC").attr("class", function(d) {
        return "link source-" + d.source.key + " target-" + d.target.key;
    });
    
    var mouseover = function(d) {
        txt.text(JSON.stringify(d));
        //txt.text("line.link.target-" + d.key);
        vis.selectAll("line.link.target-" + d.key).classed("target", true).style("stroke", '#F00');
    
        vis.selectAll("line.link.source-" + d.key).classed("source", true).style("stroke", '#F00');
    }
    
    
    var mouseout = function(d) {
        vis.selectAll("line.link.target-" + d.key).classed("target", false).style("stroke", "#CCC");
    
        vis.selectAll("line.link.source-" + d.key).classed("source", false).style("stroke", "#CCC");
    }
    
    
    var node = vis.selectAll("circle.node").data(force.nodes()).enter().append("circle").attr("class", "node").attr("r", 5).style("fill", function(d) {
        return d3.rgb(55 * d.value, 255 * d.value, 155 * d.value)
    }).style("stroke", "#FFF").style("stroke-width", 3).on("mouseover", mouseover).on("mouseout", mouseout).call(force.drag);
    
    var txt = vis.append('text').attr({
        transform: 'translate(5,400)'
    }).text("Node Info");
    
    
    var updateLink = function() {
        this.attr("x1", function(d) {
            return d.source.x;
        }).attr("y1", function(d) {
            return d.source.y;
        }).attr("x2", function(d) {
            return d.target.x;
        }).attr("y2", function(d) {
            return d.target.y;
        });
    }
    
    var updateNode = function() {
        this.attr("transform", function(d) {
            return "translate(" + d.x + "," + d.y + ")";
        });
    }
    
    force.on("tick", function() {
        node.call(updateNode);
        link.call(updateLink);
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to highlight some of the nodes in an Ext.tree.Panel. In Ext3
I would like to highlight(select) multiple occurrences of a string in JTextPane . I
i have tons of data that i would like to highlight only those cell
Before I begin, I would like to highlight the structure of what I am
I've got a RichTextBox, and would like to highlight a whole word, given just
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to highlight some text within the body of an e-mail and
I would like to highlight search terms on a page, but not mess with
I have a DataGrid in my Silverlight application, and would like to highlight an
I would like to highlight a word which in an UILabel which is placed

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.