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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:28:12+00:00 2026-06-13T17:28:12+00:00

Hello im trying to implement this D3 project http://bl.ocks.org/929623 : with images like this

  • 0

Hello im trying to implement this D3 project http://bl.ocks.org/929623:

enter image description here

with images like this one http://bl.ocks.org/950642:

enter image description here

But I can’t make the source images to resize and move along with the nodes. Heres the code:

var nodesCreated = 1;
var newDistance = 100;
var width =  document.documentElement.clientWidth,
    height = document.documentElement.clientHeight,
    fill = d3.scale.category20(),
    nodes = [],
    links = [];

var vis = d3.select("#chart").append("svg")
    .attr("width", width)
    .attr("height", height);

vis.append("rect")
    .attr("width", width)
    .attr("height", height);

var force = d3.layout.force()
    .linkDistance(newDistance)
    .nodes(nodes)
    .links(links)
    .gravity(.01)
    .size([width, height]);

force.on("tick", function() {
vis.selectAll("line.link")
      .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; });

vis.selectAll(".node")
      .attr("cx", function(d) { return d.x; })
      .attr("cy", function(d) { return d.y; });


});


var tempX = window.innerWidth/2;
var tempY = window.innerHeight/2;
var point = tempX,tempY,
node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/48799_806120304_700633127_n.jpg"};
n = nodes.push(node);


vis.on("mousedown", function() {
      var point = d3.mouse(this),
      node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/211698_100002756979859_374256176_n.jpg"},
      n = nodes.push(node);
      nodesCreated++;
      console.log(nodesCreated);
      var tempCounter = 0;

      newDistance == 10;
      force.linkDistance(newDistance);
      nodes.forEach(function(target) {
          if (/*Math.sqrt(x * x + y * y) < 100 ||*/ tempCounter == 0) {
              links.push({source: node, target: target});
              tempCounter++;
          }
      });

  restart();
});


function restart() {
  force.start();

  vis.selectAll("line.link")
      .data(links)
    .enter().insert("line", ".node")
      .attr("class", "link");

var realNode = vis.selectAll(".node")
      .data(nodes)
      .enter().append("g")
      .attr("class", "node")
      .call(force.drag);

      realNode.append("image")
      .attr("xlink:href", function(d) { return d.imgsrc; })
      .attr("x", -8)
      .attr("y", -8)
      .attr("width", 160)
      .attr("height", 160);

}

I have been looking for some help at google but I found no solution.

  • 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-13T17:28:13+00:00Added an answer on June 13, 2026 at 5:28 pm

    You should add X and Y co-ordinates to your nodes:

    var tempX = window.innerWidth/2;
    var tempY = window.innerHeight/2;
    var point = [tempX,tempY],
        node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/48799_806120304_700633127_n.jpg", x: tempX, y: tempY};
    

    and

      var point = d3.mouse(this),
          node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/211698_100002756979859_374256176_n.jpg", x:point[0], y:point[1]},
          n = nodes.push(node);
    

    And then need to add a transform to the force.on("tick".... function:

     vis.selectAll(".node")
        .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ") scale(0.30)"; });
    

    This scales your images down to 30%, but you can configure this.

    For completeness, here is all of the code:

    var nodesCreated = 1;
    var newDistance = 100;
    var width =  document.documentElement.clientWidth,
        height = document.documentElement.clientHeight,
        fill = d3.scale.category20(),
        nodes = [],
        links = [];
    
    var vis = d3.select("#chart").append("svg")
        .attr("width", width)
        .attr("height", height);
    
    vis.append("rect")
        .attr("width", width)
        .attr("height", height);
    
    var force = d3.layout.force()
        .linkDistance(newDistance)
        .nodes(nodes)
        .links(links)
        .gravity(.01)
        .size([width, height]);
    
    force.on("tick", function() {
    vis.selectAll("line.link")
          .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; });
    
     vis.selectAll(".node")
          .attr("cx", function(d) { return d.x; })
          .attr("cy", function(d) { return d.y; });
    
     vis.selectAll(".node")
        .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ") scale(0.30)"; });
    
    });
    
    
        var tempX = window.innerWidth/2;
        var tempY = window.innerHeight/2;
        var point = [tempX,tempY],
            node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/48799_806120304_700633127_n.jpg", x: tempX, y:tempY};
        n = nodes.push(node);
    
    
    vis.on("mousedown", function() {
      var point = d3.mouse(this),
          node = {imgsrc: "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/211698_100002756979859_374256176_n.jpg", x:point[0], y:point[1]},
          n = nodes.push(node);
          nodesCreated++;
          console.log(nodesCreated);
          var tempCounter = 0;
    
      newDistance == 10;
      force.linkDistance(newDistance);
      nodes.forEach(function(target) {
        if (/*Math.sqrt(x * x + y * y) < 100 ||*/ tempCounter == 0) {
          links.push({source: node, target: target});
          tempCounter++;
        }
      });
    
      restart();
    });
    
    
    function restart() {
      force.start();
    
      vis.selectAll("line.link")
          .data(links)
        .enter().insert("line", ".node")
          .attr("class", "link");
    
    var realNode = vis.selectAll(".node")
          .data(nodes)
          .enter().append("g")
          .attr("class", "node")
          .call(force.drag);
    
          realNode.append("image")
          .attr("xlink:href", function(d) { return d.imgsrc; })
          .attr("x", -8)
          .attr("y", -8)
          .attr("width", 160)
          .attr("height", 160);
    
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys, I have been trying to implement the DSUM function but failed to
I'm trying to implement a basic qtimer in a qgraphicsview but can't seem to
I've been trying to implement the tab UI described in this tutorial: https://developer.android.com/resources/tutorials/views/hello-tabwidget.html I
This maybe a very noobish question but I am trying to implement a simple
Hello i'm trying to implement an AsynController, here is my code: [NoCache] public class
Hello everyone i am trying to implement push notifications with urbanairship i followed the
I am trying to implement a hello world application for the iPhone and i've
Hello I´m trying to automate AZURE VM management like Amazon EC2. Is there any
Hello im trying to echo only the 50 letters, but something in my code
hello i am trying a sqlite database tutorial to build, but its not working

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.