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

  • SEARCH
  • Home
  • 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 7767111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:35:40+00:00 2026-06-01T15:35:40+00:00

I have a d3 force-directed graph that contains a group of nodes: var node

  • 0

I have a d3 force-directed graph that contains a group of nodes:

var node = vis.selectAll("g.node")
              .data(json.nodes)
              .enter().append("svg:g")
              .attr("class", "node")
              .attr("id", function(d) { return "node" + d.index; })
              .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
              .call(force.drag);

This renders fine.

I’d now like to translate (move) these nodes 200 pixels to the right when I show a detail div with the id detail_container.

I tried the following, but nothing happens to the nodes when I show detail_container (other than showing the detail div):

$('#detail_container').fadeIn('slow', function() {
    d3.selectAll("g.node").attr("transform", function(d) { return "translate(200, 0)"; });
});

The d3.selectAll("g.node") statement contains the node data, which I can confirm by looking at the data in the console:

console.log(d3.selectAll("g.node"));

As another approach, I attached the zoom/pan behavior to my graph:

var vis = d3.select("#position")
            .append("svg:svg")
            .attr("width", w)
            .attr("height", h)
            .attr("pointer-events", "all")
            .append("svg:g")
            .call(d3.behavior.zoom().on("zoom", redraw))
            .append("svg:g");

This works fine. However, this interacts with the mouse, not with events that occur in my program, so is there a programmatic way to call the zoom/pan behavior, so that I can accomplish the translation I want?

  • 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-01T15:35:42+00:00Added an answer on June 1, 2026 at 3:35 pm

    If you just want to move the nodes to the right, then you can accomplish that by setting a transform; only use the zoom behavior if you want interactive panning and zooming.

    It’s not clear to me why nothing is happening when you select the nodes and set a transform, but one problem I see is that by setting the transform attribute on the nodes directly, you’re overwriting the x & y position set by the force layout. So, you probably want to put all of the nodes inside another G element, so that you can offset all of them by changing the transform on the container rather than the individual nodes. The DOM would look like this:

    <g class="nodes">
      <g class="node" transform="translate(42,128)">
        <circle r="2.5">
        <text>First Node</text>
      </g>
      <g class="node" transform="translate(64,501)">
        <circle r="2.5">
        <text>Second Node</text>
      </g>
      …
    </g>
    

    So then, if you want to shift all the nodes to the right by 200px, it’s just:

    d3.select(".nodes").attr("transform", "translate(200,0)");
    

    And to revert the shift, remove the container’s transform:

    d3.select(".nodes").attr("transform", null);
    

    If you wanted to be really fancy, another way of achieving this effect would be to change the center of gravity of the force layout, and then reheat the graph when you show or hide the details DIV. This will cause the nodes to smoothly shift into a new position to make way for the details container. You can see an example of this in Shan Carter’s visualization, Four Ways to Slice Obama’s 2013 Budget Proposal: click the “Types of Spending” button and watch the circles recenter. Or, see this example on custom gravity.

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

Sidebar

Related Questions

I have a test site where I am building a d3-based force-directed network graph
I have a login screen that I force to be ssl, so like this:
I have just come across a Visual C++ option that allows you to force
I have a force-download script that produces good results with PDF and plain text,
We currently have a dynamically updated network graph with around 1,500 nodes and 2,000
I can't find any way to draw a force directed graph where the weighting
Scenario I have a Node.JS service (written using ExpressJS ) that accepts image uploads
I am trying to create a d3 force-directed graph ( http://mbostock.github.com/d3/ex/force.html ). Here is
I am trying to add Tipsy hover-over popups to my simple force-directed graph of
I'm drawing graphs with force-directed layout, and the problem is that the created graphs

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.