force-layout

Why does d3.js v3 break my force graph when implementing zooming when v2 doesn't?

泄露秘密 提交于 2019-11-26 22:04:09
I have a force layout that I have created using d3.js I would like to have both the normal functionality of a draggable force layout as well as the ability to zoom. I have basically copy/pasted the zooming code from ( http://jsfiddle.net/nrabinowitz/QMKm3/ ). This is the same way of zooming that Mike Bostock uses in ( http://bl.ocks.org/mbostock/3680957 ). Here is my code: http://jsfiddle.net/kM4Hs/6/ The zooming works fine, but I am unable to select single nodes in the force layout and drag them around. I have found the culprit to be the fact that both authors use d3.v2.js rather than the

D3 force directed layout with bounding box

妖精的绣舞 提交于 2019-11-26 21:54:19
I am new to D3 and having trouble setting the bounds for my force directed layout. I have managed to piece together (from examples) what I would like, but I need the graph to be contained. In the tick function, a transform/translate will display my graph correctly, but when i use cx and cy with Math.max/min (See commented code), the nodes are pinned to the top left corner while the lines are contained properly. Here is what I have below... what am I doing wrong?? var w=960, h=500, r=8, z = d3.scale.category20(); var color = d3.scale.category20(); var force = d3.layout.force() .linkDistance(

D3js: Automatic labels placement to avoid overlaps? (force repulsion)

时间秒杀一切 提交于 2019-11-26 21:33:05
How to apply force repulsion on map's labels so they find their right places automatically ? Bostock' "Let's Make a Map" Mike Bostock's Let's Make a Map (screenshot below). By default, labels are put at the point's coordinates and polygons/multipolygons's path.centroid(d) + a simple left or right align, so they frequently enter in conflict. Handmade label placements One improvement I met requires to add an human made IF fixes, and to add as many as needed, such : .attr("dy", function(d){ if(d.properties.name==="Berlin") {return ".9em"} }) The whole become increasingly dirty as the number of

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 19:36:24
问题 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

semantic zooming of the force directed graph in d3

萝らか妹 提交于 2019-11-26 18:39:38
Many cases have been shown for force directed graph geometric zooming by SVG Geometric Zooming . In geometric zooming, I only need to add a transform attribute in zoom function. However, in semantic zooming, if I only add a transform attribute in node, links won't connect to node. So, I am wondering whether there exist a solution for geometric zooming for force directed graph in d3. Here is my example with geometric zooming following previous case. I have two problems: When I zoom out, then drag whole graph, the graph will strangely disappear. Using the same redraw function function zoom() {

D3.js: Remove force.drag from a selection

假如想象 提交于 2019-11-26 17:49:04
问题 I have a (rather simple) question: How to "un-call" force.drag on a selection made by D3.js? Let's say I created a set of elements and called "call" on it, giving it the drag-callback of a force-directed layout. That looked like this: d3.selectAll('rect').call(force.drag); Now it shall be possible to remove that behavior from some of the nodes later on. My approaches included resetting various listeners, such as 'click', 'drag' etc. using d3.select('rect#no-drag').on('click', null); None of

D3 force layout fix root node at the center

橙三吉。 提交于 2019-11-26 17:11:45
问题 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? 回答1: force.on("tick", function() { nodes[0].x = w / 2; nodes[0].y = h / 2

Updating links on a force directed graph from dynamic json data

天大地大妈咪最大 提交于 2019-11-26 15:09:18
问题 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

Display an arrow head in the middle of D3 force layout link

风流意气都作罢 提交于 2019-11-26 13:45:27
问题 I'm using D3 to draw a force-directed graph, which is very similar to this example: http://bl.ocks.org/mbostock/1153292 I'm trying to place the arrowheads in the middle of the links instead of the end. Playing with the attr("refX", 0) of the marker doesn't help much, because it's absolute and not relative to the link length - my links have varying lengths. I've been googling around, and my best idea was to replace link.attr("marker-end", ...) with link.attr("marker-segment", ...) according to

Align Marker on node edges D3 Force Layout

你。 提交于 2019-11-26 09:43:34
问题 I\'m trying to implement a d3 force layout and can\'t figure out how to position the markers of my links in a proper way. Here is what I got so far: var links = force_data.force_directed_data.links; 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}); }); console.log(nodes); var width = 1000,