r2194 - improve tree verging
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 31 Aug 2008 23:45:16 +0000 (23:45 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sun, 31 Aug 2008 23:45:16 +0000 (23:45 +0000)
inc/functions.php
inc/init.php
inc/interface.php
pix/last-minus.png [new file with mode: 0644]
pix/last-plus.png [new file with mode: 0644]
pix/last-terminal.png [new file with mode: 0644]
pix/midst-minus.png [new file with mode: 0644]
pix/midst-plus.png [new file with mode: 0644]
pix/midst-terminal.png [new file with mode: 0644]
pix/verge.png [deleted file]

index a9b547b412eb276ec526c3f4ec121f4a923cbe3c..6e19b26503e05e5d7c438071ad729753c59a1c03 100644 (file)
@@ -764,31 +764,32 @@ function getAutoPorts ($type_id)
 
 // Find if a particular tag id exists on the tree, then attach the
 // given child tag to it. If the parent tag doesn't exist, return FALSE.
-function attachChildTag (&$tree, $parent_id, $child_id, $child_info)
+function attachChildTag (&$tree, $parent_id, $child_id, $child_info, $threshold = 0)
 {
+       $self = __FUNCTION__;
        foreach ($tree as $tagid => $taginfo)
        {
                if ($tagid == $parent_id)
                {
-                       $tree[$tagid]['kids'][$child_id] = $child_info;
+                       if (!$threshold or ($threshold and $tree[$tagid]['kidc'] + 1 < $threshold))
+                               $tree[$tagid]['kids'][$child_id] = $child_info;
+                       // Reset the list only once.
+                       if (++$tree[$tagid]['kidc'] == $threshold)
+                               $tree[$tagid]['kids'] = array();
                        return TRUE;
                }
-               elseif (attachChildTag ($tree[$tagid]['kids'], $parent_id, $child_id, $child_info))
+               elseif ($self ($tree[$tagid]['kids'], $parent_id, $child_id, $child_info, $threshold))
                        return TRUE;
        }
        return FALSE;
 }
 
-function getTagTree ()
-{
-       global $taglist;
-       return treeFromList ($taglist);
-}
-
 // Build a tree from the item list and return it. Input and output data is
 // indexed by item id (nested items in output are recursively stored in 'kids'
-// key, which is in turn indexed by id.
-function treeFromList ($mytaglist)
+// key, which is in turn indexed by id. Functions, which are ready to handle
+// tree collapsion/expansion themselves, may request non-zero threshold value
+// for smaller resulting tree.
+function treeFromList ($mytaglist, $threshold = 0)
 {
        $ret = array();
        while (count ($mytaglist) > 0)
@@ -796,6 +797,7 @@ function treeFromList ($mytaglist)
                $picked = FALSE;
                foreach ($mytaglist as $tagid => $taginfo)
                {
+                       $taginfo['kidc'] = 0;
                        $taginfo['kids'] = array();
                        if ($taginfo['parent_id'] == NULL)
                        {
@@ -803,7 +805,7 @@ function treeFromList ($mytaglist)
                                $picked = TRUE;
                                unset ($mytaglist[$tagid]);
                        }
-                       elseif (attachChildTag ($ret, $taginfo['parent_id'], $tagid, $taginfo))
+                       elseif (attachChildTag ($ret, $taginfo['parent_id'], $tagid, $taginfo, $threshold))
                        {
                                $picked = TRUE;
                                unset ($mytaglist[$tagid]);
@@ -863,6 +865,7 @@ function serializeTags ($chain, $baseurl = '')
 // a helper for getTagChainExpansion()
 function traceTagChain ($tree, $chain)
 {
+       $self = __FUNCTION__;
        // For each tag find its path from the root, then combine items
        // of all paths and add them to the chain, if they aren't there yet.
        $ret = array();
@@ -877,7 +880,7 @@ function traceTagChain ($tree, $chain)
                        }
                if (count ($taginfo1['kids']) > 0)
                {
-                       $subsearch = traceTagChain ($taginfo1['kids'], $chain);
+                       $subsearch = $self ($taginfo1['kids'], $chain);
                        if (count ($subsearch))
                        {
                                $hit = TRUE;
@@ -922,6 +925,7 @@ function getImplicitTags ($oldtags)
 // Minimize the chain: exclude all implicit tags and return the result.
 function getExplicitTagsOnly ($chain, $tree = NULL)
 {
+       $self = __FUNCTION__;
        global $tagtree;
        if ($tree === NULL)
                $tree = $tagtree;
@@ -930,7 +934,7 @@ function getExplicitTagsOnly ($chain, $tree = NULL)
        {
                if (isset ($taginfo['kids']))
                {
-                       $harvest = getExplicitTagsOnly ($chain, $taginfo['kids']);
+                       $harvest = $self ($chain, $taginfo['kids']);
                        if (count ($harvest) > 0)
                        {
                                $ret = array_merge ($ret, $harvest);
@@ -953,6 +957,7 @@ function getExplicitTagsOnly ($chain, $tree = NULL)
 // a list of tag structures. Same structure (tag ID list) is returned after processing.
 function complementByKids ($idlist, $tree = NULL, $getall = FALSE)
 {
+       $self = __FUNCTION__;
        global $tagtree;
        if ($tree === NULL)
                $tree = $tagtree;
@@ -970,7 +975,7 @@ function complementByKids ($idlist, $tree = NULL, $getall = FALSE)
                                break;
                        }
                if (isset ($taginfo['kids']))
-                       $ret = array_merge ($ret, complementByKids ($idlist, $taginfo['kids'], $getallkids));
+                       $ret = array_merge ($ret, $self ($idlist, $taginfo['kids'], $getallkids));
                $getallkids = FALSE;
        }
        return $ret;
@@ -1157,6 +1162,7 @@ function buildTagChainFromIds ($tagidlist)
 // (sub)tree will have refcnt leaves on every last branch.
 function getObjectiveTagTree ($tree, $realm)
 {
+       $self = __FUNCTION__;
        $ret = array();
        foreach ($tree as $taginfo)
        {
@@ -1164,7 +1170,7 @@ function getObjectiveTagTree ($tree, $realm)
                $pick = FALSE;
                if (count ($taginfo['kids']))
                {
-                       $subsearch = getObjectiveTagTree ($taginfo['kids'], $realm);
+                       $subsearch = $self ($taginfo['kids'], $realm);
                        $pick = count ($subsearch) > 0;
                }
                if (isset ($taginfo['refcnt'][$realm]))
@@ -1427,11 +1433,12 @@ function sortTree (&$tree, $sortfunc = '')
 {
        if (empty ($sortfunc))
                return;
+       $self = __FUNCTION__;
        usort ($tree, $sortfunc);
        // Don't make a mistake of directly iterating over the items of current level, because this way
        // the sorting will be performed on a _copy_ if each item, not the item itself.
        foreach (array_keys ($tree) as $tagid)
-               sortTree ($tree[$tagid]['kids'], $sortfunc);
+               $self ($tree[$tagid]['kids'], $sortfunc);
 }
 
 ?>
index 62e449f3f8da726346acdf81d773525067af4fc3..f285a1de75b04d0481e087f7b4ddeaf2af2499f5 100644 (file)
@@ -159,9 +159,8 @@ else
        $tabno = 'default';
 $op = (isset ($_REQUEST['op'])) ? $_REQUEST['op'] : '';
 
-// Order matters here.
 $taglist = getTagList();
-$tagtree = getTagTree();
+$tagtree = treeFromList ($taglist);
 sortTree ($tagtree, 'taginfoCmp');
 
 require_once 'inc/navigation.php';
index 3d77b25b0bb6745659177f3e764c761caac4c820..e4e1856b13a0bdbfe22c8712e2c44a367174086d 100644 (file)
@@ -93,10 +93,24 @@ $image['find']['height'] = 16;
 $image['spacer']['path'] = 'pix/pixel.png';
 $image['spacer']['width'] = 16;
 $image['spacer']['height'] = 16;
-$image['verge']['path'] = 'pix/pixel.png';
-//$image['verge']['path'] = 'pix/verge.png';
-$image['verge']['width'] = 16;
-$image['verge']['height'] = 16;
+$image['MP']['path'] = 'pix/midst-plus.png';
+$image['MP']['width'] = 16;
+$image['MP']['height'] = 16;
+$image['MM']['path'] = 'pix/midst-minus.png';
+$image['MM']['width'] = 16;
+$image['MM']['height'] = 16;
+$image['LP']['path'] = 'pix/last-plus.png';
+$image['LP']['width'] = 16;
+$image['LP']['height'] = 16;
+$image['LM']['path'] = 'pix/last-minus.png';
+$image['LM']['width'] = 16;
+$image['LM']['height'] = 16;
+$image['MT']['path'] = 'pix/midst-terminal.png';
+$image['MT']['width'] = 16;
+$image['MT']['height'] = 16;
+$image['LT']['path'] = 'pix/last-terminal.png';
+$image['LT']['width'] = 16;
+$image['LT']['height'] = 16;
 $image['next']['path'] = 'pix/tango-go-next.png';
 $image['next']['width'] = 32;
 $image['next']['height'] = 32;
@@ -1989,30 +2003,33 @@ function renderRackspaceHistory ()
        
 }
 
-function renderIPv4SpaceRecords ($tree, $level = 0, &$tagcache = array())
+function renderIPv4SpaceRecords ($tree, $itemc, $level = 0, &$tagcache = array())
 {
        $self = __FUNCTION__;
+       $c = 1;
        foreach ($tree as $item)
        {
                $netdata = getIPv4Network ($item['id']);
                $total = ($netdata['ip_bin'] | $netdata['mask_bin_inv']) - ($netdata['ip_bin'] & $netdata['mask_bin']) + 1;
                $used = count ($netdata['addrlist']);
                echo "<tr valign=top>";
-               printIPv4NetInfoTDs ($netdata, 'tdleft', $level);
+               $verge = ($c == $itemc ? 'L' : 'M') . ($item['kidc'] ? 'M' : 'T');
+               printIPv4NetInfoTDs ($netdata, 'tdleft', $level, $verge);
                echo "<td class=tdcenter>";
                renderProgressBar ($used/$total);
                echo "<br><small>${used}/${total}</small></td>";
                if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
                        printRoutersTD (findRouters ($netdata['addrlist']), $tagcache);
                echo "</tr>";
-               $self ($item['kids'], $level + 1, $tagcache);
+               $self ($item['kids'], $item['kidc'], $level + 1, $tagcache);
+               $c++;
        }
 }
 
 function renderIPv4Space ()
 {
        $tagfilter = getTagFilter();
-       $tree = treeFromList (getIPv4NetworkList ($tagfilter, getTFMode()));
+       $tree = treeFromList (getIPv4NetworkList ($tagfilter, getTFMode()), getConfigVar ('TREE_THRESHOLD'));
        sortTree ($tree, 'IPv4NetworkCmp');
 
        echo "<table border=0 class=objectview>\n";
@@ -2024,7 +2041,7 @@ function renderIPv4Space ()
        if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
                echo "<th>routed by</th>";
        echo "</tr>\n";
-       renderIPv4SpaceRecords ($tree);
+       renderIPv4SpaceRecords ($tree, count ($tree));
        echo "</table>\n";
        finishPortlet();
        echo '</td><td class=pcright>';
@@ -5265,7 +5282,7 @@ function printRoutersTD ($rlist, &$tagcache = array())
 }
 
 // Same as for routers, but produce two TD cells to lay the content out better.
-function printIPv4NetInfoTDs ($netinfo, $tdclass = 'tdleft', $indent = 0)
+function printIPv4NetInfoTDs ($netinfo, $tdclass = 'tdleft', $indent = 0, $verge = 'spacer')
 {
        global $root;
        $tags = loadIPv4PrefixTags ($netinfo['id']);
@@ -5273,7 +5290,7 @@ function printIPv4NetInfoTDs ($netinfo, $tdclass = 'tdleft', $indent = 0)
        for ($i = 0; $i < $indent - 1; $i++)
                printImageHREF ('spacer');
        if ($indent)
-               printImageHREF ('verge');
+               printImageHREF ($verge);
        echo "<a href='${root}?page=iprange&id=${netinfo['id']}'>${netinfo['ip']}/${netinfo['mask']}</a></td>";
        echo "<td class='${tdclass}'>" . niftyString ($netinfo['name']);
        if (count ($tags))
diff --git a/pix/last-minus.png b/pix/last-minus.png
new file mode 100644 (file)
index 0000000..450cf78
Binary files /dev/null and b/pix/last-minus.png differ
diff --git a/pix/last-plus.png b/pix/last-plus.png
new file mode 100644 (file)
index 0000000..9106d33
Binary files /dev/null and b/pix/last-plus.png differ
diff --git a/pix/last-terminal.png b/pix/last-terminal.png
new file mode 100644 (file)
index 0000000..4bd9509
Binary files /dev/null and b/pix/last-terminal.png differ
diff --git a/pix/midst-minus.png b/pix/midst-minus.png
new file mode 100644 (file)
index 0000000..0ddc543
Binary files /dev/null and b/pix/midst-minus.png differ
diff --git a/pix/midst-plus.png b/pix/midst-plus.png
new file mode 100644 (file)
index 0000000..87d4ddc
Binary files /dev/null and b/pix/midst-plus.png differ
diff --git a/pix/midst-terminal.png b/pix/midst-terminal.png
new file mode 100644 (file)
index 0000000..97196ee
Binary files /dev/null and b/pix/midst-terminal.png differ
diff --git a/pix/verge.png b/pix/verge.png
deleted file mode 100644 (file)
index d9279bc..0000000
Binary files a/pix/verge.png and /dev/null differ