dist/js/jquery.orgchart.js
function ($appendTo, data) {
      var that = this;
      var opts = this.options;
      var level = 0;
      if (data.level) {
        level = data.level;
      } else {
        level = data.level = $appendTo.parentsUntil('.orgchart', '.nodes').length + 1;
      }
      // Construct the node
      var childrenData = data.children;
      var hasChildren = childrenData ? childrenData.length : false;
      var $nodeWrapper;
      if (Object.keys(data).length > 2) {
        var $nodeDiv = this.createNode(data);
        if (opts.verticalLevel && level >= opts.verticalLevel) {
          $appendTo.append($nodeDiv);
        }else {
          $nodeWrapper = $('<table>');
          $appendTo.append($nodeWrapper.append($('<tr/>').append($('<td' + (hasChildren ? ' colspan="' + childrenData.length * 2 + '"' : '') + '></td>').append($nodeDiv))));
        }
      }
      // Construct the lower level(two "connectiong lines" rows and "inferior nodes" row)
      if (hasChildren) {
        var isHidden = (level + 1 > opts.visibleLevel || data.collapsed) ? ' hidden' : '';
        var isVerticalLayer = (opts.verticalLevel && (level + 1) >= opts.verticalLevel) ? true : false;
        var $nodesLayer;
        if (isVerticalLayer) {
          $nodesLayer = $('<ul>');
          if (isHidden && level + 1 > opts.verticalLevel) {
            $nodesLayer.addClass(isHidden);
          }
          if (level + 1 === opts.verticalLevel) {
            $appendTo.children('table').append('<tr class="verticalNodes' + isHidden + '"><td></td></tr>')
              .find('.verticalNodes').children().append($nodesLayer);
          } else {
            $appendTo.append($nodesLayer);
          }
        } else {
          var $upperLines = $('<tr class="lines' + isHidden + '"><td colspan="' + childrenData.length * 2 + '"><div class="downLine"></div></td></tr>');
          var lowerLines = '<tr class="lines' + isHidden + '"><td class="rightLine"></td>';
          for (var i=1; i<childrenData.length; i++) {
            lowerLines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
          }
          lowerLines += '<td class="leftLine"></td></tr>';
          $nodesLayer = $('<tr class="nodes' + isHidden + '">');
          if (Object.keys(data).length === 2) {
            $appendTo.append($upperLines).append(lowerLines).append($nodesLayer);
          } else {
            $nodeWrapper.append($upperLines).append(lowerLines).append($nodesLayer);
          }
        }
        // recurse through children nodes
        $.each(childrenData, function () {
          var $nodeCell = isVerticalLayer ? $('<li>') : $('<td colspan="2">');
          $nodesLayer.append($nodeCell);
          this.level = level + 1;
          that.buildHierarchy($nodeCell, this);
        });
      }
    }
function ($appendTo, data) {
      var that = this;
      var opts = this.options;
      var level = 0;
      if (data.level) {
        level = data.level;
      } else {
        level = data.level = $appendTo.parentsUntil('.orgchart', '.nodes').length + 1;
      }
      // Construct the node
      var childrenData = data.children;
      var hasChildren = childrenData ? childrenData.length : false;
      var $nodeWrapper;
      if (Object.keys(data).length > 2) {
        var $nodeDiv = this.createNode(data);
        if (opts.verticalLevel && level >= opts.verticalLevel) {
          $appendTo.append($nodeDiv);
        }else {
          $nodeWrapper = $('<table>');
          $appendTo.append($nodeWrapper.append($('<tr/>').append($('<td' + (hasChildren ? ' colspan="' + childrenData.length * 2 + '"' : '') + '></td>').append($nodeDiv))));
        }
      }
      // Construct the lower level(two "connectiong lines" rows and "inferior nodes" row)
      if (hasChildren) {
        var isHidden = (level + 1 > opts.visibleLevel || data.collapsed) ? ' hidden' : '';
        var isVerticalLayer = (opts.verticalLevel && (level + 1) >= opts.verticalLevel) ? true : false;
        var $nodesLayer;
        if (isVerticalLayer) {
          $nodesLayer = $('<ul>');
          if (isHidden && level + 1 > opts.verticalLevel) {
            $nodesLayer.addClass(isHidden);
          }
          if (level + 1 === opts.verticalLevel) {
            $appendTo.children('table').append('<tr class="verticalNodes' + isHidden + '"><td></td></tr>')
              .find('.verticalNodes').children().append($nodesLayer);
          } else {
            $appendTo.append($nodesLayer);
          }
        } else {
          var $upperLines = $('<tr class="lines' + isHidden + '"><td colspan="' + childrenData.length * 2 + '"><div class="downLine"></div></td></tr>');
          var lowerLines = '<tr class="lines' + isHidden + '"><td class="rightLine"></td>';
          for (var i=1; i<childrenData.length; i++) {
            lowerLines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>';
          }
          lowerLines += '<td class="leftLine"></td></tr>';
          $nodesLayer = $('<tr class="nodes' + isHidden + '">');
          if (Object.keys(data).length === 2) {
            $appendTo.append($upperLines).append(lowerLines).append($nodesLayer);
          } else {
            $nodeWrapper.append($upperLines).append(lowerLines).append($nodesLayer);
          }
        }
        // recurse through children nodes
        $.each(childrenData, function () {
          var $nodeCell = isVerticalLayer ? $('<li>') : $('<td colspan="2">');
          $nodesLayer.append($nodeCell);
          this.level = level + 1;
          that.buildHierarchy($nodeCell, this);
        });
      }
    }
function ( $appendTo , data ) { var that = this ; var opts = this . options ; var level = 0 ; if ( data . level ) { level = data . level ; } else { level = data . level = $appendTo . parentsUntil ( '.orgchart' , '.nodes' ) . length + 1 ; } // Construct the node var childrenData = data . children ; var hasChildren = childrenData ? childrenData . length : false ; var $nodeWrapper ; if ( Object . keys ( data ) . length > 2 ) { var $nodeDiv = this . createNode ( data ) ; if ( opts . verticalLevel && level >= opts . verticalLevel ) { $appendTo . append ( $nodeDiv ) ; } else { $nodeWrapper = $ ( '<table>' ) ; $appendTo . append ( $nodeWrapper . append ( $ ( '<tr/>' ) . append ( $ ( '<td' + ( hasChildren ? ' colspan="' + childrenData . length * 2 + '"' : '' ) + '></td>' ) . append ( $nodeDiv ) ) ) ) ; } } // Construct the lower level(two "connectiong lines" rows and "inferior nodes" row) if ( hasChildren ) { var isHidden = ( level + 1 > opts . visibleLevel || data . collapsed ) ? ' hidden' : '' ; var isVerticalLayer = ( opts . verticalLevel && ( level + 1 ) >= opts . verticalLevel ) ? true : false ; var $nodesLayer ; if ( isVerticalLayer ) { $nodesLayer = $ ( '<ul>' ) ; if ( isHidden && level + 1 > opts . verticalLevel ) { $nodesLayer . addClass ( isHidden ) ; } if ( level + 1 === opts . verticalLevel ) { $appendTo . children ( 'table' ) . append ( '<tr class="verticalNodes' + isHidden + '"><td></td></tr>' ) . find ( '.verticalNodes' ) . children ( ) . append ( $nodesLayer ) ; } else { $appendTo . append ( $nodesLayer ) ; } } else { var $upperLines = $ ( '<tr class="lines' + isHidden + '"><td colspan="' + childrenData . length * 2 + '"><div class="downLine"></div></td></tr>' ) ; var lowerLines = '<tr class="lines' + isHidden + '"><td class="rightLine"></td>' ; for ( var i = 1 ; i < childrenData . length ; i ++ ) { lowerLines += '<td class="leftLine topLine"></td><td class="rightLine topLine"></td>' ; } lowerLines += '<td class="leftLine"></td></tr>' ; $nodesLayer = $ ( '<tr class="nodes' + isHidden + '">' ) ; if ( Object . keys ( data ) . length === 2 ) { $appendTo . append ( $upperLines ) . append ( lowerLines ) . append ( $nodesLayer ) ; } else { $nodeWrapper . append ( $upperLines ) . append ( lowerLines ) . append ( $nodesLayer ) ; } } // recurse through children nodes $ . each ( childrenData , function ( ) { var $nodeCell = isVerticalLayer ? $ ( '<li>' ) : $ ( '<td colspan="2">' ) ; $nodesLayer . append ( $nodeCell ) ; this . level = level + 1 ; that . buildHierarchy ( $nodeCell , this ) ; } ) ; } }
recursively build the tree
recursively build the tree