force-layout

Collapse/expand child nodes of tree in d3.js?

*爱你&永不变心* 提交于 2019-12-01 02:32:18
问题 I'm building a tree structure (or rather modifying one of the examples with a set of my own data in my own json) and I'm trying to create some functionality: My tree's layout is that from the tree example: http://mbostock.github.com/d3/ex/cluster.html I am adding (to the circles) an onclick event which I would like to collapse the children of the clicked node. That is to say, when a user clicks the steelblue circle associated with a node, I want that nodes children to disappear. I've scoured

D3.js force directed graph, each group different color?

时光怂恿深爱的人放手 提交于 2019-12-01 02:13:34
问题 I've made a force directed graph with d3.js plugin, and I wanna color the nodes and the labels with the different color according to group which they belong. I've added scale for color: var color = d3.scale.category20(); and to node variable I've added: .style("fill", function(d) { return color(d.group); }) but all nodes are in the same color.. Here is my current situation: http://jsfiddle.net/WBkw9/ full script: var links = [ {source: "John", target: "Mike", group: "5"}, {source: "John",

Conflict between d3.forceCollide() and d3.forceX/Y() with high strength() value

怎甘沉沦 提交于 2019-12-01 00:28:29
I believe I found a bug in D3 v4.x (v4.5.0), when in a force-directed chart one combines d3.forceCollide to prevent nodes from overlapping and d3.forceX/Y to set the position of the nodes with a high strength value, and I’m about to create an issue in D3 GitHub repository. However, before creating the issue, I’d like to check it with the D3 users here on StackOverflow: it may not be a bug , it may be the very expected behaviour of using such combination. The code In the S.O. snippet below, I’m plotting 900 (30 x 30) circles. They are positioned using d3.forceX and d3.forceY , with a high

D3.js how do I arrange nodes of a force layout to be on a circle

三世轮回 提交于 2019-11-30 22:50:12
I have developed a force layout to represent relationships between social groups. Now I would like to get the nodes to be distributed in a circle with links joining them. What is the best way to do this? The complete version of the code (without data) is here http://jsfiddle.net/PatriciaW/zZSJT/ (Why do I have to include code here too? Here is the main portion) d3.json("/relationships?nocache=" + (new Date()).getTime(),function(error,members){ var links=members.organizations.map(function(members) { return members.member; }); var nodes = {}; links.forEach(function(link) { link.source = nodes

Center force directed layout after tick using root node (return to center)

Deadly 提交于 2019-11-30 21:24:35
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. Actually I solved this like this(similar to previous but more sophisticated): force.on("tick", function

Moving fixed nodes in D3

删除回忆录丶 提交于 2019-11-30 20:34:51
I have nodes in a D3 force-directed layout that are set to . fixed = true. If I set the .x or .y values, the nodes themselves don't move to their new position. Here's my function: function fixNode(idArray, locationX, locationY) { for ( x = 0; x < idArray.length; x++ ) { for ( y = 0; y < nodes.length; y++ ) { if (nodes[y].id == idArray[x]) { nodes[y].fixed = true; nodes[y].x = 50; nodes[y].y = 50; break; } } } } UPDATE 1: Here is the working function based on Jason's advice: function fixNode(idArray, locationX, locationY) { for ( x = 0; x < idArray.length; x++ ) { for ( y = 0; y < nodes.length;

Constrained d3.js Force display

放肆的年华 提交于 2019-11-30 20:21:01
I'd like to do something a little bit out of the ordinary with force layouts (for visualizing graphs). Constellations and all are fun to look at, but for timeseries data, it's not that helpful. I'd like to be able to constrain the layout by some axis, for example, by laying out the nodes according to the time they appear in a dataset, while still retaining the "bouncyness" of the visualization. Is this possible using d3? To elaborate on my comment, yes, this is perfectly possible. The force layout does not in fact position the nodes itself, it merely computes the positions. In the handler of

Unable to get click event in D3 JavaScript library

倾然丶 夕夏残阳落幕 提交于 2019-11-30 18:58:13
I am using D3 JavaScript library to display data as a force directed marker. It works fine. But I am unable to add click event to the circle. so when I click on the circle, I get detailed analysis of the circle and display it in a modal box. var links = [{source: "x", target:"y", type: "paid"},......]'; var nodes = {}; // Compute the distinct nodes from the links. links.forEach(function(link) { link.source = nodes[link.source] || (nodes[link.source] = {name: link.source}); link.target = nodes[link.target] || (nodes[link.target] = {name: link.target}); }); var w = 950, h = 500; var force = d3

Conflict between d3.forceCollide() and d3.forceX/Y() with high strength() value

核能气质少年 提交于 2019-11-30 18:45:53
问题 I believe I found a bug in D3 v4.x (v4.5.0), when in a force-directed chart one combines d3.forceCollide to prevent nodes from overlapping and d3.forceX/Y to set the position of the nodes with a high strength value, and I’m about to create an issue in D3 GitHub repository. However, before creating the issue, I’d like to check it with the D3 users here on StackOverflow: it may not be a bug , it may be the very expected behaviour of using such combination. The code In the S.O. snippet below, I

D3.js how do I arrange nodes of a force layout to be on a circle

匆匆过客 提交于 2019-11-30 17:31:20
问题 I have developed a force layout to represent relationships between social groups. Now I would like to get the nodes to be distributed in a circle with links joining them. What is the best way to do this? The complete version of the code (without data) is here http://jsfiddle.net/PatriciaW/zZSJT/ (Why do I have to include code here too? Here is the main portion) d3.json("/relationships?nocache=" + (new Date()).getTime(),function(error,members){ var links=members.organizations.map(function