score:2
Accepted answer
Here is how you can fix your layout problem.
Instead of setting cx and cy to circle in the tick.
Do following:
- Make a group
- Add circle to above group (do not set cx/cy)
- Add path to the above group. (do not set transform)
In tick
do following to transform both circle and path which is contained in it.
function tick() {
link.attr("x1", function(d) {
return d.source.x;
})
.attr("y1", function(d) {
return d.source.y;
})
.attr("x2", function(d) {
return d.target.x;
})
.attr("y2", function(d) {
return d.target.y;
});
//transform for nodes.
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")"
})
}
Working code here
Hope this helps!
Source: stackoverflow.com
Related Query
- Grouping Circles and Path as a node in D3 Force Layout?
- d3.js - Force Layout and Node Positions
- D3 force layout change links into paths and place arrows on node edge instead of center
- D3 force directed layout - changing node color and its links color on button click
- Are node x and y automatically set in force layout graphs?
- D3.js v4 Force layout and fixed node anomaly
- Create nodes based on content BBox and get width of source node when adding links in force layout
- Meaning of node size in force layout and calculating radius
- D3 force layout shall add nodes and links when clicking a node
- D3 Force Layout - Text Wrapping and Node Overlaps
- D3.js force layout : show root path of any node
- d3 force layout zoom and pan conflict with node drag
- Fix Node Position in D3 Force Directed Layout
- Add text label to d3 node in Force directed Graph and resize on hover
- Simple graph of nodes and links without using force layout
- D3 force directed graph with drag and drop support to make selected node position fixed when dropped
- d3.js: "Cannot read property 'weight' of undefined" when manually defining both nodes and links for force layout
- Avoid collision between nodes and edges in D3 force layout
- Saving and reloading a force layout using d3.js
- d3.js: suggested node position in force layout
- D3 force layout fix root node at the center
- D3 Force Layout Graph - Self linking node
- Space out nodes evenly around root node in D3 force layout
- Add text label to d3 node in Force layout
- Align Marker on node edges D3 Force Layout
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- Relation between LinkDistance and LinkStrength in D3.js Force layout
- D3js force layout destroy and reset
- Stop Force Layout on d3js and start free dragging nodes
- Recentering D3 force layout diagram on node click
More Query from same tag
- d3 v6 RuntimeError: circular definition error after drag end
- zooming and panning - upgrading d3 code to d3.v4
- d3:Adding Axis like a Box
- d3.json getting 'Uncaught SyntaxError: missing ) after argument list'
- Make circles match same color filtering as multi-line on d3.js?
- D3.js Highlight an element when hovering over another
- how to import php script that convert mysql data to json format, from d3.json function in force directed layout
- Filter by Point in Polygon and Return County ID/Name
- javascript d3 render chart
- How to display percentage in Pie Chart for DIMPLE js
- How to zoom properly using D3.js?
- How to bind d3 generated HTML elements to scope?
- How to read data generated from REST API in a Javascript file and use it another?
- d3 convert bar chart to grouped bar chart
- D3js v5 tree draggable
- D3 Graph Won't Show dynamically created JSON
- d3.js accessing the DOM on ready document
- D3 Zoom TypeError: t.apply is not a function
- Angular D3 TopoJSON: mouseover tooltip coordinates wrong
- Modify and display abbreviated data in the table generated using D3
- How in d3.js pass current selection to .each() callback?
- How to change the distance between nodes in a force layout?
- D3.js: Cannot make Y axis scrollable and X axis fixed
- How to create a Javascript Table Lens
- Can it is possible to use click event in tag cloud of D3 and If yes how?
- How to change json file in d3.js and update chart using select options
- Simplest way to store 2d array in external file
- Plotting a line using d3 and an JSON data object passed from rails
- include d3.js into angular2 project
- JavaScript Uncaught Reference when using setTimeout()