Skip to content

Commit

Permalink
added version 5.2.6: solved issue 127 about multiple lines in text()
Browse files Browse the repository at this point in the history
  • Loading branch information
piccolomo committed Sep 24, 2022
1 parent cdba5d5 commit 001d71e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion plotext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""\nplotext plots directly on terminal"""

__name__ = "plotext"
__version__ = "5.2.5"
__version__ = "5.2.6"

from ._core import *
from .plotext_cli import build_parser
4 changes: 2 additions & 2 deletions plotext/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def build_plot(self): # it builds the plot given the external settings and inter
[self.matrix.add_horizontal_string(col_start + S + 3, row_end - 1 - s, labels[s], self.ticks_color, self.ticks_style) for s in range(l)] if legend_test else None

# Add Text to Canvas
[self.matrix.add_horizontal_string(col_start + tcticks[s], row_start + trticks[s], self.text[s], self.tfull[s], self.tstyle[s], self.tback[s], self.talign[s], False, True) for s in Texts if self.torien[s] is self.default.orientation[0]]
[self.matrix.add_vertical_string(col_start + tcticks[s], row_start + trticks[s], self.text[s], self.tfull[s], self.tstyle[s], self.tback[s], self.talign[s], True) for s in Texts if self.torien[s] is self.default.orientation[1]]
[self.matrix.add_multiple_horizontal_strings(col_start + tcticks[s], row_start + trticks[s], self.text[s], self.tfull[s], self.tstyle[s], self.tback[s], self.talign[s], False, True) for s in Texts if self.torien[s] is self.default.orientation[0]]
[self.matrix.add_multiple_vertical_strings(col_start + tcticks[s], row_start + trticks[s], self.text[s], self.tfull[s], self.tstyle[s], self.tback[s], self.talign[s], True) for s in Texts if self.torien[s] is self.default.orientation[1]]



Expand Down
4 changes: 3 additions & 1 deletion plotext/_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@
\x1b[96morientation\x1b[0m sets the orientation of the text and could be either 'vertical' (in short 'v', as by default) or 'horizontal' (in short 'h').
\x1b[96malignment\x1b[0m sets the text horizontal / vertical alignment to either 'left', 'center', and 'right' or 'top', 'center' and 'bottom'."""
\x1b[96malignment\x1b[0m sets the text horizontal / vertical alignment to either 'left', 'center', and 'right' or 'top', 'center' and 'bottom' ('left' and 'top' by default).
Note that the new line character \\n is allowed: multiple sub strings will be printed in sequence with same alignment."""
text = lambda: print(_text)

_rectangle = """It creates a rectangle with coordinates given by x and y, each being a list of length 2. As the scatter() function, it accepts the parameters 'color', 'marker', 'xside', 'yside', and 'label', with the following extra parameters:
Expand Down
35 changes: 15 additions & 20 deletions plotext/_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,27 @@ def insert_element(self, col, row, marker, fullground = None, style = None, back
self.set_fullground(col, row, fullground) if fullground is not None else None
self.set_background(col, row, background) if background is not None else None
self.set_style(col, row, style) if style is not None else None

def add_horizontal_string(self, col, row, string, fullground = None, style = None, background = None, alignment = "left", check_space = False, check_canvas = False):
strings = ''.join(string).split('\n'); S = len(strings)
for s in range(S):
string = strings[s]
l = len(string); L = range(l)
Col = col if alignment == "left" else col - l // 2 if alignment == "center" else col - l + 1 if alignment == "right" else ut.correct_coord(self.get_marker_row(row), string, col) # if dynamic
b, e = max(Col - 1, 0), min(Col + l + 1, self.cols)
test_space = all([self.get_marker(c, row) == ut.space for c in range(b, e)]) and Col >= 0 and Col + l <= self.cols if check_space else True
[self.insert_element(Col + i, row - s, string[i], fullground, style, background, check_canvas) for i in L] if test_space else None
l = len(string); L = range(l)
col = col if alignment == "left" else col - l // 2 if alignment == "center" else col - l + 1 if alignment == "right" else ut.correct_coord(self.get_marker_row(row), string, col) # if dynamic
b, e = max(col - 1, 0), min(col + l + 1, self.cols)
test_space = all([self.get_marker(c, row) == ut.space for c in range(b, e)]) and col >= 0 and col + l <= self.cols if check_space else True
[self.insert_element(col + i, row, string[i], fullground, style, background, check_canvas) for i in L] if test_space else None
return test_space

def add_vertical_string(self, col, row, string, fullground = None, style = None, background = None, alignment = "bottom", check_canvas = False):
strings = ''.join(string).split('\n'); S = len(strings)
for s in range(S):
string = strings[s]
l = len(string); L = range(l)
Row = row if alignment == "bottom" else row - l // 2 if alignment == "center" else row - l + 1 #if alignment == "top"
[self.insert_element(col - s, Row + i, string[i], fullground, style, background, check_canvas) for i in L]
def add_vertical_string(self, col, row, string, fullground = None, style = None, background = None, alignment = "bottom", check_canvas = False):
l = len(string); L = range(l)
row = row if alignment == "bottom" else row - l // 2 if alignment == "center" else row - l + 1 #if alignment == "top"
[self.insert_element(col, row + i, string[i], fullground, style, background, check_canvas) for i in L]

def add_multiple_horizontal_strings(self, col, row, string, fullground = None, style = None, background = None, alignment = "left", check_space = False, check_canvas = False):
strings = ''.join(string).split('\n'); S = len(strings)
for s in range(S):
string = strings[s]
[self.add_horizonelement(Col + i, row - s, string[i], fullground, style, background, check_canvas) for i in L] if test_space else None
return test_space
[self.add_horizontal_string(col, row - s, strings[s], fullground, style, background, alignment, check_space, check_canvas) for s in range(S)]

def add_multiple_vertical_strings(self, col, row, string, fullground = None, style = None, background = None, alignment = "left", check_canvas = False):
strings = ''.join(string).split('\n'); S = len(strings)
[self.add_vertical_string(col + s, row, strings[s], fullground, style, background, alignment, check_canvas) for s in range(S)]

def get_colors(self, col, row):
return [self.fullground[row][col], self.style[row][col], self.background[row][col]] #if self.legal(col, row) else ["OUT"] * 3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
author = "Savino Piccolomo",
author_email = "[email protected]",
name = 'plotext',
version='5.2.5',
version='5.2.6',
description = 'plotext plots directly on terminal',
long_description = README,
long_description_content_type = "text/markdown",
Expand Down

0 comments on commit 001d71e

Please sign in to comment.