force-layout

How can I dynamically change the position and the size of direction arrows on a directed d3.js force layout?

我是研究僧i 提交于 2019-12-06 11:36:34
I am currently implementing arrows in my force layout as is done in this example ( http://bl.ocks.org/mbostock/1153292 ) and that works perfectly. However, one will quickly realize that the location and size of the arrows are hard-coded here since the nodes never change size. I have a graph were I dynamically change node sizes, and as such I would like the arrows to update accordingly since otherwise they are covered by the node or cover the node or are just not attached to the node. There is only one post I have found ( linking nodes of variable radius with arrows ) that talks about this

d3: Multi-Foci Force key code component understanding

[亡魂溺海] 提交于 2019-12-06 10:55:26
问题 The real magic for multi-foci force is done here; function tick(e) { var k = .1 * e.alpha; // Push nodes toward their designated focus. nodes.forEach(function(o, i) { o.y += (foci[o.id].y - o.y) * k; o.x += (foci[o.id].x - o.x) * k; }); node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); } but I'd appreciate some clarification about what's going on. alpha, I believe, is a force method that controls the rate at which the force comes to rest, accepting values

Add labels to nodes in Hobbelt's “Group/Bundle Nodes” D3 force layout example?

醉酒当歌 提交于 2019-12-06 10:47:16
I adapted Ger Hobbelt's excellent example of group/bundle nodes https://gist.github.com/GerHobbelt/3071239 as a JSFiddle here: https://jsfiddle.net/NovasTaylor/tco2fkad/ The display demonstrates both collapsible nodes and regions (hulls). The one tweak that eludes me is how to add labels to expanded nodes. I have successfully added labels to nodes in my other force network diagrams using code similar to: nodes.append("text") .attr("class", "nodetext") .attr("dx", 12) .attr("dy", ".35em") .text(function(d) { // d.name is a label for the node, present in the JSON source return d.name; }); Is

Using the force-layout physics for seperated elements

对着背影说爱祢 提交于 2019-12-06 08:47:30
I use the force layout in D3.js v4. Now I want to click on a node and use the force physics like collide for that one node only. The simulation for every node on the entire SVG is this: var simulation = d3.forceSimulation() .force("link", d3.forceLink().id(function(d) { return d.index })) .force("collide", d3.forceCollide(function(d) { return d.r + 8 }).iterations(16)) .force("charge", d3.forceManyBody()) .force("center", d3.forceCenter(chartWidth / 2, chartWidth / 2)) Now I want to change the collide behavior for the one node I clicked on to push other nodes away or attract them. Is there

d3js: _on()_ doesn't send the current datum object to the onmouse function

拜拜、爱过 提交于 2019-12-06 07:58:58
I would like to highlight the edges of a graph when the connected nodes are hovered. I took inspiration from the Bundle example : 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

Cannot read property 'weight' of undefined in d3.force implementation

假如想象 提交于 2019-12-06 05:31:23
问题 I've been stuck on this problem for a while now and have no idea what to do even based on existing answers. I keep getting this error on the last JSON entry of a uniform response. ...{"paperCount": 1, "PMIDs": [20626970], "authorA": 79, "authorB": 80}, {"paperCount": 1, "PMIDs": [20492581], "authorA": 81, "authorB": 82}, {"paperCount": 1, "PMIDs": [20492581], "authorA": 81, "authorB": 83}, {"paperCount": 1, "PMIDs": [20492581], "authorA": 81, "authorB": 84}, {"paperCount": 1, "PMIDs":

Node size proportional to number of children in D3

巧了我就是萌 提交于 2019-12-06 03:17:19
问题 I created this click-expand-collapse network -http://jsfiddle.net/5Lv8gkqv/ var width = 960, height = 500, root = { "name": "Chocolate", "tag":"class", "children": [ { "name": "Wafer", "tag":"subclass", "children": [ { "name": "Nestle", "tag":"company", "children": [ {"name": "KitKat", "tag":"product"} ] } ] }, { "name": "White", "tag":"subclass", "children": [ { "name": "Nestle", "tag":"company", "children": [ {"name": "Milkybar", "tag":"product"} ] } ] }, { "name": "Caramel", "tag":

Inserting a line break in D3 force layout node labels

折月煮酒 提交于 2019-12-06 02:31:25
问题 So, I am playing with force directed graph, and I've made that .text on my node changes on mouse over to another text from data. My code looks like this: script: var data = {"nodes":[ {"name":"YHO", "full_name":"Yahoo", "type":1, "slug": "www.yahoo.com", "entity":"company", "img_hrefD":"", "img_hrefL":""}, {"name":"GGL", "full_name":"Google", "type":2, "slug": "www.google.com", "entity":"company", "img_hrefD":"", "img_hrefL":""}, {"name":"BNG", "full_name":"Bing", "type":2, "slug": "www.bing

d3js force directed - On hover to node, highlight/colourup linked nodes and links?

冷暖自知 提交于 2019-12-06 02:19:16
问题 I have force directed graph with 4 types of nodes and two types of links. One type of node (the small blue one) I'm using as "connection node" between two bigger nodes. on mouseover node, it gets bigger, but also I wanna colour up "connections" to this node in different color. So whey you hover over a node... all links and little "connection nodes" gets in the different color, so you can know to which other bigger node is this one hovered connected. You can see my situation on following link:

add different shapes to d3 force layout

狂风中的少年 提交于 2019-12-05 23:58:21
I'm trying to add different shapes to my d3 force layout but unsucessfully. The end goal is determine the shape based on properties of the node object itself. I'm using selection.enter() to then .append() the shapes like so. As the force directed layout only takes one array of nodes, and .append() takes a string and not a function node = vis.selectAll('.node') .data(nodes, function(d) { return d.filename }); then... node.enter() .append(**'rect'**) //I need to vary this based on node properties .attr('class', function(d) { return 'node ' + d.entityType; //return d.entityType; }); I am unsure