http://bl.ocks.org/JohnBerryman/2295155
This is my attempt to add templating to D3. I drew the original face in Inkscape and then I turned the SVG into an iCanHaz template and made the template variables correspond to facial measurements. This way I could define a face (and by extension, whatever else) and I could easily instantiate the face, or even let the face change by just updating the data bound to the face object. The first part of the code (if you scroll past the demo) is a patch to D3, and then the rest of the code uses that patch.
Unfortunately I didn't ever get to put nice tests around this and submit a pull request to Mr. Bostock.
Questions:
@meetamit is on the right way but you've to use a polyfill to apply d3.select.html method on SVG. This method uses innerHTML and isn't supported on SVG elements. Check the
d3.select.html reference
My solution on bl.ocks
D3 Templating Plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With