From 4ebb65079821f062c45d73ac854e845e2071aa84 Mon Sep 17 00:00:00 2001 From: naturalneuralnet Date: Sat, 11 Nov 2023 20:54:43 +0000 Subject: [PATCH 1/2] adding + signs to the title corners --- .gitignore | 1 + bashplotlib/utils/helpers.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ee9a2c6..e20a0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.history *.pyc env *.txt diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index cf209ee..3de3e1d 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -80,7 +80,7 @@ def box_text(text, width, offset=0): """ Return text inside an ascii textbox """ - box = " " * offset + "-" * (width+2) + "\n" + box = " " * offset + "+" + "-" * (width) + "+" + "\n" box += " " * offset + "|" + text.center(width) + "|" + "\n" - box += " " * offset + "-" * (width+2) + box += " " * offset + "+" + "-" * (width) + "+" return box From 229f84e6232aed647c14dc8a2beaa8f4304162fe Mon Sep 17 00:00:00 2001 From: naturalneuralnet Date: Sun, 12 Nov 2023 20:01:52 +0000 Subject: [PATCH 2/2] adding text alignment option --- bashplotlib/scatterplot.py | 8 ++++---- bashplotlib/utils/helpers.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..048981d 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -28,11 +28,11 @@ def get_scale(series, is_y=False, steps=20): return scaled_series -def _plot_scatter(xs, ys, size, pch, colour, title, cs): +def _plot_scatter(xs, ys, size, pch, colour, title, cs, title_align): plotted = set() if title: - print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1))) + print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1), title_align)) print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) for y in get_scale(ys, True, size): @@ -49,7 +49,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): print(" |") print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) -def plot_scatter(f, xs, ys, size, pch, colour, title): +def plot_scatter(f, xs, ys, size, pch, colour, title, title_align): """ Form a complex number. @@ -81,7 +81,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): with open(ys) as fh: ys = [float(str(row).strip()) for row in fh] - _plot_scatter(xs, ys, size, pch, colour, title, cs) + _plot_scatter(xs, ys, size, pch, colour, title, cs, title_align) diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index 3de3e1d..de958a2 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -76,11 +76,21 @@ def abbreviate(labels, rfill=' '): return abbrev -def box_text(text, width, offset=0): +def box_text(text, width, title_align, offset=0 ): """ Return text inside an ascii textbox """ + + aligned_text = text.center(width) + if title_align == "center": + aligned_text = text.center(width) + elif title_align == "left": + aligned_text = text.ljust(width) + elif title_align == "right": + aligned_text = text.rjust(width) + + box = " " * offset + "+" + "-" * (width) + "+" + "\n" - box += " " * offset + "|" + text.center(width) + "|" + "\n" + box += " " * offset + "|" + aligned_text + "|" + "\n" box += " " * offset + "+" + "-" * (width) + "+" return box