Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress branches #8

Open
T3sT3ro opened this issue Nov 12, 2022 · 1 comment
Open

Compress branches #8

T3sT3ro opened this issue Nov 12, 2022 · 1 comment
Assignees

Comments

@T3sT3ro
Copy link

T3sT3ro commented Nov 12, 2022

Take a look at https://github.com/billvanyo/tree_printer.

It is capable of using as much space as possible - child branches can overflow under sibling parent branches, which makes the tree look a lot more compact. Something like that would be nice to have

Another nice feature would be to compress row spacing to compress rows:

                    1                
                    └┐               <-- one row for branches instead of 2 
                     20              
               ┌─────┴─────┐         
               15          24        
           ┌───┴───┐   ┌───┴───┐     
           10      19  21      27    
        ┌──┴──┐   ┌┘   └┐    ┌─┴─┐   
        7     12  16    22   26  29  
      ┌─┴─┐ ┌─┴─┐ └┐    └┐  ┌┘ ┌─┴─┐ 
      5   8 11  14 18    23 25 28  30
     ┌┴┐  └┐   ┌┘ ┌┘                 
     4 6   9   13 17                 
    ┌┘                               
    2                                
    └┐                               
     3                 

ALSO when I pulled and debugged your lib, I saw there are a lot of writes and changes to the LineBuffer, as well as methods that return encoded values (like array of 2 elements encoding properties like position and width — maybe use records or classes with meaningful fields for them?). Maybe it would be possible to avoid changes like that if you had a dynamic list elements per row (like pad, branch, node, branch, pad) which is rewritten in some kind of two-pass bottom-up + top-down fashion?

@davidsusu
Copy link
Owner

Thank you for your request. I once planned to implement a compact binary tree printer and some compactness options for TraditionalTreePrinter.

It's a serious difficulty that each node's content can have different heights and insets (multiline nodes are first-class citizens). I wouldn't be surprised if this is a computationally hard problem (in any case, a weighted MAX-SAT solver could still help).

I'll think about it some more, so I will leave this open for now.

@davidsusu davidsusu self-assigned this Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants