Creating D3js data visualizations in Stata just got a little bit easier. If you go to the libd3 Mata library repository, you'll find an object oriented D3js wrapper written in Mata with a few utility functions. In addition to implementing all of the methods/functions in the D3js library (to the best of my knowledge at least), the library includes functions that allow users to store their own JavaScript code; static members to make it a bit easier to insert newline characters/spaces, JavaScript style indents; print methods that attempt to "pretty" print the JavaScript code; and an undo method that allows you to roll back the object to its immediately prior state (e.g., if you pass some arguments and decide you didn't need it you can call .undo() to revert the object back to its state prior to current unwanted state). Additionally, with few exceptions, you can generally take existing D3js code and have a working and parameterized version of the existing code without too much additional effort
You can find a working example of a graph created with a Mata function called d3scatterTip at http://wbuchanan.github.io/d3mata-examples/.
If you're interested in testing/using this, you'll also need the libhtml Mata library to create HTML tag objects. The libhtml Mata library contains class definitions for all of the HTML5 defined tags, with corresponding accessors to tag specific attributes and global attributes. If you find any bugs/issues with any of this, please submit an issue to the corresponding GitHub repository so I can keep track of things a bit more easily and consistently.
Code:
// d3.svg.axis() won't work directly // Create a d3 object x = d3() // Now create the equivalent from above x.init().svg().axis()
If you're interested in testing/using this, you'll also need the libhtml Mata library to create HTML tag objects. The libhtml Mata library contains class definitions for all of the HTML5 defined tags, with corresponding accessors to tag specific attributes and global attributes. If you find any bugs/issues with any of this, please submit an issue to the corresponding GitHub repository so I can keep track of things a bit more easily and consistently.
Comment