Skip to content

Commit 5716a74

Browse files
Merge pull request #1 from naturalneuralnet/dev-branch
adding + signs to the title corners
2 parents cded03a + 229f84e commit 5716a74

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.history
12
*.pyc
23
env
34
*.txt

bashplotlib/scatterplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def get_scale(series, is_y=False, steps=20):
2828
return scaled_series
2929

3030

31-
def _plot_scatter(xs, ys, size, pch, colour, title, cs):
31+
def _plot_scatter(xs, ys, size, pch, colour, title, cs, title_align):
3232
plotted = set()
3333

3434
if title:
35-
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)))
35+
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1), title_align))
3636

3737
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
3838
for y in get_scale(ys, True, size):
@@ -49,7 +49,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
4949
print(" |")
5050
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
5151

52-
def plot_scatter(f, xs, ys, size, pch, colour, title):
52+
def plot_scatter(f, xs, ys, size, pch, colour, title, title_align):
5353
"""
5454
Form a complex number.
5555
@@ -81,7 +81,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
8181
with open(ys) as fh:
8282
ys = [float(str(row).strip()) for row in fh]
8383

84-
_plot_scatter(xs, ys, size, pch, colour, title, cs)
84+
_plot_scatter(xs, ys, size, pch, colour, title, cs, title_align)
8585

8686

8787

bashplotlib/utils/helpers.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ def abbreviate(labels, rfill=' '):
7676
return abbrev
7777

7878

79-
def box_text(text, width, offset=0):
79+
def box_text(text, width, title_align, offset=0 ):
8080
"""
8181
Return text inside an ascii textbox
8282
"""
83-
box = " " * offset + "-" * (width+2) + "\n"
84-
box += " " * offset + "|" + text.center(width) + "|" + "\n"
85-
box += " " * offset + "-" * (width+2)
83+
84+
aligned_text = text.center(width)
85+
if title_align == "center":
86+
aligned_text = text.center(width)
87+
elif title_align == "left":
88+
aligned_text = text.ljust(width)
89+
elif title_align == "right":
90+
aligned_text = text.rjust(width)
91+
92+
93+
box = " " * offset + "+" + "-" * (width) + "+" + "\n"
94+
box += " " * offset + "|" + aligned_text + "|" + "\n"
95+
box += " " * offset + "+" + "-" * (width) + "+"
8696
return box

0 commit comments

Comments
 (0)