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

Use Unicode-art for the tree display. #83

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

ezio-melotti
Copy link
Collaborator

@ezio-melotti ezio-melotti commented Aug 3, 2022

This PR is a proof of concept that updates the Branch.display_viz() method to use Unicode-art instead of ASCII-art.

This is an example of the new representation:

                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────┤+├────╮           ╭────┤+├────╮                  
     b           b           c           a           

Or as a screenshot from my terminal:
image

I also played around with a few different representations:

  1. without rounded corners and nothing around the operator:
      ┌───────────────────────*─────┐                        
      a                       ┌─────*─────────────────┐      
                  ┌───────────-─────┐                 a      
                  b           ┌─────-─────┐                  
                              a           a     
    
  2. with rounded corners and nothing around the operator:
                    ╭─────────/───────────────────╮          
               ╭────*──────────────╮         ╭────+────╮     
     ╭─────────-────╮              c         c         b     
     a         ╭────/────╮                                   
               a         c   
    
    
  3. with rounded corners and [ ] around the operators:
                         ╭───[+]───────────────────────╮     
     ╭──────────────────[-]───╮                        c     
     b              ╭────────[+]────────╮                    
               ╭───[-]───╮         ╭───[-]───╮               
               b         c         a         c  
    
  4. with rounded corners and ┤ ├ around the operators (the proposed one, shown at the top).

TODO:

  • decide which representation to adopt
  • fix tests accordingly
  • possibly add a unicode=True arg

There are also a few items that don't seem directly related to this PR, but should be fixed in a separate PR:

  • fix some alignment issues
  • handle functions/operators with len > 1
  • handle deep tree

@ezio-melotti ezio-melotti marked this pull request as draft August 4, 2022 00:32
@kstaats
Copy link
Owner

kstaats commented Aug 4, 2022 via email

@granawkins
Copy link
Collaborator

I also like Number 4.

re: 'deep tree', I thought of adding an option to clip the display at the bottom and/or top, to guarantee readability. There are some details to work out, but here's an idea:

                        (+3 hidden)
                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────┤+├────╮           ╭────┤+├────╮                  
     b           b          |+|         |-|
                        (+4 hidden)  (+2 hidden)       

Another useful feature would be to highlight one node, or a node + all nodes below it. I'm close to adding click for my work on the interactive mode, which I'm sure we can co-opt for this.

@ezio-melotti
Copy link
Collaborator Author

Another useful feature would be to highlight one node, or a node + all nodes below it.

Unicode provides a range of characters that can be used for that, e.g. this could be used to highlight the bottom-left operator:

                       ╭────┤+├──────────────────────╮      
           ╭──────────┤+├──────────╮                 b      
     ╭────╢+╟────╮           ╭────┤+├────╮                  
     b           b           c           a   

There are also double lines, but not for rounded corners.

We could also make it fancier:
image
however this is more complicated to achieve and takes 2x many lines compared to the other version:
image

@kstaats
Copy link
Owner

kstaats commented Oct 11, 2022 via email

@ezio-melotti
Copy link
Collaborator Author

Yes, this is the last item in the checklist in my first message -- this PR was mostly a proof of concept.
We discussed a different tree-style representation for larger sets too. I can go back to this before the release of 3.0 and implement both.

@granawkins
Copy link
Collaborator

For Karoo 3.0:

  • left right: one-line, indented layout, like a directory (default)
  • top down: hierarchical, leave as is

Future updates:

  • Unicode
  • Vector art (graphviz)
  • highlighting
  • Clip above/below depth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants