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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:03:23+00:00 2026-05-31T10:03:23+00:00

I am experimenting with force directed layout using D3.js. What I need is center

  • 0

I am experimenting with force directed layout using D3.js. What I need is center the layout by root (or other selected node) and return this node to the svg (e.g. canvas) center after the tick function is done (the graph alpha is low). Is it possible? I found an example at

http://bl.ocks.org/1080941

but I am unable to make the root (when using aplha or other custom tick function calculation) return back to the center (center the layout by this particular node).

Any help would be 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-05-31T10:03:24+00:00Added an answer on May 31, 2026 at 10:03 am

    Actually I solved this like this(similar to previous but more sophisticated):

    force.on("tick", function(e) {
    
         node.attr("transform", function(d) { 
             //TODO move these constants to the header section
            //center the center (root) node when graph is cooling down
            if(d.index==0){
                damper = 0.1;
                d.x = d.x + (w/2 - d.x) * (damper + 0.71) * e.alpha;
                d.y = d.y + (h/2 - d.y) * (damper + 0.71) * e.alpha;
            }
            //start is initiated when importing nodes from XML
            if(d.start === true){
                d.x = w/2;
                d.y = h/2;
                d.start = false;
            }
    
            r = d.name.length;
            //these setting are used for bounding box, see [http://blockses.appspot.com/1129492][1]
            d.x = Math.max(r, Math.min(w - r, d.x));
            d.y = Math.max(r, Math.min(h - r, d.y));
    
                return "translate("+d.x+","+d.y+")";            
    
         }
        );
    
         });   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Experimenting with android game development. I'm using PNG format for images, and was wondering
While experimenting with this question on collections in Spring.NET , I discovered that Spring
While experimenting a bit with C++ templates I managed to produce this simple code,
Experimenting with Cocos2D collection detection and have some questions. First, some background: This is
I'm experimenting with a custom LayoutManager and I don't understand the subtleties of using
been experimenting with unordered list UL and i have seem varios examples of using
Was experimenting with interface inheritance and found this: interface String{} interface Object{} interface Exception{}
Experimenting with a battery monitor icon at the moment in Python using pygtk and
In experimenting with this question I created an example that I utterly do not
Experimenting using different approaches and reducing code maintenance I have ended up using reflection

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.