score:3
Based on advice from Lars Kotfoff :
Working fiddle here
If the elements to be graph-ed already exist, simply skip the enter() D3 phase and use select() or selectAll() based on a common characteristic of your elements ( a class name for instance ).
This is how the element got created ( added a specific class for allowing an isolated selection ):
var element0a = svgContainer.append("g").attr("class","node").attr("transform","translate(100,100)");
var element0b = element0a.append("rect").attr("x",0).attr("y",0).attr("width",20).attr("height",10).attr("fill","red");
This is thene part of the code replacing the enter() phase
var node = svgContainer.selectAll("g.node")
.data(nodeArray)
.call(force.drag);
This is what was removed
var node = svgContainer.selectAll("g.node")
.data(nodeArray)
.enter().append("svg:g")
.attr("class", "node")
.call(force.drag);
// HERE (below) COMES THE ISSUE, where you see append("cicle") I want to append the nodeArray's ".ui" element.
node.append("circle") // <---
.attr("class", "node")
.attr("r",10)
.attr("fill","orange")
.call(force.drag);
score:0
The problem is that you append the elements to svgContainer
to create them, thus they are already attached to something.
What I would suggest as a workaround is to store the element properties in a json file and then read the configuration from the json.
There might be something more elegant.
Source: stackoverflow.com
Related Query
- How to use D3 force layout with existing SVG elements as nodes
- How to update the fill color on existing svg elements with d3.js?
- How to update elements of D3 force layout when the underlying data changes
- Update existing nodes in a d3 Force Layout
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- d3js create a force layout with fixed nodes
- d3.js: How to remove nodes when link-data updates in a force layout
- How to move elements along with svg group
- D3 force layout graph with nodes positioned in a grid
- How to check d3 js force graph for nodes with no links and remove them?
- How to modify a d3 force layout with voronoi polygons to trigger events on grouped elements?
- d3.js: Drag is disabled when use zoom with force layout
- Dragging nodes with labels in d3 v4 force layout glitches
- d3js (v4) canvas force layout with text on nodes
- D3.js how to transition in opposite direction with basic SVG elements
- D3.js how do I arrange nodes of a force layout to be on a circle
- Speed up d3 force layout with many nodes and links
- D3js force layout - line with gradient between nodes
- Possible to use SVG markup with a force in D3?
- how to generate a network graph with edge weight using D3.js force layout
- Get attributes of existing SVG elements and bind as data with d3.js
- How to create d3.js Collapsible force layout with non tree data?
- Force layout inside force layout: How to drag inner nodes
- d3 force collapsible layout - start page with all nodes collapsed
- How do you translate HTML elements along with SVG elements when zooming and panning with D3
- how to vary distance between d3 nodes in force layout
- How to add links from CSV file to SVG elements generated with D3?
- How can I add an external group to an existing svg with d3.js?
- How to snap svg element to grid while dragging in force layout
- How to properly use the Use tag in SVG with d3 js?
More Query from same tag
- How to avoid .lower() to reshuffle elements in d3?
- Replace string by an other variable with a string
- How to make D3 display xAxis correctly during daylight saving time change
- d3js overlapping elements: how to "pass through" clicks to "lower" element?
- Is it possible to make offset/shift in d3.js scales?
- How to stop Angular handling a click event from within d3
- meshing a map using d3.js
- How to group elements by row?
- D3.js How do I rotate a Marimekko chart
- d3.js Add labels in Chord diagram
- D3.js WordCloud: Words overlap and have weird spacing & distribution
- Automatically place text from two data variables into an svg with d3
- d3.js an Inverse bubble chart
- how to show bar chart based on multiple filter values in D3 js
- Is it possible to use d3.svg.symbol along with svg.marker
- D3js: how to get Lat/Log geocoordinates from mouse click?
- How to know if topojson is installed and working normally?
- Visualizing polynomial functions with d3.js
- Replace Circles and Texts in d3 demo with foreignObject containing custom HTML and ko binding
- D3 graph not displaying JSON information from variable
- d3.js pan restricted behaviour
- How to use element from defs inside a circle in D3.JS
- How to filter children based on whether the parent is filtered in D3?
- How can I draw an autoscaling D3.js graph that plots a mathematical function?
- React-D3 using fetch data
- How to add text alternative for external images in SVG?
- Transition of an axis
- d3 image on top of node / circle doesn't work with clipPath
- How to set a scale for the time series, current x scale gives me NaN?
- How to hide folders using partition layout based on available space in D3?