@@ -59,7 +59,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
5959 Args:
6060 val: The value to center
6161 unitSize: The total width of the output string (uses DEFAULT_UNIT_SIZE if None)
62- fillChar: The character to use for padding (uses DEFAULT_FILL_CHAR if None)
62+ fillChar: The character to use for padding (uses DEFAULT_FILL_CHAR "_" if None)
6363
6464 Returns:
6565 A centered string representation of val
@@ -78,7 +78,7 @@ <h2 id="args">Args</h2>
7878< dt > < strong > < code > unitSize</ code > </ strong > </ dt >
7979< dd > The total width of the output string (uses DEFAULT_UNIT_SIZE if None)</ dd >
8080< dt > < strong > < code > fillChar</ code > </ strong > </ dt >
81- < dd > The character to use for padding (uses DEFAULT_FILL_CHAR if None)</ dd >
81+ < dd > The character to use for padding (uses DEFAULT_FILL_CHAR "_" if None)</ dd >
8282</ dl >
8383< h2 id ="returns "> Returns</ h2 >
8484< p > A centered string representation of val</ p > </ div >
@@ -115,14 +115,14 @@ <h2 id="returns">Returns</h2>
115115< p > The depth of the tree (number of levels from root to deepest leaf)</ p > </ div >
116116</ dd >
117117< dt id ="printBin.nodeToMat "> < code class ="name flex ">
118- < span > def < span class ="ident "> nodeToMat</ span > </ span > (< span > node: < a title ="printBin.BinaryNode " href ="#printBin.BinaryNode "> BinaryNode</ a > ,< br > depth=-1,< br > fillChar=None,< br > unitSize=None,< br > removeEmpty=True)</ span >
118+ < span > def < span class ="ident "> nodeToMat</ span > </ span > (< span > node: < a title ="printBin.BinaryNode " href ="#printBin.BinaryNode "> BinaryNode</ a > ,< br > depth=-1,< br > fillChar=None,< br > emptyFillChar=None, < br > unitSize=None,< br > removeEmpty=True)</ span >
119119</ code > </ dt >
120120< dd >
121121< details class ="source ">
122122< summary >
123123< span > Expand source code</ span >
124124</ summary >
125- < pre > < code class ="python "> def nodeToMat(node: BinaryNode, depth=-1, fillChar=None, unitSize=None, removeEmpty=True):
125+ < pre > < code class ="python "> def nodeToMat(node: BinaryNode, depth=-1, fillChar=None, emptyFillChar=None, unitSize=None, removeEmpty=True):
126126 """
127127 Converts a binary tree into a 2D matrix representation for visualization.
128128
@@ -133,7 +133,8 @@ <h2 id="returns">Returns</h2>
133133 Args:
134134 node: The root node of the tree to visualize
135135 depth: The depth of the tree (-1 for auto-calculation)
136- fillChar: Character for padding (uses DEFAULT_FILL_CHAR if None)
136+ fillChar: Character for padding node values (uses DEFAULT_FILL_CHAR "_" if None)
137+ emptyFillChar: Character for empty cells within valueIndexes (uses DEFAULT_EMPTY_FILL_CHAR "_" if None)
137138 unitSize: Size for centering (uses DEFAULT_UNIT_SIZE if None)
138139 removeEmpty: Whether to remove empty leading columns
139140
@@ -144,6 +145,8 @@ <h2 id="returns">Returns</h2>
144145 unitSize = DEFAULT_UNIT_SIZE
145146 if fillChar is None:
146147 fillChar = DEFAULT_FILL_CHAR
148+ if emptyFillChar is None:
149+ emptyFillChar = DEFAULT_EMPTY_FILL_CHAR
147150
148151 if depth == -1:
149152 depth = getDepth(node)
@@ -152,7 +155,8 @@ <h2 id="returns">Returns</h2>
152155 tree = register(node, fillChar=fillChar, unitSize=unitSize, code="", mem={})
153156
154157 # Create matrix: (2*depth - 1) rows x (2^depth - 1) columns
155- mat = [[center("", unitSize=unitSize, fillChar=fillChar) for _ in range(2 ** depth - 1)] for _ in range(2 * depth - 1)]
158+ # Initialize with space-centered empty cells
159+ mat = [[center("", unitSize=unitSize, fillChar=" ") for _ in range(2 ** depth - 1)] for _ in range(2 * depth - 1)]
156160
157161 # Start with all even column indices (where values can be placed)
158162 valueIndexes = [i for i in range(2 ** depth - 1) if i % 2 == 0]
@@ -162,7 +166,7 @@ <h2 id="returns">Returns</h2>
162166 # Odd levels: place connection characters (/ and \)
163167 if level % 2 != 0:
164168 for i, index in enumerate(valueIndexes):
165- mat[level][index] = [center("/", unitSize=unitSize, fillChar=fillChar ), center("\\", unitSize=unitSize, fillChar=fillChar )][i % 2]
169+ mat[level][index] = [center("/", unitSize=unitSize, fillChar=" " ), center("\\", unitSize=unitSize, fillChar=" " )][i % 2]
166170
167171 # Calculate parent positions (midpoints between child pairs)
168172 newIndexes = []
@@ -177,18 +181,19 @@ <h2 id="returns">Returns</h2>
177181 codes = ["".join(code) for code in codes]
178182
179183 for i, index in enumerate(valueIndexes):
180- mat[level][index] = tree.get(codes[i], center("", unitSize=unitSize, fillChar=fillChar ))
184+ mat[level][index] = tree.get(codes[i], center("", unitSize=unitSize, fillChar=emptyFillChar ))
181185
182186 # Remove empty leading columns if requested
183187 if removeEmpty:
188+ centeredSpace = center("", unitSize=unitSize, fillChar=" ")
189+ centeredSlash = center("/", unitSize=unitSize, fillChar=" ")
190+ centeredBackslash = center("\\", unitSize=unitSize, fillChar=" ")
191+
184192 for i in range(2 ** depth - 1):
185193 remove = False
186194 if all(
187- mat[j][i] in [
188- center("", unitSize=unitSize, fillChar=fillChar),
189- center("/", unitSize=unitSize, fillChar=fillChar),
190- center("\\", unitSize=unitSize, fillChar=fillChar)
191- ] for j in range(2 * depth - 1)
195+ mat[j][i] in [centeredSpace, centeredSlash, centeredBackslash]
196+ for j in range(2 * depth - 1)
192197 ):
193198 remove = True
194199 if not remove:
@@ -209,7 +214,9 @@ <h2 id="args">Args</h2>
209214< dt > < strong > < code > depth</ code > </ strong > </ dt >
210215< dd > The depth of the tree (-1 for auto-calculation)</ dd >
211216< dt > < strong > < code > fillChar</ code > </ strong > </ dt >
212- < dd > Character for padding (uses DEFAULT_FILL_CHAR if None)</ dd >
217+ < dd > Character for padding node values (uses DEFAULT_FILL_CHAR "_" if None)</ dd >
218+ < dt > < strong > < code > emptyFillChar</ code > </ strong > </ dt >
219+ < dd > Character for empty cells within valueIndexes (uses DEFAULT_EMPTY_FILL_CHAR "_" if None)</ dd >
213220< dt > < strong > < code > unitSize</ code > </ strong > </ dt >
214221< dd > Size for centering (uses DEFAULT_UNIT_SIZE if None)</ dd >
215222< dt > < strong > < code > removeEmpty</ code > </ strong > </ dt >
@@ -219,28 +226,29 @@ <h2 id="returns">Returns</h2>
219226< p > A 2D list (matrix) representing the tree structure</ p > </ div >
220227</ dd >
221228< dt id ="printBin.nodeToString "> < code class ="name flex ">
222- < span > def < span class ="ident "> nodeToString</ span > </ span > (< span > node: < a title ="printBin.BinaryNode " href ="#printBin.BinaryNode "> BinaryNode</ a > ,< br > depth=-1,< br > fillChar=None,< br > unitSize=None,< br > removeEmpty=True)</ span >
229+ < span > def < span class ="ident "> nodeToString</ span > </ span > (< span > node: < a title ="printBin.BinaryNode " href ="#printBin.BinaryNode "> BinaryNode</ a > ,< br > depth=-1,< br > fillChar=None,< br > emptyFillChar=None, < br > unitSize=None,< br > removeEmpty=True)</ span >
223230</ code > </ dt >
224231< dd >
225232< details class ="source ">
226233< summary >
227234< span > Expand source code</ span >
228235</ summary >
229- < pre > < code class ="python "> def nodeToString(node: BinaryNode, depth=-1, fillChar=None, unitSize=None, removeEmpty=True):
236+ < pre > < code class ="python "> def nodeToString(node: BinaryNode, depth=-1, fillChar=None, emptyFillChar=None, unitSize=None, removeEmpty=True):
230237 """
231238 Converts a binary tree into a string representation for visualization.
232239
233240 Args:
234241 node: The root node of the tree to visualize
235242 depth: The depth of the tree (-1 for auto-calculation)
236- fillChar: Character for padding (uses DEFAULT_FILL_CHAR if None)
243+ fillChar: Character for padding node values (uses DEFAULT_FILL_CHAR if None)
244+ emptyFillChar: Character for empty cells within valueIndexes (uses DEFAULT_EMPTY_FILL_CHAR if None)
237245 unitSize: Size for centering (uses DEFAULT_UNIT_SIZE if None)
238246 removeEmpty: Whether to remove empty leading columns
239247
240248 Returns:
241249 A string representation of the tree with each row on a new line
242250 """
243- mat = nodeToMat(node, depth=depth, fillChar=fillChar, unitSize=unitSize, removeEmpty=removeEmpty)
251+ mat = nodeToMat(node, depth=depth, fillChar=fillChar, emptyFillChar=emptyFillChar, unitSize=unitSize, removeEmpty=removeEmpty)
244252 return "\n".join("".join(row) for row in mat)</ code > </ pre >
245253</ details >
246254< div class ="desc "> < p > Converts a binary tree into a string representation for visualization.</ p >
@@ -251,7 +259,9 @@ <h2 id="args">Args</h2>
251259< dt > < strong > < code > depth</ code > </ strong > </ dt >
252260< dd > The depth of the tree (-1 for auto-calculation)</ dd >
253261< dt > < strong > < code > fillChar</ code > </ strong > </ dt >
254- < dd > Character for padding (uses DEFAULT_FILL_CHAR if None)</ dd >
262+ < dd > Character for padding node values (uses DEFAULT_FILL_CHAR if None)</ dd >
263+ < dt > < strong > < code > emptyFillChar</ code > </ strong > </ dt >
264+ < dd > Character for empty cells within valueIndexes (uses DEFAULT_EMPTY_FILL_CHAR if None)</ dd >
255265< dt > < strong > < code > unitSize</ code > </ strong > </ dt >
256266< dd > Size for centering (uses DEFAULT_UNIT_SIZE if None)</ dd >
257267< dt > < strong > < code > removeEmpty</ code > </ strong > </ dt >
@@ -279,7 +289,7 @@ <h2 id="returns">Returns</h2>
279289
280290 Args:
281291 node: The current node being processed
282- fillChar: Character used for padding (uses DEFAULT_FILL_CHAR if None)
292+ fillChar: Character used for padding node values (uses DEFAULT_FILL_CHAR "_" if None)
283293 unitSize: Size for centering values (uses DEFAULT_UNIT_SIZE if None)
284294 code: The binary path code for the current node
285295 mem: Dictionary mapping binary codes to centered node values
@@ -302,7 +312,7 @@ <h2 id="args">Args</h2>
302312< dt > < strong > < code > node</ code > </ strong > </ dt >
303313< dd > The current node being processed</ dd >
304314< dt > < strong > < code > fillChar</ code > </ strong > </ dt >
305- < dd > Character used for padding (uses DEFAULT_FILL_CHAR if None)</ dd >
315+ < dd > Character used for padding node values (uses DEFAULT_FILL_CHAR "_" if None)</ dd >
306316< dt > < strong > < code > unitSize</ code > </ strong > </ dt >
307317< dd > Size for centering values (uses DEFAULT_UNIT_SIZE if None)</ dd >
308318< dt > < strong > < code > code</ code > </ strong > </ dt >
0 commit comments