T.J. VanSlyke is working on an application using XUL Runner “to deploy a large-scale application platform which requires a hefty Javascript class hierarchy.”

T.J. took Dean Edwards Base.js and added Base.exportDotGraph() allowing GraphViz to show the class hierarchy.

However, there is one caveat with this. Since Javascript cannot guess at the identifiers you use to declare each class, we must explicitly define the identifier we would like to use in our diagrams. To maintain backward compatibility, I have simply implemented this as a property of the prototype of the class. The Kale class

JAVASCRIPT:

  1.  
  2. var Kale = Vegetable.extend({
  3.         constructor: function() {
  4.                 this.base(); // run vegetable constructor
  5.                 // … kale constructor
  6.         }
  7. });
  8.  

thus becomes:

JAVASCRIPT:

  1.  
  2. var Kale = Vegetable.extend({
  3.         identifier: “Kale”,
  4.         constructor: function() {
  5.                 this.base(); // run vegetable constructor
  6.                 // … kale constructor
  7.         }
  8. });
  9.  

We can then feed our example.dot file into dot and generate a PNG image:

dot -Tpng example.dot -o example.png

Source: Ajaxian
Original Article: http://ajaxian.com/archives/javascript-inheritance-diagrams-with-graphviz-and-basejs

Leave a Reply

You must be logged in to post a comment.



Site Navigation