prepare(); $tpl->assign("self", "$self $meta_designator"); // Do a Depth-First search of the GridTree graph // to visualize the graph in an HTML table. // Algorithm from CLR, Ch. 23. In this implementation, // no color means "white", and we keep a parent pointer. $gridtable=""; $color = array(); // A copy of our grid stack to use here. $treegridstack = $gridstack; // Take ourself off the end of the stack. array_pop($treegridstack); function DFSvisit ($u, $parent) { global $gridtree, $color, $gridtable, $self, $allgrids; global $clusters, $get_metric_string, $tree, $treegridstack; $color[$u] = "grey"; $gridtable .= "\n"; if ($u==$tree) $extrastyle="STYLE=\"border: thin solid rgb(47,47,47);\""; if ($u==$self) { $style="self"; $url="./?$get_metric_string"; } else if ($allgrids[$u]) { $style="grid"; // Keeping track of all parents along a path. $treegridstack[] = $parent ."@". $allgrids[$parent][AUTHORITY]; $GridstackURL = rawurlencode(join(">", $treegridstack)); $url = $allgrids[$u][AUTHORITY] . "?gw=fwd&gs=$GridstackURL"; } if ($n=count($gridtree[$u])) { // We are a grid, start a new table. $gridtable .= ""; $gridtable .= ""; foreach ($gridtree[$u] as $v) { if (!$color[$v]) { DFSvisit($v, $u); } } // Popping up a level. array_pop($treegridstack); $gridtable .= "
"; $gridtable .= "$u
\n"; } else { // No children, this is a cluster. if ($clusters[$u]) { $url = "./?c=". rawurlencode($u) ."&$get_metric_string"; $gridtable .= "$u"; } else $gridtable .= "$u"; } $gridtable .= ""; $color[$u] = "black"; } // Publish past grids in our stack. if (count($treegridstack)) { $tpl->newBlock("parentgrid"); $parentgridtable = ""; $parentgridstack = array(); foreach ($treegridstack as $g) { list($name, $link) = explode("@", $g); $parentgridstack[] = $g; $GridstackURL = rawurlencode(join(">", $parentgridstack)); $parentgridtable .= "". "$name\n"; } $tpl->assign("grids", $parentgridtable); $tpl->gotoBlock("_ROOT"); } // Publish our children using a Depth-First search of our Gridtree graph. DFSvisit($self, ""); $tpl->assign("gridtable", $gridtable); // A printout of our adjacency-list formatted graph. # $graph=""; # foreach ($gridtree as $v => $list) { # if (!$list) continue; # $graph .= "$v: "; # # foreach ($list as $n) { # $graph .= "$n "; # } # $graph .= "
\n"; # } # $tpl->assign("_ROOT.graph", $graph); $tpl->printToScreen(); ?>