Skip to content

Commit

Permalink
Simplified libraries and updated CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdulcet committed Dec 31, 2023
1 parent 2483bd9 commit eb5bba1
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 129 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install pylint
- 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

Ruff:
Expand All @@ -62,7 +62,7 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install ruff
- 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

Python:
Expand All @@ -76,7 +76,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
47 changes: 24 additions & 23 deletions graphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace graphs
: anumber < 1000 ? 0.05
: 0.5;

if (number != 0 and anumber < 1000 and power > 0)
if (number and anumber < 1000 and power > 0)
{
strm << setprecision(LDBL_DIG) << number;
string str = strm.str();
Expand Down Expand Up @@ -460,7 +460,6 @@ namespace graphs
const bool axisunitslabel = aoptions.axisunitslabel;
const type_type type = aoptions.type;
const char *const title = aoptions.title;
const style_type style = aoptions.style;

if (height == 0)
return 1;
Expand Down Expand Up @@ -518,15 +517,17 @@ namespace graphs

if (title and title[0] != '\0')
cout << wrap(title, awidth) << '\n';

const char *const astyle[] = styles[aoptions.style];

if (border)
{
cout << styles[style][2];
cout << astyle[2];

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)
Expand Down Expand Up @@ -561,7 +562,7 @@ namespace graphs
}

if (border)
cout << styles[style][1];
cout << astyle[1];

for (size_t j = 0; j < width; j += aj)
{
Expand All @@ -574,19 +575,19 @@ namespace graphs
{
if (axaxis and ayaxis)
{
cout << styles[style][6];
cout << astyle[6];
output = true;
}
else if (axaxis)
{
if (i == 0)
{
cout << styles[style][4];
cout << astyle[4];
output = true;
}
else if (i >= (height - ai))
{
cout << styles[style][10];
cout << astyle[10];
output = true;
}
else if (axistick)
Expand All @@ -597,27 +598,27 @@ namespace graphs
{
if (i <= k and (i + ai) > k)
{
cout << styles[style][xaxis >= aj ? 7 : 5];
cout << astyle[xaxis >= aj ? 7 : 5];
output = true;
}
}
}
if (!output)
{
cout << styles[style][1];
cout << astyle[1];
output = true;
}
}
else if (ayaxis)
{
if (j == 0)
{
cout << styles[style][2];
cout << astyle[2];
output = true;
}
else if (j >= (width - aj))
{
cout << styles[style][4];
cout << astyle[4];
output = true;
}
else if (axistick)
Expand All @@ -628,25 +629,25 @@ namespace graphs
{
if (j <= k and (j + aj) > k)
{
cout << styles[style][yaxis <= (height - ai) ? 3 : 9];
cout << astyle[yaxis <= (height - ai) ? 3 : 9];
output = true;
}
}
}
if (!output)
{
cout << styles[style][0];
cout << astyle[0];
output = true;
}
}
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;
}
else if ((xaxis <= (width - aj) ? j >= (width - aj) : j == 0) and yaxislabel and axislabel)
{
cout << "x";
cout << 'x';
output = true;
}
else if (yaxislabel and axistick and axisunitslabel)
Expand Down Expand Up @@ -692,7 +693,7 @@ namespace graphs
}
else if ((yaxis >= ai ? i == 0 : i >= (height - ai)) and xaxislabel and axislabel)
{
cout << "y";
cout << 'y';
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)
Expand Down Expand Up @@ -751,20 +752,20 @@ namespace graphs
}

if (border)
cout << styles[style][1];
cout << astyle[1];

if (i < (height - ai) or border)
cout << '\n';
}

if (border)
{
cout << styles[style][8];
cout << astyle[8];

for (size_t k = 0; k < awidth; ++k)
cout << styles[style][0];
cout << astyle[0];

cout << styles[style][10];
cout << astyle[10];
}

cout << endl;
Expand Down Expand Up @@ -972,7 +973,7 @@ namespace graphs
for (size_t j = 0; j < graphs::size(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)
{
Expand Down
39 changes: 16 additions & 23 deletions python/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -380,46 +378,45 @@ 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

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

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"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit eb5bba1

Please sign in to comment.