1 /**
  2  * Constructs a new, empty indent layout. Layouts are not typically constructed
  3  * directly; instead, they are added to an existing panel via
  4  * {@link pv.Mark#add}.
  5  *
  6  * @class Implements a hierarchical layout using the indent algorithm. This
  7  * layout implements a node-link diagram where the nodes are presented in
  8  * preorder traversal, and nodes are indented based on their depth from the
  9  * root. This technique is used ubiquitously by operating systems to represent
 10  * file directories; although it requires much vertical space, indented trees
 11  * allow efficient <i>interactive</i> exploration of trees to find a specific
 12  * node. In addition they allow rapid scanning of node labels, and multivariate
 13  * data such as file sizes can be displayed adjacent to the hierarchy.
 14  *
 15  * <p>The indent layout can be configured using the <tt>depth</tt> and
 16  * <tt>breadth</tt> properties, which control the increments in pixel space for
 17  * each indent and row in the layout. This layout does not support multiple
 18  * orientations; the root node is rendered in the top-left, while
 19  * <tt>breadth</tt> is a vertical offset from the top, and <tt>depth</tt> is a
 20  * horizontal offset from the left.
 21  *
 22  * <p>For more details on how to use this layout, see
 23  * {@link pv.Layout.Hierarchy}.
 24  *
 25  * @extends pv.Layout.Hierarchy
 26  */
 27 pv.Layout.Indent = function() {
 28   pv.Layout.Hierarchy.call(this);
 29   this.link.interpolate("step-after");
 30 };
 31 
 32 pv.Layout.Indent.prototype = pv.extend(pv.Layout.Hierarchy)
 33     .property("depth", Number)
 34     .property("breadth", Number);
 35 
 36 /**
 37  * The horizontal offset between different levels of the tree; defaults to 15.
 38  *
 39  * @type number
 40  * @name pv.Layout.Indent.prototype.depth
 41  */
 42 
 43 /**
 44  * The vertical offset between nodes; defaults to 15.
 45  *
 46  * @type number
 47  * @name pv.Layout.Indent.prototype.breadth
 48  */
 49 
 50 /**
 51  * Default properties for indent layouts. By default the depth and breadth
 52  * offsets are 15 pixels.
 53  *
 54  * @type pv.Layout.Indent
 55  */
 56 pv.Layout.Indent.prototype.defaults = new pv.Layout.Indent()
 57     .extend(pv.Layout.Hierarchy.prototype.defaults)
 58     .depth(15)
 59     .breadth(15);
 60 
 61 /** @private */
 62 pv.Layout.Indent.prototype.buildImplied = function(s) {
 63   if (pv.Layout.Hierarchy.prototype.buildImplied.call(this, s)) return;
 64 
 65   var nodes = s.nodes,
 66       bspace = s.breadth,
 67       dspace = s.depth,
 68       ax = 0,
 69       ay = 0;
 70 
 71   /** @private */
 72   function position(n, breadth, depth) {
 73     n.x = ax + depth++ * dspace;
 74     n.y = ay + breadth++ * bspace;
 75     n.midAngle = 0;
 76     for (var c = n.firstChild; c; c = c.nextSibling) {
 77       breadth = position(c, breadth, depth);
 78     }
 79     return breadth;
 80   }
 81 
 82   position(nodes[0], 1, 1);
 83 };
 84