Add support for graph with multiple nodes on the first level

Every nodes from the first level will be drawn without a parent
on the first line of the graph with a list like :
<ul>
  <li>First</li>
  <li>Second
    <ul>
      <li>Sublevel</li>
    </ul>
  </li>
</ul>
master
Guillaume DOTT 2013-01-18 11:07:10 +01:00
parent c8b7864250
commit 4b6a366c8e
1 changed files with 20 additions and 1 deletions

View File

@ -21,7 +21,7 @@
$this = $(this); $this = $(this);
var $container = $("<div class='" + opts.chartClass + "'/>"); var $container = $("<div class='" + opts.chartClass + "'/>");
if($this.is("ul")) { if($this.is("ul")) {
buildNode($this.find("li:first"), $container, 0, opts); buildNodes($this, $container, opts);
} }
else if($this.is("li")) { else if($this.is("li")) {
buildNode($this, $container, 0, opts); buildNode($this, $container, 0, opts);
@ -102,6 +102,25 @@
dragAndDrop: false dragAndDrop: false
}; };
function buildNodes($list, $appendTo, opts) {
var $table = $("<table cellpadding='0' cellspacing='0' border='0'/>");
var $tbody = $("<tbody/>");
// Construct the node container(s)
var $nodeRow = $("<tr/>");
$list.children("li").each(function(i, elem) {
var $td = $("<td class='node-container'/>");
$td.attr("colspan", 2);
buildNode($(elem), $td, 0, opts);
$nodeRow.append($td);
});
$tbody.append($nodeRow);
$table.append($tbody);
$appendTo.append($table);
}
var nodeCount = 0; var nodeCount = 0;
// Method that recursively builds the tree // Method that recursively builds the tree
function buildNode($node, $appendTo, level, opts) { function buildNode($node, $appendTo, level, opts) {