Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding templating to D3

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:

  1. I'm still new to D3. Is this something that can otherwise be done in D3 and I just don't know about it.
  2. Is this generally useful? Is it worth submitting a pull request?
  3. Is it d3-esque? Does the code here represent code appropriate for d3?
like image 391
JnBrymn Avatar asked Mar 31 '26 22:03

JnBrymn


1 Answers

@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

like image 90
jkutianski Avatar answered Apr 03 '26 16:04

jkutianski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!