But i don't know the element type or varying attributes as it is fed in. Is there a pattern to just insert an entire element as a string? or a better pattern?

网友答案:

EDIT: I just typed up the answer below, but, upon re-reading your question, I'm not sure if, by "dynamic and based on options" you actually meant that the icon type is dependent on the data. Let me know if I misinterpreted, and I'll delete this answer....

Let's say you have dataArray which is an array of objects making up your data.

And then you have:

var selection = d3.selectAll('.icon').data(dataArray)

Then, what it sounds like you're asking is to conditionally create elements of, say, either <rect> or <circle>, depending on your data. Ideally, what you would want –– BUT d3 won't let you do it –– is: