d3-force-directed

Stop moving other nodes while dragging one node in D3 forceSimulation

本秂侑毒 提交于 2021-02-08 03:41:18
问题 I made a D3 forced-directed graph by d3.forceSimulation() and attached the drag function. While clicking one node, I don't want other nodes to move accordingly. Now I can freeze the node being dragged by setting the d.fx and d.fy as the following: function dragended(d) { if (!d3.event.active) simulation.alphaTarget(0); d.fx = d.x; d.fy = d.y; } Is it possible to freeze all the other nodes while dragging one node? 回答1: Thanks @rioV8 for the hint! I tried to fix the other nodes while dragging

How to update d3-force elements?

江枫思渺然 提交于 2021-01-28 07:10:52
问题 I want to update d3-force elements when click, but I find something wrong. What I want is: generate all links first then generate all nodes, so that the node can override the link So when clicked the elements should be: <svg> <line ...></line> <line ...></line> <line ...></line> <line ...></line> <g><circle ...></circle></g> <g><circle ...></circle></g> <g><circle ...></circle></g> <g><circle ...></circle></g> <g><circle ...></circle></g> </svg> But I get: <svg> <g><circle ...></circle></g>

Set initial d3 zoom based on boundary dynamically - V4

主宰稳场 提交于 2020-12-01 07:27:07
问题 I have a large number of nodes to display on the page, most of the times the circles goes off the visible area of the screen due to node placements. Is there a way to set the initial zoom level based on the whole boundary box of nodes dynamically so that all the nodes fits on the visible area of the screen? Updated: I have added a fiddle for this https://jsfiddle.net/navinleon/6ygaxoyq/3/ var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); var zoom = d3.zoom(

Set initial d3 zoom based on boundary dynamically - V4

删除回忆录丶 提交于 2020-12-01 07:26:13
问题 I have a large number of nodes to display on the page, most of the times the circles goes off the visible area of the screen due to node placements. Is there a way to set the initial zoom level based on the whole boundary box of nodes dynamically so that all the nodes fits on the visible area of the screen? Updated: I have added a fiddle for this https://jsfiddle.net/navinleon/6ygaxoyq/3/ var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); var zoom = d3.zoom(

How to add text to svg circle in d3

浪子不回头ぞ 提交于 2020-01-24 01:10:28
问题 I have the following code and I would like to add text in the circles. How could I make it possible; I have looked at these possible duplicates Insert text inside Circle in D3 chart const link = svg.append("g") .attr("stroke", "#999") .attr("stroke-opacity", 0.6) .selectAll("line") .data(links) .enter().append("line") .attr("stroke-width", d => Math.sqrt(d.value)); // link.append("title").text(d => d.value); const node = svg.append("g") .attr("stroke", "#fff") .attr("stroke-width", 1.5)

Explain Mike Bostock Node-Parsing Loop [duplicate]

感情迁移 提交于 2019-12-20 02:15:44
问题 This question already has answers here : variable declaration conditional syntax (3 answers) Closed 2 years ago . I'm relatively new to JavaScript and d3, but I'm really interested in force-directed layouts. In Mike Bostock's force-directed visualizations, he tends to parse nodes from a list of links using the following code (or similar): var links = [ {source: "A", target: "B"}, {source: "B", target: "C"}, {source: "C", target: "A"}]; var nodes = {}; links.forEach(function(link) { link

d3-force update radius of forceCollide after initializing graph

亡梦爱人 提交于 2019-12-19 08:59:31
问题 This question is a follow-up on a previous one titled "D3-Force updating parameters after initializing graph" (D3-Force updating parameters after initializing graph) and that @altocumulus answered. I am trying to update the simulation forces after modifying the radius of some nodes. However, when I call on forceCollide to account for the changes it does not work. The graph first initiates correctly, using forceCollide and a function to have the force correspond with the radius: var

d3.js: Pass anonymous function as parameter to centering force?

守給你的承諾、 提交于 2019-12-12 12:02:38
问题 I'm making an interactive bubble chart and I'm working on functionality to split the data into two groups which move to opposite sides of the screen. I'm using a centering force for my simulation because I think it gives a much nicer and more consistent display of the data than using forceX and forceY does. However, I'm having trouble with the splitting of my data. I had the idea that, since you can pass an anonymous function as a parameter to forceX to determine whether a node moves left or