mirror of
https://github.com/tdulcet/Table-and-Graph-Libs.git
synced 2025-05-06 06:35:26 +08:00
Simplified libraries and updated CI.
This commit is contained in:
parent
2483bd996d
commit
fb9352d236
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -48,7 +48,7 @@ jobs:
|
|||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install pylint
|
python3 -m pip install pylint
|
||||||
- name: Script
|
- name: Script
|
||||||
run: pylint -f colorized --py-version 3.7 -d design,C0103,W0311,C0301,C0302,C0209 --load-plugins pylint.extensions.code_style,pylint.extensions.emptystring,pylint.extensions.comparetozero,pylint.extensions.comparison_placement,pylint.extensions.for_any_all,pylint.extensions.consider_refactoring_into_while_condition,pylint.extensions.consider_ternary_expression,pylint.extensions.dict_init_mutate,pylint.extensions.docstyle,pylint.extensions.check_elif,pylint.extensions.set_membership,pylint.extensions.typing -e R6104 -r y python/*.py
|
run: pylint -f colorized --py-version 3.7 -d design,C0103,W0311,C0301,C0302,C0209 --load-plugins pylint.extensions.code_style,pylint.extensions.comparison_placement,pylint.extensions.for_any_all,pylint.extensions.consider_refactoring_into_while_condition,pylint.extensions.consider_ternary_expression,pylint.extensions.dict_init_mutate,pylint.extensions.docstyle,pylint.extensions.check_elif,pylint.extensions.set_membership,pylint.extensions.typing -e R6104,C1804,C1805 -r y python/*.py
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
Ruff:
|
Ruff:
|
||||||
@ -62,7 +62,7 @@ jobs:
|
|||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install ruff
|
python3 -m pip install ruff
|
||||||
- name: Script
|
- name: Script
|
||||||
run: ruff --output-format=github --target-version py37 --select F,E,W,I,D,UP,YTT,S,BLE,B,A,C4,T10,EM,EXE,ISC,ICN,G,PIE,PYI,Q,RSE,RET,SLF,SLOT,SIM,TID,TCH,ARG,PGH,PL,TRY,FLY,PERF,FURB,LOG,RUF --preview --ignore E101,E501,W191,D211,D213,D401,PLR09,PLR2004,RUF001,RUF002,RUF003 .
|
run: ruff --output-format=github --target-version py37 --select F,E4,E7,E9,W,I,D,UP,YTT,ANN,S,BLE,B,A,COM819,C4,T10,EM,EXE,ISC,ICN,G,PIE,PYI,Q,RSE,RET,SLF,SLOT,SIM,TID,TCH,ARG,PGH,PL,TRY,FLY,PERF,FURB,LOG,RUF --preview --ignore W191,D211,D213,D401,PLR09,PLR2004,RUF001,RUF002,RUF003 .
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
@ -76,7 +76,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
47
graphs.hpp
47
graphs.hpp
@ -324,7 +324,7 @@ namespace graphs
|
|||||||
: anumber < 1000 ? 0.05
|
: anumber < 1000 ? 0.05
|
||||||
: 0.5;
|
: 0.5;
|
||||||
|
|
||||||
if (number != 0 and anumber < 1000 and power > 0)
|
if (number and anumber < 1000 and power > 0)
|
||||||
{
|
{
|
||||||
strm << setprecision(LDBL_DIG) << number;
|
strm << setprecision(LDBL_DIG) << number;
|
||||||
string str = strm.str();
|
string str = strm.str();
|
||||||
@ -460,7 +460,6 @@ namespace graphs
|
|||||||
const bool axisunitslabel = aoptions.axisunitslabel;
|
const bool axisunitslabel = aoptions.axisunitslabel;
|
||||||
const type_type type = aoptions.type;
|
const type_type type = aoptions.type;
|
||||||
const char *const title = aoptions.title;
|
const char *const title = aoptions.title;
|
||||||
const style_type style = aoptions.style;
|
|
||||||
|
|
||||||
if (height == 0)
|
if (height == 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -519,14 +518,16 @@ namespace graphs
|
|||||||
if (title and title[0] != '\0')
|
if (title and title[0] != '\0')
|
||||||
cout << wrap(title, awidth) << '\n';
|
cout << wrap(title, awidth) << '\n';
|
||||||
|
|
||||||
|
const char *const *astyle = styles[aoptions.style];
|
||||||
|
|
||||||
if (border)
|
if (border)
|
||||||
{
|
{
|
||||||
cout << styles[style][2];
|
cout << astyle[2];
|
||||||
|
|
||||||
for (size_t k = 0; k < awidth; ++k)
|
for (size_t k = 0; k < awidth; ++k)
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
|
|
||||||
cout << styles[style][4] << '\n';
|
cout << astyle[4] << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < height; i += ai)
|
for (size_t i = 0; i < height; i += ai)
|
||||||
@ -561,7 +562,7 @@ namespace graphs
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (border)
|
if (border)
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
|
|
||||||
for (size_t j = 0; j < width; j += aj)
|
for (size_t j = 0; j < width; j += aj)
|
||||||
{
|
{
|
||||||
@ -574,19 +575,19 @@ namespace graphs
|
|||||||
{
|
{
|
||||||
if (axaxis and ayaxis)
|
if (axaxis and ayaxis)
|
||||||
{
|
{
|
||||||
cout << styles[style][6];
|
cout << astyle[6];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (axaxis)
|
else if (axaxis)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
cout << styles[style][4];
|
cout << astyle[4];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (i >= (height - ai))
|
else if (i >= (height - ai))
|
||||||
{
|
{
|
||||||
cout << styles[style][10];
|
cout << astyle[10];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (axistick)
|
else if (axistick)
|
||||||
@ -597,14 +598,14 @@ namespace graphs
|
|||||||
{
|
{
|
||||||
if (i <= k and (i + ai) > k)
|
if (i <= k and (i + ai) > k)
|
||||||
{
|
{
|
||||||
cout << styles[style][xaxis >= aj ? 7 : 5];
|
cout << astyle[xaxis >= aj ? 7 : 5];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!output)
|
if (!output)
|
||||||
{
|
{
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -612,12 +613,12 @@ namespace graphs
|
|||||||
{
|
{
|
||||||
if (j == 0)
|
if (j == 0)
|
||||||
{
|
{
|
||||||
cout << styles[style][2];
|
cout << astyle[2];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (j >= (width - aj))
|
else if (j >= (width - aj))
|
||||||
{
|
{
|
||||||
cout << styles[style][4];
|
cout << astyle[4];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (axistick)
|
else if (axistick)
|
||||||
@ -628,25 +629,25 @@ namespace graphs
|
|||||||
{
|
{
|
||||||
if (j <= k and (j + aj) > k)
|
if (j <= k and (j + aj) > k)
|
||||||
{
|
{
|
||||||
cout << styles[style][yaxis <= (height - ai) ? 3 : 9];
|
cout << astyle[yaxis <= (height - ai) ? 3 : 9];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!output)
|
if (!output)
|
||||||
{
|
{
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (yaxislabel and xaxislabel and axistick and axisunitslabel and ymin <= 0 and ymax >= 0 and xmin <= 0 and xmax >= 0)
|
else if (yaxislabel and xaxislabel and axistick and axisunitslabel and ymin <= 0 and ymax >= 0 and xmin <= 0 and xmax >= 0)
|
||||||
{
|
{
|
||||||
cout << "0";
|
cout << '0';
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if ((xaxis <= (width - aj) ? j >= (width - aj) : j == 0) and yaxislabel and axislabel)
|
else if ((xaxis <= (width - aj) ? j >= (width - aj) : j == 0) and yaxislabel and axislabel)
|
||||||
{
|
{
|
||||||
cout << "x";
|
cout << 'x';
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (yaxislabel and axistick and axisunitslabel)
|
else if (yaxislabel and axistick and axisunitslabel)
|
||||||
@ -692,7 +693,7 @@ namespace graphs
|
|||||||
}
|
}
|
||||||
else if ((yaxis >= ai ? i == 0 : i >= (height - ai)) and xaxislabel and axislabel)
|
else if ((yaxis >= ai ? i == 0 : i >= (height - ai)) and xaxislabel and axislabel)
|
||||||
{
|
{
|
||||||
cout << "y";
|
cout << 'y';
|
||||||
output = true;
|
output = true;
|
||||||
}
|
}
|
||||||
else if (ylabellength and (xaxis < aj ? xaxislabel : j < (xaxis - ylabellength) and (j + aj) >= (xaxis - ylabellength)) and (yaxis >= ai or i < (height - ai)) and axistick and axisunitslabel)
|
else if (ylabellength and (xaxis < aj ? xaxislabel : j < (xaxis - ylabellength) and (j + aj) >= (xaxis - ylabellength)) and (yaxis >= ai or i < (height - ai)) and axistick and axisunitslabel)
|
||||||
@ -751,7 +752,7 @@ namespace graphs
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (border)
|
if (border)
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
|
|
||||||
if (i < (height - ai) or border)
|
if (i < (height - ai) or border)
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
@ -759,12 +760,12 @@ namespace graphs
|
|||||||
|
|
||||||
if (border)
|
if (border)
|
||||||
{
|
{
|
||||||
cout << styles[style][8];
|
cout << astyle[8];
|
||||||
|
|
||||||
for (size_t k = 0; k < awidth; ++k)
|
for (size_t k = 0; k < awidth; ++k)
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
|
|
||||||
cout << styles[style][10];
|
cout << astyle[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@ -972,7 +973,7 @@ namespace graphs
|
|||||||
for (size_t j = 0; j < graphs::size(arrays); ++j)
|
for (size_t j = 0; j < graphs::size(arrays); ++j)
|
||||||
{
|
{
|
||||||
const auto &array = arrays[j];
|
const auto &array = arrays[j];
|
||||||
const unsigned int acolor = graphs::size(arrays) == 1 ? color + 1 : (j % (graphs::size(colors) - 2)) + 3;
|
const unsigned acolor = graphs::size(arrays) == 1 ? color + 1 : (j % (graphs::size(colors) - 2)) + 3;
|
||||||
|
|
||||||
for (size_t i = 0; i < graphs::size(array); ++i)
|
for (size_t i = 0; i < graphs::size(array); ++i)
|
||||||
{
|
{
|
||||||
|
@ -334,14 +334,12 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
|
|||||||
if title:
|
if title:
|
||||||
print(textwrap.fill(title, width=awidth))
|
print(textwrap.fill(title, width=awidth))
|
||||||
|
|
||||||
|
astyle = styles[style]
|
||||||
|
|
||||||
strm = ""
|
strm = ""
|
||||||
|
|
||||||
if border:
|
if border:
|
||||||
strm += styles[style][2]
|
strm += astyle[2] + (astyle[0] * awidth) + astyle[4] + "\n"
|
||||||
|
|
||||||
strm += styles[style][0] * awidth
|
|
||||||
|
|
||||||
strm += styles[style][4] + "\n"
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < height:
|
while i < height:
|
||||||
@ -369,7 +367,7 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
|
|||||||
ylabellength *= aj
|
ylabellength *= aj
|
||||||
|
|
||||||
if border:
|
if border:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
|
|
||||||
j = 0
|
j = 0
|
||||||
while j < width:
|
while j < width:
|
||||||
@ -380,14 +378,14 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
|
|||||||
|
|
||||||
if axis:
|
if axis:
|
||||||
if axaxis and ayaxis:
|
if axaxis and ayaxis:
|
||||||
strm += styles[style][6]
|
strm += astyle[6]
|
||||||
output = True
|
output = True
|
||||||
elif axaxis:
|
elif axaxis:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
strm += styles[style][4]
|
strm += astyle[4]
|
||||||
output = True
|
output = True
|
||||||
elif i >= height - ai:
|
elif i >= height - ai:
|
||||||
strm += styles[style][10]
|
strm += astyle[10]
|
||||||
output = True
|
output = True
|
||||||
elif axistick:
|
elif axistick:
|
||||||
adivisor = -ydivisor if i < yaxis else ydivisor
|
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
|
k = yaxis + adivisor
|
||||||
while (k >= i if i < yaxis else k < i + ai) and i >= ai and not output:
|
while (k >= i if i < yaxis else k < i + ai) and i >= ai and not output:
|
||||||
if i <= k < i + ai:
|
if i <= k < i + ai:
|
||||||
strm += styles[style][7 if xaxis >= aj else 5]
|
strm += astyle[7 if xaxis >= aj else 5]
|
||||||
output = True
|
output = True
|
||||||
k += adivisor
|
k += adivisor
|
||||||
if not output:
|
if not output:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
output = True
|
output = True
|
||||||
elif ayaxis:
|
elif ayaxis:
|
||||||
if j == 0:
|
if j == 0:
|
||||||
strm += styles[style][2]
|
strm += astyle[2]
|
||||||
output = True
|
output = True
|
||||||
elif j >= width - aj:
|
elif j >= width - aj:
|
||||||
strm += styles[style][4]
|
strm += astyle[4]
|
||||||
output = True
|
output = True
|
||||||
elif axistick:
|
elif axistick:
|
||||||
adivisor = -xdivisor if j < xaxis else xdivisor
|
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
|
k = xaxis + adivisor
|
||||||
while (k >= j if j < xaxis else k < j + aj) and j < width - ai and not output:
|
while (k >= j if j < xaxis else k < j + aj) and j < width - ai and not output:
|
||||||
if j <= k < j + aj:
|
if j <= k < j + aj:
|
||||||
strm += styles[style][3 if yaxis <=
|
strm += astyle[3 if yaxis <= height - ai else 9]
|
||||||
height - ai else 9]
|
|
||||||
output = True
|
output = True
|
||||||
k += adivisor
|
k += adivisor
|
||||||
if not output:
|
if not output:
|
||||||
strm += styles[style][0]
|
strm += astyle[0]
|
||||||
output = True
|
output = True
|
||||||
elif yaxislabel and xaxislabel and axistick and axisunitslabel and ymin <= 0 <= ymax and xmin <= 0 <= xmax:
|
elif yaxislabel and xaxislabel and axistick and axisunitslabel and ymin <= 0 <= ymax and xmin <= 0 <= xmax:
|
||||||
strm += "0"
|
strm += "0"
|
||||||
@ -503,25 +500,21 @@ def graph(height: int, width: int, xmin: float, xmax: float, ymin: float, ymax:
|
|||||||
j += aj
|
j += aj
|
||||||
|
|
||||||
if border:
|
if border:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
|
|
||||||
if i < height - ai or border:
|
if i < height - ai or border:
|
||||||
strm += "\n"
|
strm += "\n"
|
||||||
i += ai
|
i += ai
|
||||||
|
|
||||||
if border:
|
if border:
|
||||||
strm += styles[style][8]
|
strm += astyle[8] + (astyle[0] * awidth) + astyle[10]
|
||||||
|
|
||||||
strm += styles[style][0] * awidth
|
|
||||||
|
|
||||||
strm += styles[style][10]
|
|
||||||
|
|
||||||
print(strm)
|
print(strm)
|
||||||
|
|
||||||
return 0
|
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."""
|
"""Convert one or more arrays to graph and output."""
|
||||||
if not aarray:
|
if not aarray:
|
||||||
return 1
|
return 1
|
||||||
|
@ -74,116 +74,104 @@ def table(array: List[List[str]], headerrow: bool = False, headercolumn: bool =
|
|||||||
else:
|
else:
|
||||||
width += 2 * padding * columns
|
width += 2 * padding * columns
|
||||||
|
|
||||||
if check:
|
if check and width > w.columns:
|
||||||
if width > w.columns:
|
print(
|
||||||
print(
|
f"The width of the table ({width}) is greater then the width of the terminal ({w.columns}).", file=sys.stderr)
|
||||||
f"The width of the table ({width}) is greater then the width of the terminal ({w.columns}).", file=sys.stderr)
|
return 1
|
||||||
return 1
|
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
print(textwrap.fill(title, width=width))
|
print(textwrap.fill(title, width=width))
|
||||||
|
|
||||||
|
astyle = styles[style]
|
||||||
|
|
||||||
strm = ""
|
strm = ""
|
||||||
|
|
||||||
if tableborder:
|
if tableborder:
|
||||||
strm += styles[style][2]
|
strm += astyle[2]
|
||||||
|
|
||||||
for j in range(columns):
|
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 j < columns - 1:
|
||||||
if cellborder or headerrow or (j == 0 and headercolumn):
|
if cellborder or headerrow or (j == 0 and headercolumn):
|
||||||
strm += styles[style][3]
|
strm += astyle[3]
|
||||||
else:
|
else:
|
||||||
strm += styles[style][0]
|
strm += astyle[0]
|
||||||
|
|
||||||
strm += styles[style][4] + "\n"
|
strm += astyle[4] + "\n"
|
||||||
|
|
||||||
for i in range(rows):
|
for i in range(rows):
|
||||||
if tableborder:
|
if tableborder:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
|
|
||||||
for j in range(columns):
|
for j in range(columns):
|
||||||
if (j > 0 and cellborder) or (i == 0 and j > 0 and headerrow) or (j == 1 and headercolumn):
|
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):
|
elif j > 0 and (tableborder or (i > 0 and headerrow) or headercolumn):
|
||||||
strm += " "
|
strm += " "
|
||||||
|
|
||||||
awidth = columnwidth[j] - (strcol(array[i][j]) - len(array[i][j]))
|
awidth = columnwidth[j] - (strcol(array[i][j]) - len(array[i][j]))
|
||||||
|
|
||||||
if (i == 0 and headerrow) or (j == 0 and headercolumn):
|
if (i == 0 and headerrow) or (j == 0 and headercolumn):
|
||||||
strm += " " * padding
|
strm += (" " * padding) + "\033[1m" + array[i][j].center(awidth) + "\033[22m" + (" " * padding)
|
||||||
|
|
||||||
strm += "\033[1m" + array[i][j].center(awidth) + "\033[22m"
|
|
||||||
|
|
||||||
strm += " " * padding
|
|
||||||
else:
|
else:
|
||||||
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 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
|
|
||||||
|
|
||||||
if tableborder:
|
if tableborder:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
|
|
||||||
if i < rows - 1 or tableborder:
|
if i < rows - 1 or tableborder:
|
||||||
strm += "\n"
|
strm += "\n"
|
||||||
|
|
||||||
if (i < rows - 1 and cellborder) or (i == 0 and headerrow) or (i < rows - 1 and headercolumn):
|
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):
|
if tableborder and (cellborder or (i == 0 and headerrow) or headercolumn):
|
||||||
strm += styles[style][5]
|
strm += astyle[5]
|
||||||
|
|
||||||
for j in range(columns):
|
for j in range(columns):
|
||||||
if cellborder or (i == 0 and headerrow) or (j == 0 and headercolumn):
|
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:
|
elif headercolumn:
|
||||||
strm += " " * (2 * padding + columnwidth[j])
|
strm += " " * (2 * padding + columnwidth[j])
|
||||||
|
|
||||||
if j < columns - 1:
|
if j < columns - 1:
|
||||||
if cellborder or ((i == 0 and headerrow) and (j == 0 and headercolumn)):
|
if cellborder or ((i == 0 and headerrow) and (j == 0 and headercolumn)):
|
||||||
strm += styles[style][6]
|
strm += astyle[6]
|
||||||
elif i == 0 and headerrow:
|
elif i == 0 and headerrow:
|
||||||
strm += styles[style][9]
|
strm += astyle[9]
|
||||||
elif headercolumn:
|
elif headercolumn:
|
||||||
if j == 0:
|
if j == 0:
|
||||||
strm += styles[style][7]
|
strm += astyle[7]
|
||||||
else:
|
else:
|
||||||
strm += " "
|
strm += " "
|
||||||
|
|
||||||
if tableborder:
|
if tableborder:
|
||||||
if cellborder or (i == 0 and headerrow):
|
if cellborder or (i == 0 and headerrow):
|
||||||
strm += styles[style][7]
|
strm += astyle[7]
|
||||||
elif headercolumn:
|
elif headercolumn:
|
||||||
strm += styles[style][1]
|
strm += astyle[1]
|
||||||
|
|
||||||
strm += "\n"
|
strm += "\n"
|
||||||
|
|
||||||
if tableborder:
|
if tableborder:
|
||||||
strm += styles[style][8]
|
strm += astyle[8]
|
||||||
|
|
||||||
for j in range(columns):
|
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 j < columns - 1:
|
||||||
if cellborder or (j == 0 and headercolumn):
|
if cellborder or (j == 0 and headercolumn):
|
||||||
strm += styles[style][9]
|
strm += astyle[9]
|
||||||
else:
|
else:
|
||||||
strm += styles[style][0]
|
strm += astyle[0]
|
||||||
|
|
||||||
strm += styles[style][10]
|
strm += astyle[10]
|
||||||
|
|
||||||
print(strm)
|
print(strm)
|
||||||
|
|
||||||
return 0
|
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."""
|
"""Convert array to char array and output as table."""
|
||||||
if not aarray:
|
if not aarray:
|
||||||
return 1
|
return 1
|
||||||
@ -253,11 +241,7 @@ def functions(xmin: float, xmax: float, xstep: float, afunctions: Sequence[Calla
|
|||||||
|
|
||||||
aheaderrow = [""] * columns
|
aheaderrow = [""] * columns
|
||||||
|
|
||||||
if len(afunctions) == 1:
|
aheaderrow = aaheaderrow if len(afunctions) == 1 else aaheaderrow[:-1] + [aaheaderrow[-1] + str(j - length + 2) for j in range(1, columns)]
|
||||||
aheaderrow = aaheaderrow
|
|
||||||
else:
|
|
||||||
aheaderrow = 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)]
|
aarray = [[0 for j in range(columns)] for i in range(rows)]
|
||||||
|
|
||||||
|
@ -12,15 +12,15 @@ import graphs
|
|||||||
import tables
|
import tables
|
||||||
|
|
||||||
|
|
||||||
def afunction(x: float):
|
def afunction(x: float) -> float:
|
||||||
return x + 1
|
return x + 1
|
||||||
|
|
||||||
|
|
||||||
def function1(x: float):
|
def function1(x: float) -> float:
|
||||||
return 2 * x
|
return 2 * x
|
||||||
|
|
||||||
|
|
||||||
def function2(x: float):
|
def function2(x: float) -> float:
|
||||||
return x ** 2
|
return x ** 2
|
||||||
|
|
||||||
|
|
||||||
|
55
tables.hpp
55
tables.hpp
@ -179,7 +179,6 @@ namespace tables
|
|||||||
const bool cellborder = aoptions.cellborder;
|
const bool cellborder = aoptions.cellborder;
|
||||||
const unsigned padding = aoptions.padding;
|
const unsigned padding = aoptions.padding;
|
||||||
const char *const title = aoptions.title;
|
const char *const title = aoptions.title;
|
||||||
const style_type style = aoptions.style;
|
|
||||||
|
|
||||||
const size_t rows = array.size();
|
const size_t rows = array.size();
|
||||||
const size_t columns = array[0].size();
|
const size_t columns = array[0].size();
|
||||||
@ -225,36 +224,38 @@ namespace tables
|
|||||||
if (aoptions.alignment)
|
if (aoptions.alignment)
|
||||||
cout << aoptions.alignment;
|
cout << aoptions.alignment;
|
||||||
|
|
||||||
|
const char *const *astyle = styles[aoptions.style];
|
||||||
|
|
||||||
if (tableborder)
|
if (tableborder)
|
||||||
{
|
{
|
||||||
cout << styles[style][2];
|
cout << astyle[2];
|
||||||
|
|
||||||
for (size_t j = 0; j < columns; ++j)
|
for (size_t j = 0; j < columns; ++j)
|
||||||
{
|
{
|
||||||
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
|
|
||||||
if (j < (columns - 1))
|
if (j < (columns - 1))
|
||||||
{
|
{
|
||||||
if (cellborder or headerrow or (j == 0 and headercolumn))
|
if (cellborder or headerrow or (j == 0 and headercolumn))
|
||||||
cout << styles[style][3];
|
cout << astyle[3];
|
||||||
else
|
else
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << styles[style][4] << '\n';
|
cout << astyle[4] << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < rows; ++i)
|
for (size_t i = 0; i < rows; ++i)
|
||||||
{
|
{
|
||||||
if (tableborder)
|
if (tableborder)
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
|
|
||||||
for (size_t j = 0; j < columns; ++j)
|
for (size_t j = 0; j < columns; ++j)
|
||||||
{
|
{
|
||||||
if ((j and cellborder) or (i == 0 and j and headerrow) or (j == 1 and headercolumn))
|
if ((j and cellborder) or (i == 0 and j and headerrow) or (j == 1 and headercolumn))
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
else if (j and (tableborder or (i and headerrow) or headercolumn))
|
else if (j and (tableborder or (i and headerrow) or headercolumn))
|
||||||
cout << ' ';
|
cout << ' ';
|
||||||
|
|
||||||
@ -264,24 +265,16 @@ namespace tables
|
|||||||
{
|
{
|
||||||
const int apadding = (difference / 2);
|
const int apadding = (difference / 2);
|
||||||
|
|
||||||
cout << string(padding + apadding, ' ');
|
cout << string(padding + apadding, ' ') << "\e[1m" << array[i][j] << "\e[22m" << string(padding + (difference - apadding), ' ');
|
||||||
|
|
||||||
cout << "\e[1m" << array[i][j] << "\e[22m";
|
|
||||||
|
|
||||||
cout << string(padding + (difference - apadding), ' ');
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << string(padding, ' ');
|
cout << string(padding, ' ') << setw(difference + array[i][j].length()) << array[i][j] << string(padding, ' ');
|
||||||
|
|
||||||
cout << setw(difference + array[i][j].length()) << array[i][j];
|
|
||||||
|
|
||||||
cout << string(padding, ' ');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tableborder)
|
if (tableborder)
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
|
|
||||||
if (i < (rows - 1) or tableborder)
|
if (i < (rows - 1) or tableborder)
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
@ -291,27 +284,27 @@ namespace tables
|
|||||||
if (tableborder)
|
if (tableborder)
|
||||||
{
|
{
|
||||||
if (cellborder or (i == 0 and headerrow) or headercolumn)
|
if (cellborder or (i == 0 and headerrow) or headercolumn)
|
||||||
cout << styles[style][5];
|
cout << astyle[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < columns; ++j)
|
for (size_t j = 0; j < columns; ++j)
|
||||||
{
|
{
|
||||||
if (cellborder or (i == 0 and headerrow) or (j == 0 and headercolumn))
|
if (cellborder or (i == 0 and headerrow) or (j == 0 and headercolumn))
|
||||||
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
else if (headercolumn)
|
else if (headercolumn)
|
||||||
cout << string((2 * padding) + columnwidth[j], ' ');
|
cout << string((2 * padding) + columnwidth[j], ' ');
|
||||||
|
|
||||||
if (j < (columns - 1))
|
if (j < (columns - 1))
|
||||||
{
|
{
|
||||||
if (cellborder or ((i == 0 and headerrow) and (j == 0 and headercolumn)))
|
if (cellborder or ((i == 0 and headerrow) and (j == 0 and headercolumn)))
|
||||||
cout << styles[style][6];
|
cout << astyle[6];
|
||||||
else if (i == 0 and headerrow)
|
else if (i == 0 and headerrow)
|
||||||
cout << styles[style][9];
|
cout << astyle[9];
|
||||||
else if (headercolumn)
|
else if (headercolumn)
|
||||||
{
|
{
|
||||||
if (j == 0)
|
if (j == 0)
|
||||||
cout << styles[style][7];
|
cout << astyle[7];
|
||||||
else
|
else
|
||||||
cout << ' ';
|
cout << ' ';
|
||||||
}
|
}
|
||||||
@ -321,9 +314,9 @@ namespace tables
|
|||||||
if (tableborder)
|
if (tableborder)
|
||||||
{
|
{
|
||||||
if (cellborder or (i == 0 and headerrow))
|
if (cellborder or (i == 0 and headerrow))
|
||||||
cout << styles[style][7];
|
cout << astyle[7];
|
||||||
else if (headercolumn)
|
else if (headercolumn)
|
||||||
cout << styles[style][1];
|
cout << astyle[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
@ -332,23 +325,23 @@ namespace tables
|
|||||||
|
|
||||||
if (tableborder)
|
if (tableborder)
|
||||||
{
|
{
|
||||||
cout << styles[style][8];
|
cout << astyle[8];
|
||||||
|
|
||||||
for (size_t j = 0; j < columns; ++j)
|
for (size_t j = 0; j < columns; ++j)
|
||||||
{
|
{
|
||||||
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
for (size_t k = 0; k < (2 * padding) + columnwidth[j]; ++k)
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
|
|
||||||
if (j < (columns - 1))
|
if (j < (columns - 1))
|
||||||
{
|
{
|
||||||
if (cellborder or (j == 0 and headercolumn))
|
if (cellborder or (j == 0 and headercolumn))
|
||||||
cout << styles[style][9];
|
cout << astyle[9];
|
||||||
else
|
else
|
||||||
cout << styles[style][0];
|
cout << astyle[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << styles[style][10];
|
cout << astyle[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user