mkaz / termgraph

a python command-line tool which draws basic graphs in the terminal
MIT License
3.14k stars 165 forks source link

Feature request: provide a static scale option #108

Open danielhoherd opened 1 year ago

danielhoherd commented 1 year ago

Description

I would love to see a feature that lets the user specify a scale to use, rather than setting the max width.

Use cases

If a user does something like:

while sleep 1m ; do
  fetch-widely-variable-data | termgraph
done

The produced graph is always scaled to the max width no matter what the values are. For instance, on one run it might be:

▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 26
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 37
▇▇▇▇▇▇▇▇ 6

But later on it may be:

▇▇▇▇▇▇ 12
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 70
▇▇▇ 6

The numbers show the difference, but the horizontal line is the same length because the scale of units to ticks is different, which makes the data change over time difficult to visually parse at a glance.

Proposed solution

Implement a --scale option that allows the user to specify how many units should be represented in 1 tick. For instance --scale=4 could mean that the numbers 1-4 are always represented by , 5-8 as ▇▇, and so on.

The --scale=4 example here may not be the best that we can come up with, but is one possible solution.