force-layout

Collapsible D3 force directed graph with non-tree data

半腔热情 提交于 2019-11-28 06:05:14
问题 I have a D3 force directed graph using non-tree data and ID associations vs index. I cannot seem to find an example of this structure of data in a collapsible force layout. Basically, when you click a node, the data for that node should collapse/expand like this example: http://bl.ocks.org/mbostock/1062288. The last answer to this questions got close but is linking nodes by index rather than id: How to create d3.js Collapsible force layout with non tree data? Here is a fiddle of my code https

What is the difference between alphaTarget and alphaMin?

十年热恋 提交于 2019-11-28 03:04:10
问题 The description from the API is confusing. I expect target to be the value where the simulation stops ticking, but what target does is not defined in the API. Also alpha itself is not defined in the API but I found that on another website: https://roshansanthosh.wordpress.com/2016/09/25/forces-in-d3-js-v4/ An important aspect of simulations is alpha. alpha is a number between 0 and 1 and defines how far the simulation has progressed. When a simulation starts alpha is set to 1 and this value

Breaking text from json into several lines for displaying labels in a D3 force layout

↘锁芯ラ 提交于 2019-11-28 02:06:22
问题 I am new to d3.js and coding in general. This is my question: I am trying to find a way to break long displayed names of force layout objects in lines. I would like to be able to determine where to break these lines, and I am guessing this is something that might be possible to be done from the json file. I am aware that there have been similar questions asked already, but I just can't find where to put the code or why my previous attempts haven't been successful. This is the code that I have

d3.js force layout auto zoom/scale after loading

我的梦境 提交于 2019-11-27 21:11:30
问题 I'm using this nice force layout from Flowingdata.com to create a network diagram. My diagram currently shows between 5 and 750 nodes with their relations. It works great with some custom changes to fit my needs. However one thing I can't get to work. I have a viewBox with preserveAspectRatio to auto fit the container it is in. But depending on the amount of nodes there are always some nodes around the edges (mainly top and buttom) that get cut off. And if there are very little nodes, it

D3 force directed graph with drag and drop support to make selected node position fixed when dropped

倖福魔咒の 提交于 2019-11-27 19:05:18
Example on a force direct graph can be found here: http://bl.ocks.org/950642 How can I easily add support for drag and drop? It should set the node to fixed with current location of where it dropped it. It is important that rest of the nodes still uses the 'force directed mode' to position rest of the nodes in the graph automatically https://github.com/mbostock/d3/wiki/Force-Layout I've played around a bit without success, and wondering if anyone is able to give me a quick example on how to add such support as explained above. Finally got it working after figuring out it is not ideal to fight

D3 force layout fix root node at the center

故事扮演 提交于 2019-11-27 15:30:47
I managed to draw some basic d3 force layout graph, but struggling how to fix root node at the center. My data is rather simple; one root node with one-level children. Only one level. Another particular thing about my graph is that the link distance varies based on some parameter. I want root node to be at the center of the graph. Setting its property 'fixed':true doesn't work. Any idea to place root node at the center? force.on("tick", function() { nodes[0].x = w / 2; nodes[0].y = h / 2; That should do it. 来源: https://stackoverflow.com/questions/21843206/d3-force-layout-fix-root-node-at-the

Add text label to d3 node in Force directed Graph and resize on hover

旧城冷巷雨未停 提交于 2019-11-27 11:54:37
I am trying to add text label to nodes in d3 Force Directed Graph, there seems to be an issue. This is my Fiddle : When I add the node name like this: node.append("text") .attr("class", "word") .attr("dy", ".35em") .text(function(d) { console.log(d.name); return d.name; }); There's no change but the names are getting logged. When i tried using bounding box , the node labels appeared but the nodes are stacked up on the top-left corner of box while the node links are fine.This fiddle is the outcome of that effort i put in. Can anyone tell me what am i doing wrong? You are adding a text element

Updating links on a force directed graph from dynamic json data

妖精的绣舞 提交于 2019-11-27 10:23:59
I am new to D3 and working on a force directed graph where the json data is dynamic. I am able to change the force graph upon receiving new data but that happens with a springing effect. The code that creates my force graph is : <div class="graph"></div> <script> var w = 660, h = 700, r = 10; var vis = d3.select(".graph") .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'); vis.append('svg:rect') .attr('width', w) .attr('height', h) .attr('fill', 'rgba(1,1,1,0)'); function redraw()

Configure fixed-layout static graph in d3.js

女生的网名这么多〃 提交于 2019-11-27 10:10:05
问题 I have a working code example (only the <script type="text/javascript"> part) of a static graph using d3.js as below: /* Create graph data */ var nodes = []; for (var i = 0; i < 13; i++) { var datum = { "value": i }; nodes.push(datum); } var links = [{"source": 0, "target": 1}, {"source": 1, "target": 2}, {"source": 2, "target": 0}, {"source": 1, "target": 3}, {"source": 3, "target": 2}, {"source": 3, "target": 4}, {"source": 4, "target": 5}, {"source": 5, "target": 6}, {"source": 5, "target"

Add text label to d3 node in Force layout

谁说胖子不能爱 提交于 2019-11-27 09:31:17
This is my code look like, you can also have full code on JsFiddle . I want to have labels on every node, but I can't. By the way, labels can be embedded in the circle in the console . var nodes = svg.selectAll("circle") .data(dataset.nodes) .enter() .append("circle") .attr("r", 10) .style("fill", function(d, i){ return colors(i); }) .call(force.drag); var label = nodes.append("svg:text") .text(function (d) { return d.name; }) .style("text-anchor", "middle") .style("fill", "#555") .style("font-family", "Arial") .style("font-size", 12); force.on("tick", function(){ edges.attr("x1", function(d){