Is it possible to โuseโ a whole different svg in a separate svg? I want to use the map generated with d3 as an icon on the same page. This is what I tried, but it does not work.
<svg id="map"> svg stuff here </svg> <svg id="bar"> svg stuff here <use xlink:href="#map" height="20" width="30" ...> </svg>
I also tried the cloning approach, but in the end all svg appeared in another svg and could not scale it. eg. makeicon ("# map", "#icon")
function makeicon(source, destination) { //https://groups.google.com/forum/?fromgroups=#!topic/d3-js/-EEgqt29wmQ var src = d3.select(source); var dest = d3.select(destination); if (!src.empty() && !dest.empty()) { var newNode = d3.select(dest.node().insertBefore(src.node().cloneNode(true), src.node().nextSibling)) .attr("id", "newnode") .attr("width", null) // remove height and width of original svg .attr("height", null) .attr("viewBox", "0 0 20 30"); // try to make it smaller return newNode;
source share