Simplified libraries and updated CI.

This commit is contained in:
Teal Dulcet
2023-12-31 07:57:30 -08:00
parent 2483bd996d
commit fb9352d236
6 changed files with 100 additions and 129 deletions

View File

@@ -334,14 +334,12 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
if title:
print(textwrap.fill(title, width=awidth))
astyle = styles[style]
strm = ""
if border:
strm += styles[style][2]
strm += styles[style][0] * awidth
strm += styles[style][4] + "\n"
strm += astyle[2] + (astyle[0] * awidth) + astyle[4] + "\n"
i = 0
while i < height:
@@ -369,7 +367,7 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
ylabellength *= aj
if border:
strm += styles[style][1]
strm += astyle[1]
j = 0
while j < width:
@@ -380,14 +378,14 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
if axis:
if axaxis and ayaxis:
strm += styles[style][6]
strm += astyle[6]
output = True
elif axaxis:
if i == 0:
strm += styles[style][4]
strm += astyle[4]
output = True
elif i >= height - ai:
strm += styles[style][10]
strm += astyle[10]
output = True
elif axistick:
adivisor = -ydivisor if i < yaxis else ydivisor
@@ -395,18 +393,18 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
k = yaxis + adivisor
while (k >= i if i < yaxis else k < i + ai) and i >= ai and not output:
if i <= k < i + ai:
strm += styles[style][7 if xaxis >= aj else 5]
strm += astyle[7 if xaxis >= aj else 5]
output = True
k += adivisor
if not output:
strm += styles[style][1]
strm += astyle[1]
output = True
elif ayaxis:
if j == 0:
strm += styles[style][2]
strm += astyle[2]
output = True
elif j >= width - aj:
strm += styles[style][4]
strm += astyle[4]
output = True
elif axistick:
adivisor = -xdivisor if j < xaxis else xdivisor
@@ -414,12 +412,11 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
k = xaxis + adivisor
while (k >= j if j < xaxis else k < j + aj) and j < width - ai and not output:
if j <= k < j + aj:
strm += styles[style][3 if yaxis <=
height - ai else 9]
strm += astyle[3 if yaxis <= height - ai else 9]
output = True
k += adivisor
if not output:
strm += styles[style][0]
strm += astyle[0]
output = True
elif yaxislabel and xaxislabel and axistick and axisunitslabel and ymin <= 0 <= ymax and xmin <= 0 <= xmax:
strm += "0"
@@ -503,25 +500,21 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
j += aj
if border:
strm += styles[style][1]
strm += astyle[1]
if i < height - ai or border:
strm += "\n"
i += ai
if border:
strm += styles[style][8]
strm += styles[style][0] * awidth
strm += styles[style][10]
strm += astyle[8] + (astyle[0] * awidth) + astyle[10]
print(strm)
return 0
def histogram(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax: float, aarray: Sequence[Sequence[Sequence[float]]], border: bool = False, axis: bool = True, axislabel: bool = True, axistick: bool = True, axisunitslabel: bool = True, xunits: units_types = units_types.fracts, yunits: units_types = units_types.fracts, style: style_types = style_types.light, color: color_types = color_types.red, title: Optional[str] = None, check: bool = True) -> int:
def histogram(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax: float, aarray: Sequence[float], border: bool = False, axis: bool = True, axislabel: bool = True, axistick: bool = True, axisunitslabel: bool = True, xunits: units_types = units_types.fracts, yunits: units_types = units_types.fracts, style: style_types = style_types.light, color: color_types = color_types.red, title: Optional[str] = None, check: bool = True) -> int:
"""Convert one or more arrays to graph and output."""
if not aarray:
return 1

View File

@@ -74,116 +74,104 @@ def table(array: List[List[str]], headerrow: bool = False, headercolumn: bool =
else:
width += 2 * padding * columns
if check:
if width > w.columns:
print(
f"The width of the table ({width}) is greater then the width of the terminal ({w.columns}).", file=sys.stderr)
return 1
if check and width > w.columns:
print(
f"The width of the table ({width}) is greater then the width of the terminal ({w.columns}).", file=sys.stderr)
return 1
if title:
print(textwrap.fill(title, width=width))
astyle = styles[style]
strm = ""
if tableborder:
strm += styles[style][2]
strm += astyle[2]
for j in range(columns):
strm += styles[style][0] * (2 * padding + columnwidth[j])
strm += astyle[0] * (2 * padding + columnwidth[j])
if j < columns - 1:
if cellborder or headerrow or (j == 0 and headercolumn):
strm += styles[style][3]
strm += astyle[3]
else:
strm += styles[style][0]
strm += astyle[0]
strm += styles[style][4] + "\n"
strm += astyle[4] + "\n"
for i in range(rows):
if tableborder:
strm += styles[style][1]
strm += astyle[1]
for j in range(columns):
if (j > 0 and cellborder) or (i == 0 and j > 0 and headerrow) or (j == 1 and headercolumn):
strm += styles[style][1]
strm += astyle[1]
elif j > 0 and (tableborder or (i > 0 and headerrow) or headercolumn):
strm += " "
awidth = columnwidth[j] - (strcol(array[i][j]) - len(array[i][j]))
if (i == 0 and headerrow) or (j == 0 and headercolumn):
strm += " " * padding
strm += "\033[1m" + array[i][j].center(awidth) + "\033[22m"
strm += " " * padding
strm += (" " * padding) + "\033[1m" + array[i][j].center(awidth) + "\033[22m" + (" " * padding)
else:
strm += " " * padding
if alignment is None:
strm += f"{array[i][j]:{awidth}}"
elif alignment:
strm += array[i][j].rjust(awidth)
else:
strm += array[i][j].ljust(awidth)
strm += " " * padding
strm += (" " * padding) + (f"{array[i][j]:{awidth}}" if alignment is None else array[i][j].rjust(awidth) if alignment else array[i][j].ljust(awidth)) + (" " * padding)
if tableborder:
strm += styles[style][1]
strm += astyle[1]
if i < rows - 1 or tableborder:
strm += "\n"
if (i < rows - 1 and cellborder) or (i == 0 and headerrow) or (i < rows - 1 and headercolumn):
if tableborder and (cellborder or (i == 0 and headerrow) or headercolumn):
strm += styles[style][5]
strm += astyle[5]
for j in range(columns):
if cellborder or (i == 0 and headerrow) or (j == 0 and headercolumn):
strm += styles[style][0] * (2 * padding + columnwidth[j])
strm += astyle[0] * (2 * padding + columnwidth[j])
elif headercolumn:
strm += " " * (2 * padding + columnwidth[j])
if j < columns - 1:
if cellborder or ((i == 0 and headerrow) and (j == 0 and headercolumn)):
strm += styles[style][6]
strm += astyle[6]
elif i == 0 and headerrow:
strm += styles[style][9]
strm += astyle[9]
elif headercolumn:
if j == 0:
strm += styles[style][7]
strm += astyle[7]
else:
strm += " "
if tableborder:
if cellborder or (i == 0 and headerrow):
strm += styles[style][7]
strm += astyle[7]
elif headercolumn:
strm += styles[style][1]
strm += astyle[1]
strm += "\n"
if tableborder:
strm += styles[style][8]
strm += astyle[8]
for j in range(columns):
strm += styles[style][0] * (2 * padding + columnwidth[j])
strm += astyle[0] * (2 * padding + columnwidth[j])
if j < columns - 1:
if cellborder or (j == 0 and headercolumn):
strm += styles[style][9]
strm += astyle[9]
else:
strm += styles[style][0]
strm += astyle[0]
strm += styles[style][10]
strm += astyle[10]
print(strm)
return 0
def array(aarray: Sequence[Sequence[Any]], aheaderrow: Optional[Sequence[Any]] = None, aheadercolumn: Optional[Sequence[Any]] = None, headerrow: bool = False, headercolumn: bool = False, tableborder: bool = True, cellborder: bool = False, padding: int = 1, alignment: Optional[bool] = None, title: Optional[str] = None, style: style_types = style_types.light) -> int:
def array(aarray: Sequence[Sequence[Any]], aheaderrow: Optional[Sequence[str]] = None, aheadercolumn: Optional[Sequence[str]] = None, headerrow: bool = False, headercolumn: bool = False, tableborder: bool = True, cellborder: bool = False, padding: int = 1, alignment: Optional[bool] = None, title: Optional[str] = None, style: style_types = style_types.light) -> int:
"""Convert array to char array and output as table."""
if not aarray:
return 1
@@ -253,11 +241,7 @@ def functions(xmin: float, xmax: float, xstep: float, afunctions: Sequence[Calla
aheaderrow = [""] * columns
if len(afunctions) == 1:
aheaderrow = aaheaderrow
else:
aheaderrow = aaheaderrow[:-1] + [aaheaderrow[-1] +
str(j - length + 2) for j in range(1, columns)]
aheaderrow = aaheaderrow if len(afunctions) == 1 else aaheaderrow[:-1] + [aaheaderrow[-1] + str(j - length + 2) for j in range(1, columns)]
aarray = [[0 for j in range(columns)] for i in range(rows)]

View File

@@ -12,15 +12,15 @@ import graphs
import tables
def afunction(x: float):
def afunction(x: float) -> float:
return x + 1
def function1(x: float):
def function1(x: float) -> float:
return 2 * x
def function2(x: float):
def function2(x: float) -> float:
return x ** 2