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

Stacked width inconsistent #83

Open
mbforbes opened this issue Jun 9, 2021 · 2 comments
Open

Stacked width inconsistent #83

mbforbes opened this issue Jun 9, 2021 · 2 comments

Comments

@mbforbes
Copy link

mbforbes commented Jun 9, 2021

Hi there,

Thank you very much for providing this library!

I'm attempting to use it to print a live indicator as a debugging aid. (I'm charting how much GPU memory is used vs free). I'm setting width=60 on every call. However, the total bar width changes when the data changes!

image

I'm wondering if the issue is with normalization not accounting for stacked charts?

In case it helps, here's how I'm calling it:

from collections import defaultdict
import time

from gpustat import core as gpus
from termgraph import termgraph


C = termgraph.AVAILABLE_COLORS


while True:
    # Settings
    gpu_idx = 7  # TODO: cmd line

    info = gpus.new_query()
    gpu = info[gpu_idx]

    termgraph.chart(
        colors=[C["red"], C["yellow"]],
        data=[[gpu.memory_used, gpu.memory_free]],
        args=defaultdict(
            bool,
            {
                "stacked": True,
                "width": 60,
                "format": "{:<5.2f}",
                "no_labels": True,
                "suffix": f" (used: {gpu.memory_used}, free: {gpu.memory_free})",
            },
        ),
        labels=[""],
    )

    time.sleep(1)

Many thanks for any tips, and apologies if I'm confused here!

@mkaz
Copy link
Owner

mkaz commented Sep 4, 2021

Correct it's the normalization, the width is the overall width and not necessarily what it will draw, just what it tries to fit the data in to.

I think to get consistent widths from call to call it will need a normalization factor passed in, so it treats data the same across calls.

@danielhoherd
Copy link
Contributor

danielhoherd commented Jul 29, 2024

I'm also experiencing this on the CLI. EG:

$ termgraph --version
termgraph v0.5.3
$ cat data.txt
2024-07-23T12:48:01-04:00  2.27   97.73
2024-07-23T14:48:01-04:00  9.3    90.7
2024-07-23T16:48:01-04:00  12.93  87.07
2024-07-23T18:48:01-04:00  19.72  80.28
2024-07-23T20:48:01-04:00  23.6   76.4
2024-07-23T22:48:01-04:00  29.82  70.18
2024-07-24T00:48:01-04:00  31.33  68.67
$ cat data.txt | termgraph --stacked

2024-07-23T12:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-23T14:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-23T16:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-23T18:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-23T20:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-23T22:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
2024-07-24T00:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
Screenshot 2024-07-29 at 11 01 27 AM

If I truncate the decimals, essentially turning the floats into integers, the problem goes away:

$ cat data2.txt
2024-07-23T12:48:01-04:00  2   97
2024-07-23T14:48:01-04:00  9   90
2024-07-23T16:48:01-04:00  12  87
2024-07-23T18:48:01-04:00  19  80
2024-07-23T20:48:01-04:00  23  76
2024-07-23T22:48:01-04:00  29  70
2024-07-24T00:48:01-04:00  31  68
$ cat data2.txt | termgraph --stacked

2024-07-23T12:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-23T14:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-23T16:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-23T18:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-23T20:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-23T22:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00
2024-07-24T00:48:01-04:00: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99.00

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

No branches or pull requests

3 participants