From d253b8e2de6a46fdde1b03b01a1f629124916e44 Mon Sep 17 00:00:00 2001 From: Yosi Angel Date: Fri, 11 Feb 2022 13:58:49 +0200 Subject: [PATCH] task 1 --- bashplotlib/scatterplot.py | 5 +++-- bashplotlib/utils/helpers.py | 14 ++++++++++++-- scratch.py | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 scratch.py diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..e77acaa 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -34,7 +34,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): if title: print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1))) - print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) + # print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) for y in get_scale(ys, True, size): print("|", end=' ') for x in get_scale(xs, False, size): @@ -47,7 +47,8 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): colour = cs[i] printcolour(point + " ", True, colour) print(" |") - print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) + # print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) + print(wrap_text_with_symbol("-" * (2 * (len(get_scale(xs, False, size)) + 1)), "+")) def plot_scatter(f, xs, ys, size, pch, colour, title): """ diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index cf209ee..f14d95c 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -80,7 +80,17 @@ def box_text(text, width, offset=0): """ Return text inside an ascii textbox """ - box = " " * offset + "-" * (width+2) + "\n" + box = " " * offset + wrap_text_with_symbol("-" * width, "+") + "\n" + # box = " " * offset + "-" * (width+2) + "\n" box += " " * offset + "|" + text.center(width) + "|" + "\n" - box += " " * offset + "-" * (width+2) + # box += " " * offset + "-" * (width+2) + box += " " * offset + wrap_text_with_symbol("-" * width, "+") return box + +def wrap_text_with_symbol(text, symbol = "+"): + """ + Returns text wrapped with symbol + default wrapper is '+' + """ + newText = symbol + text + symbol + return newText \ No newline at end of file diff --git a/scratch.py b/scratch.py new file mode 100644 index 0000000..b58d36c --- /dev/null +++ b/scratch.py @@ -0,0 +1,18 @@ +# scratch.py +from bashplotlib.scatterplot import plot_scatter + +x_coords = [-10,20,30] +y_coords = [-10,20,30] +width = 10 +char = 'x' +color = 'default' +title = 'My Test Graph' + +plot_scatter( + None, + x_coords, + y_coords, + width, + char, + color, + title) \ No newline at end of file