kroitor / asciichart

Nice-looking lightweight console ASCII line charts ╭┈╯ for NodeJS, browsers and terminal, no dependencies
MIT License
1.87k stars 94 forks source link

Add a title option in the Python version. #27

Open neighthan opened 5 years ago

neighthan commented 5 years ago

This updates the Python plot command and the pplot script with an additional title argument. If given, the title is the first line of the plot string and is centered over the non-axis region of the plot (unless it's too long, then it starts just after the y-axis ends). If no title is given, the behavior is the same as right now.

Example:

$ pplot 1 10 5 3 9 7 10 0.1 --title "Title"
            Title
   10.00  ┼╭╮   ╭╮ 
    8.90  ┤││ ╭╮││ 
    7.80  ┤││ ││││ 
    6.70  ┤││ │╰╯│ 
    5.60  ┤││ │  │ 
    4.50  ┤│╰╮│  │ 
    3.40  ┤│ ╰╯  │ 
    2.30  ┤│     │ 
    1.20  ┤╯     │ 
    0.10  ┼      ╰ 

Note: if there is a title, I decrease the height allotted for the rest of the plot by 1. This means that the rest of the plot will look a little different (the axis values change; see an example below). If you'd prefer, we could leave the height the same and just note (e.g. in the doc string) that a plot with a title will have a height that is 1 larger.

$ pplot 1 10 5 3 9 7 10 0.1
   10.00  ┼╭╮   ╭╮ 
    9.01  ┤││ ╭╮││ 
    8.02  ┤││ ││││ 
    7.03  ┤││ │╰╯│ 
    6.04  ┤││ │  │ 
    5.05  ┤│╰╮│  │ 
    4.06  ┤│ ││  │ 
    3.07  ┤│ ╰╯  │ 
    2.08  ┤│     │ 
    1.09  ┼╯     │ 
    0.10  ┤      ╰ 
coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 240ce86c8600e82d2d9e6313d2eacaab2a93e8d4 on neighthan:add_title into 714e0570022fdeeed910875bf374b951c1388cef on kroitor:master.

kroitor commented 5 years ago

Will merge shortly!