From bd1f3efd476122b5d6c79e881b6f1017c8771713 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Fri, 25 Dec 2009 19:49:22 +0000 Subject: [PATCH] Added configuration node collapse behavior. --- class.krumo.php | 131 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 35 deletions(-) diff --git a/class.krumo.php b/class.krumo.php index 7f0534a..8629e09 100755 --- a/class.krumo.php +++ b/class.krumo.php @@ -610,7 +610,7 @@ /** * Configuration array. */ - static $_config = array(); + Private Static $_config = array(); /** * Returns values from Krumo's configuration @@ -644,6 +644,47 @@ } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + + /** + * Cascade configuration array + * + * By default, all nodes are collapsed. + */ + Private Static $_cascade = array(0); + + /** + * Set a cascade configuration array. + * + * Each value in the array is the maximum number of entries that node can + * have before it is being collapsed. The last value is repeated for all + * further levels. + * + * Example: + * array(10,5,0) - Nodes from the first level are expanded if they have less + * than 10 child nodes. Nodes from the second level are ex- + * panded if they have less then 5 nodes and all lower levels + * are collapsed. + * + * @param array $cascade Cascading information + * @access public + * @static + */ + Public Static Function cascade($cascade) { + self::$_cascade = $cascade; + } + + /** + * Determines if a given node will be collapsed or not. + */ + Private Static Function _isCollapsed($level, $childCount) { + if (isset(self::$_cascade[$level])) { + return $childCount > self::$_cascade[$level]; + } else { + return $childCount > end(self::$_cascade); + } + } + + // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Print the skin (CSS) @@ -922,6 +963,11 @@ } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + + /** + * Level of recursion. + */ + Private Static $_level = 0; /** * Render a dump for the properties of an array or objeect @@ -954,41 +1000,48 @@ krumo::_hive($data); // render it - // + // + $collapsed = krumo::_isCollapsed(self::$_level, count($data)-1); ?> -