javascript - D3 append (insert) existing SVG string (or element) to a DIV -


i've searched on place answer question , found resources thought may useful, did not lead me answer. here few...

the issue

what trying append existing svg element or string div on page , able apply various d3.js properties , attributes on it, can later manipulate , work (such apply zooming abilities, etc.).

i using jquery svg in did this:

var shapesrequest= '"<svg id="shapes" width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg">' +        '<polygon id="svgsection_floor" points="222.61,199.75,222.61,295.19,380.62,295.19,380.62,199.75,222.61,199.75,368.46,283.92,233.54,283.92,233.54,209.12,368.46,209.12,368.46,283.92" title="floor" link="primary" />' +        '<text x="302.61" y="289.4705">floor</text>...and lot more of same...</svg>'; $('#svgtmp').append(shapesrequest); $('#svgtmp #shapes text').attr('fill', 'white').attr('font-size', '9').attr('font-weight', 'bold'); $('#pnlshapes').width(640).height(480).svg().svg('get').add($('#svgtmp #shapes')); 

so jquery svg , code doing appending svg string temporary div, manipulating properties within svg, adding svg permanent location on page.

this trying d3. although not sure if need append temporary div first, have access svg string , append/attach dom element d3.

what i've tried...

var mapsvg = d3.select("#pnlshapes").append("svg").attr("width", svgwidth).attr("height", svgheight); d3.xml(shapesrequest, function (xmldata) {     var svgnode = xmldata.getelementsbytagname("svg")[0];     mapsvg.node().appendchild(svgnode); }); 

but isn't correct approach, not hitting external api endpoint retrieve svg - have stored string.

i looking @ doing this

d3.select("#pnlshapes").append('svg').append(shapesrequest).attr("width", svgwidth).attr("height", svgheight); 

but .append() when using d3 isn't used kind of appending.


question

what proper way append existing svg string dom using d3 (also i'm using jquery if helps)? ultimate goal append svg , allow zoomable using this tutorial base.

you can use .html insert string dom node

d3.select('#svgtmp').append('div').html('<svg...') 

there may more elegant way without <div>.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -