score:2
I would handle your data at the g
level and create a group for every map feature (country) which contains the path and a sibling image:
<!doctype html>
<html>
<head>
<script src="https://d3js.org/d3.v6.min.js"></script>
</head>
<body>
<svg width="600" height="600"></svg>
<script>
let svg = d3.select('svg'),
mapEPCI = {
features: [100, 200, 300, 400]
};
let g = svg.selectAll('g')
.data(mapEPCI.features)
// enter selection is collection of g
let ge = g.enter().append("g");
// append a path to each g according to data
ge.append('path')
.attr("d", (d) => "M" + d + ",10L" + d + ",100")
.style("stroke", "black");
// append a sibling image
ge.append("image")
.attr("xlink:href", "https://placeimg.com/20/15/animals")
.attr("width", "20")
.attr("height", "15")
.attr("transform", function(d) {
// find my sibling path to get bbox
let sibling = this.parentNode.firstChild;
let bbox = sibling.getBBox();
return "translate(" + (bbox.x - 20 / 2) + "," + (bbox.y + bbox.height / 2 - 15 / 2) + ")"
});
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- Append two elements in svg at the same level
- D3js how to append 2 children at the same level in .enter context
- d3.js: How to deal with svg elements that are being appended on the same position, one on top of the other?
- How to update all existing elements in the same level with same parent value?
- d3 - append two objects to the same parent
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- Can d3.js draw two scatterplots on the same graph using data from the same source?
- maximum number of svg elements for the browser in a map
- How to update the fill color on existing svg elements with d3.js?
- How do I associate SVG elements generated by graphviz to elements in the DOT source code
- How can I copy the content of my SVG and append it to another SVG frame?
- d3 - Append elements to external SVG file
- Path in SVG placed in front of the circles in D3 chart, despite the order of append
- Mouseover event on two charts at the same time d3.js
- How do I scroll d3 elements while keeping a portion of the svg in a fixed position?
- Append svg icon always right behind the text
- Make two pie charts with the same d3js code
- D3.js Moving elements in the svg structure
- How do I reduce two arrays to a single value that is present at the same index?
- D3.js: "On the fly" added elements to array are not refreshing the svg graphic
- How to append javascript file to the body from javascript file which is in the same directory. Java server faces 2 JSF2
- How do you prevent the interference of MULTIPLE SVG elements (text labels) on mouseover of a different SVG element?
- How can the elements in SVG can't be dragged out of the scope of SVG?
- How to reuse the same pattern on multiple svg circles in d3.js
- Two scripts adding different listeners to the same element
- Two D3.js graph in the same page with AngularJS
- Display all the leafs on the same level with D3.JS
- Mirrored pan/zoom two svg elements
- How do I use two versions of the same javascript library without bleeding functions in the same page?
- How do I append the text tag to just one svg e.g. svg tag with "id=50"?
More Query from same tag
- How to access attributes of an element inside a group?
- Combining D3 Visualization
- d3 set number of gradation for color scales
- Adding images to the nodes' circles in the Mobile Patent Suits example
- Unable to position tooltip on d3.js pie chart in Angular
- D3 bar chart not parsing csv
- D3v4: missing text in circle for force directed graph
- D3 add zoom to circle pack
- Passing json object from grails controller to a gsp rendering a d3 chart?
- Feeding data into database with Php form and using that data into JSON format to be used in D3
- Reset drag position after repositioning map in D3.js
- Using div tooltips versus using g tooltips in d3
- D3.js join data from multiple csv files
- d3.js v5 : Unable to get data points to show on map of US
- how to change text angle for labels in D3.js?
- How do I use D3 to I populate drop-down options from JSON?
- d3.js : Getting gradients on a bar chart?
- D3.js: Dragging everything in group ('g') by element contained in the group using origin() function
- D3.js - Text not appearing in circles
- JS Recursion Maximum call stack size exceeded: difference between 2 functions
- get d3.extent of property from a shapefile to use as domain
- Data keyfunction filter always returning first element
- d3 Sankey assign fixed x,y position
- Force simulation is jittery when using svg transforms to update position
- D3.JS Browser Support
- Highlight all connected paths from start to end of a sankey diagram using networkD3
- D3js with element base on data
- D3 fade function Circle Graph
- How to sort object by key through JSON file parsing in D3.js
- How to get a value from a nested object in a GeoJson object in d3js?