score:2
Accepted answer
After reading selection.data on the d3 wiki again, i finally got it working.
I merged my notes beforehand, so my selection included the enter and update nodes. What i did now was first to create the enter nodes, then do the selections and filters on them and merge them afterwards.
function draw() {
self.domNodes = self.domNodes.data(self.nodes, (node) => node.id)
self.domNodes.exit().remove()
// all nodes
const enterNodes = self.domNodes.enter()
.append('g')
.attr('class', (node) => `node ${node.type}`)
// contributions
enterNodes.filter((d) => d.type === 'contribution')
.append('circle')
.attr('r', 4)
.attr('fill', 'blue')
// persons
enterNodes.filter((d) => d.type === 'person')
.append('other elements and attributes...')
self.domNodes = self.domNodes.merge(enterNodes)
self.simulation.nodes(self.nodes)
self.simulation.force('link').links(self.links)
self.simulation.alpha(1).restart()
}
Source: stackoverflow.com
Related Query
- Adding child elements to specific nodes in a force-directed graph using d3js
- How to change the colors of nodes in force directed graph in d3js using javascript?
- Adding and Removing Nodes in D3js Force Graph
- Dynamically adding nodes to d3.js Force directed graph
- D3js - Force directed graph - advanced highlighting of neigbour nodes and links, is it possible?
- d3.js Force Directed Graph - Using Images instead of Circles for the Nodes
- Adding nodes group by group to a D3 force directed graph
- Issues with adding a link via mouse click to two nodes in force directed graph
- d3 v4 adding new nodes to force directed graph
- Simple graph of nodes and links without using force layout
- Labels / text on the nodes of a D3 force directed graph
- d3js force directed - On hover to node, highlight/colourup linked nodes and links?
- D3js Force Directed Graph Link not found
- enclosing the nodes of a d3 force directed graph in a circle or a polygon or a cloud
- Place pie charts on nodes of force directed layout graph in D3
- Adding label to the links in D3 force directed graph
- How do I make a d3.js force directed graph interactive using ajax and python?
- D3v4 force directed graph - localStorage disconnects links and nodes
- d3js Force Directed Graph - Click on node to popup infobox which read from JSON
- how to add mouse events to force directed graph using the d3 canvas renderer?
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- Adding Multiple shaped nodes to a force directed network diagram in d3v4
- How to restrict number of nodes initially in d3 Force directed graph
- D3JS Force network: Links to nodes that are grouped using formula in transform fnt
- How do I group the nodes in a force directed graph
- how to highlight(change color) of all connected(neighbours) nodes and links in a d3 force directed graph
- How to change color of nodes in force directed graph
- d3 force directed graph nodes stay at fixed position after filter
- D3 force directed graph issue: nodes are stacked at coordinate (0,0)
- force directed graph - width of link based on number of connections (volume) between nodes
More Query from same tag
- Tooltips not showing on mouse move and mouse over
- D3 positioning a custom SVG on scattersplot
- D3 graphs Multi series with different time range not working properly
- How to set color of node based on data value in D3JS
- D3 bar chart transition confusion
- Understanding a multi-line d3 chart example
- How do I display text for touch events in D3.js?
- How to use d3.symbols with an ordinal scale
- Splitting an object key name (separated by a comma) generating a new array of objects
- unable to get click event between the path link using collapse graph
- RazorEngine evaluation issue with .js code
- How to add a separator in D3 bar chart
- Javascript File Reading and Parsing Only Working with Breakpoints
- dc.js bar chart with ordinal x axis scale doesn't render correctly
- how to use .data() to append 2 children to parent w/o counting an existing child?
- d3 Bilevel Partition - equal parts
- How to sort an array in D3 without affecting the assigned color order
- reformat large csv dataset using d3 for nvd3
- D3js Contour Displaying as Black Box
- How to modify d3js fisheye distortion so that it will support radius
- Unfolding array of values into distinct categories
- D3.js draw line path with data array
- Javascript d3 insert image from local file
- How can I highlight a part of a grouped chart when filter d3
- D3js moving nested groups
- Hyperlinks in D3.js objects, part 2
- Scale / Redraw d3.js gridlines on zoom / drag
- Passing functions to d3 generators in typescript
- dc.js - Stacked bar chart with empty bin filter displaying in strange way
- SVG vs Canvas for a "wind" chart