score:4
Accepted answer
Yes, that is possible in D3.js, however, I recommend the webcola library since it is more easy and faster and works very well with D3.js.
Each edge may contain other information besides source
and target
. So, it is easy to add a weight
attribute, e.g.:
let edge = {
source: node1,
target: node2,
weight: 2
};
When using webcola (https://github.com/tgdwyer/WebCola/), you can add some constraints to use your weights, or you can use the linkDistance
as a function, explained here: https://github.com/tgdwyer/WebCola/wiki/link-lengths, e.g.:
let weightFactor = 10;
let d3cola = cola.d3adaptor(d3)
.size([500, 400])
.linkDistance(function (l) { return l.weight * weightFactor; };
So, the steps are:
- Build your graph with D3.js, however,
- Simulate it with webcola
You can create an instance of a webcola simulation for d3.js like that:
d3cola.avoidOverlaps(true)
.handleDisconnected(false)
.start(30);
let simulation = this.d3cola
.nodes(graph.nodes) // graph is your graph
.links(graph.edges)
.start();
Source: stackoverflow.com
Related Query
- how to generate a network graph with edge weight using D3.js force layout
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- Using Drop-down menu with D3 force layout graph
- How to make force layout graph in D3.js responsive to screen/browser size
- Simple graph of nodes and links without using force layout
- Graph with auto layout using d3 (a tree with multiple parent nodes)
- How to show a tooltip with value when mouseover a svg line graph using d3.js?
- D3 force layout graph with nodes positioned in a grid
- How to get the same node positions in d3's force layout graph
- How to check d3 js force graph for nodes with no links and remove them?
- How to stop a d3 force graph layout simulation?
- How to modify a d3 force layout with voronoi polygons to trigger events on grouped elements?
- How to create d3.js Collapsible force layout with non tree data?
- Link D3 force layout network diagram with table on mouseover
- How to use D3 force layout with existing SVG elements as nodes
- How to pan to a node using d3's force layout
- How to generate links towards right side in force layout D3.js
- How do I make a d3.js force directed graph interactive using ajax and python?
- how to add mouse events to force directed graph using the d3 canvas renderer?
- How to code a simple d3.js network graph using DIVs as nodes
- How do I replace a node with an image using D3 and CoffeeScript for a network visualization?
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- d3.js force layout graph : how to build the nodes object from scratch?
- Using data(...) in D3 force layout to update the graph
- How can i convert d3 force directive graph to use with angularjs?
- How to show edges in force directed graph using d3.js and Angular?
- How to draw a multi line series graph using d3.js with json data using angular directives
- D3.js network graph using force-directed layout and rectangles for nodes
- d3.js Combining the draggable network with a force directed graph
- How to set cx and cy with only one function using d3.js, force and network?
More Query from same tag
- Is it possible to vary the time interval while the timer is running in d3.js?
- d3 x scale and labels at the bottom
- Variable precision in d3.format
- how to rotate any shape continuously in D3 js?
- Display original and updated data of the bar chart
- Drag not working properly after applying scale transform on force layout
- Getting key and value of object
- d3js: `xlink:href` is not working
- d3 or nvd3 - Rendering Y axis title horizontally or on mousover on ticks
- d3 flickering line on setInterval
- d3 tooltip position issue in line chart using javascript
- event.touches detecting multiple touch events after touch screen spam
- D3 triangle positioning to an exact point
- Replicating a chropleth in D3.js using d3.tsv
- D3 getting JSON data within a JSON
- D3.js polylinear quantize scale
- Does the click event mutate the source json in this D3 example?
- Can't load TSV when using D3.JS
- Plotting along a path in d3.js
- How to show labels in first two rings only in a zoomable sunburst partition with rotated labels?
- Pan, zoom canvas together with drag nodes in D3
- Google API V3: How to remove overlay using Custom Overlay's onRemove() method
- How to create a grouped waterfall chart in amchart?
- nvd3 data holes in charts
- webpack 4 and d3 es6 imports not working
- Overlay d3 paths onto Google Maps?
- d3.js v3 time scale: How to change default hour in label to specific hour
- .exit().remove() appears to remove text but not rectangle in line chart legend
- D3.js bar chart 'enter' appears to draw the new bars in wrong position
- Graphviz svg output, groups not positioned