Skip to content

Commit

Permalink
added version 5.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
piccolomo committed Sep 24, 2022
1 parent 63125c9 commit 6c80e18
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 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.2"
__version__ = "5.2.4"

from ._core import *
from .plotext_cli import build_parser
2 changes: 1 addition & 1 deletion plotext/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def build_plot(self): # it builds the plot given the external settings and inter

# 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], False, True) for s in Texts if self.torien[s] is self.default.orientation[1]]
[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]]



Expand Down
31 changes: 22 additions & 9 deletions plotext/_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,30 @@ def insert_element(self, col, row, marker, fullground = None, style = None, back
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):
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
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
return test_space

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_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_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

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 plotext/_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def check_alignment(self, alignment = None):
default = self.default.alignment[0:-1]
default_first_letter = [el[0] for el in default]
alignment = default[default_first_letter.index(alignment)] if alignment in default_first_letter else alignment
alignment = default[1] if alignment not in default else alignment
alignment = default[0] if alignment not in default else alignment
return alignment

def _draw_image(self, image, marker = None, style = None, grayscale = False, fast = False):
Expand Down
18 changes: 9 additions & 9 deletions plotext/plotext_cli.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from plotext._utility import all_markers, colors
import argparse, sys, os
import plotext as plt
#import shtab
import shtab

# For Possible Colors and Markers Completion
# def dict_to_complete(d={}):
# return {'zsh': '((' + ' '.join(map(lambda x: str(x[0]) + '\\:' + x[1], d.items())) + '))'}
def dict_to_complete(d={}):
return {'zsh': '((' + ' '.join(map(lambda x: str(x[0]) + '\\:' + x[1], d.items())) + '))'}

# def list_to_complete(data):
# return {'zsh': '((' + ' '.join([el + '\\:' for el in data]) + '))'}
def list_to_complete(data):
return {'zsh': '((' + ' '.join([el + '\\:' for el in data]) + '))'}


def build_parser():
Expand All @@ -21,7 +21,7 @@ def build_parser():
description = "plotting directly on terminal",
epilog = examples,
formatter_class = argparse.RawDescriptionHelpFormatter)
#shtab.add_argument_to(parser, ["-s", "--print-completion"])
shtab.add_argument_to(parser, ["-s", "--print-completion"])

parser.set_defaults(type = "scatter")

Expand All @@ -33,7 +33,7 @@ def build_parser():
type = str,
metavar = "FILE",
help = "file path of the data table; if not used it will read from stdin. Use 'test' to automatically download, in your user folder, some test data/image/gif or video, depending on the function used; the file will be removed after the plot",
)#.complete = shtab.FILE
).complete = shtab.FILE

common_parser = argparse.ArgumentParser(add_help = False)

Expand Down Expand Up @@ -86,7 +86,7 @@ def build_parser():
choices = all_markers.keys(),
metavar = "marker",
help = "character or marker code identifying the data points in the plot, eg: x, braille, sd, heart, fhd; by default hd",
)#.complete = dict_to_complete(all_markers)
).complete = dict_to_complete(all_markers)

options_parser.add_argument("-c", "--color",
type = str,
Expand All @@ -95,7 +95,7 @@ def build_parser():
choices = colors,
metavar = "COLOR",
help = "color of the data points in the plot, between: " + ",".join(colors) + "; add + at the end of the color (except black and white) for clearer colors, eg: red+"
)#.complete = list_to_complete(colors)
).complete = list_to_complete(colors)

options_parser.add_argument("-t", "--title",
nargs = 1,
Expand Down
11 changes: 4 additions & 7 deletions setup.cfg
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Inside of setup.cfg
[metadata]
description-file = README.md

[options.extras_require]
image = pillow>=8.4
video = pillow>=8.4; pafy>=0.5.5; opencv-python>=4.5.5; ffpyplayer>=4.3.5; youtube-dl==2020.12.2
completion = shtab

[options.entry_points]
console_scripts =
plotext = plotext.plotext_cli:main

[egg_info]
tag_build =
tag_date = 0

console_scripts =
plotext = plotext.plotext_cli:main
4 changes: 2 additions & 2 deletions setup.py
100755 → 100644
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.2',
version='5.2.4',
description = 'plotext plots directly on terminal',
long_description = README,
long_description_content_type = "text/markdown",
Expand All @@ -22,6 +22,6 @@
python_requires = ">=3.5",
include_package_data = True,
install_requires = [],
extras_require = {"image": ["pillow>=8.4"], "video": ["pillow>=8.4", "pafy>=0.5.5", "opencv-python>=4.5.5", "ffpyplayer>=4.3.5", "youtube-dl==2020.12.2"]},# "completion": ["shtab"]},
extras_require = {"image": ["pillow>=8.4"], "video": ["pillow>=8.4", "pafy>=0.5.5", "opencv-python>=4.5.5", "ffpyplayer>=4.3.5", "youtube-dl==2020.12.2"], "completion": ["shtab"]},
classifiers = []
)

0 comments on commit 6c80e18

Please sign in to comment.