From f0e9e1f0c3465b446ec57fe2f4b89942748a941a Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Tue, 18 Aug 2020 05:42:12 -0700 Subject: [PATCH] Updated Travis CI and README. --- .travis.yml | 2 ++ README.md | 48 ++++++++++++++++++------------------------------ graphs.hpp | 45 ++++++++++++++++++++++++--------------------- tables.hpp | 5 ++--- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b897e8..3e80a56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ matrix: dist: xenial - os: linux dist: bionic + - os: linux + dist: focal install: - sudo apt-get -yqq update - sudo apt-get -yqq install cppcheck diff --git a/README.md b/README.md index f0477e0..64dd8d0 100644 --- a/README.md +++ b/README.md @@ -230,44 +230,38 @@ int main() #### Header row -Option: `headerrow` - +Option: `headerrow`\ Default value: `false` Header rows are bolded and centered. #### Header column -Option: `headercolumn` - +Option: `headercolumn`\ Default value: `false` Header columns are bolded and centered. #### Table border -Option: `tableborder` - +Option: `tableborder`\ Default value: `true` #### Cell border -Option: `cellborder` - +Option: `cellborder`\ Default value: `false` Requires `tableborder` to be `true`. #### Cell padding -Option: `padding` - +Option: `padding`\ Default value: `1` #### Alignment -Option: `alignment` - +Option: `alignment`\ Values: * `left` (default) @@ -275,22 +269,19 @@ Values: #### bool to alpha -Option: `boolalpha` - +Option: `boolalpha`\ Default value: `false` #### Title -Option: `title` - +Option: `title`\ Default value: `NULL` The title is word wrapped based on the current width of the terminal, using [this](https://gist.github.com/tdulcet/819821ca69501822ad3f84a060c640a0) solution. Handles newlines, tabs and [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters). #### Border style -Option: `style` - +Option: `style`\ Values: 0. ASCII @@ -442,38 +433,33 @@ int main() #### Border/Axis -Option: `border` - +Option: `border`\ Default value: `true` #### Axis labels -Option: `axislabel` - +Option: `axislabel`\ Default value: `true` Requires `border` to be `true`. #### Axis units labels -Option: `axisunitslabel` - +Option: `axisunitslabel`\ Default value: `true` Requires `border` and `axislabel` to be `true`. #### Title -Option: `title` - +Option: `title`\ Default value: `NULL` The title is word wrapped based on the current width of the terminal, using [this](https://gist.github.com/tdulcet/819821ca69501822ad3f84a060c640a0) solution. Handles newlines, tabs and [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters). #### Axis/Border style -Option: `style` - +Option: `style`\ Values: 0. ASCII @@ -500,8 +486,7 @@ Values: #### Graph/Plot Color -Option: `color` - +Option: `color`\ Values: 0. System default @@ -544,6 +529,7 @@ Pull requests welcome! Ideas for contributions: * Add more options * Add an option to print a border around graphs/plots + * Add options to word wrap and truncate long text in table cells * Add more examples * Improve the performance * Handle newlines, tabs and formatted text in the tables @@ -551,4 +537,6 @@ Pull requests welcome! Ideas for contributions: * Support more graph/plot colors * Support combining colors when functions cross * Support plotting multiple arrays of different sizes +* Update the `-t, --table` options of column command from [util-linux](https://en.wikipedia.org/wiki/Util-linux) to use the Table library +* Create a new CLI tool that uses the Graph library * Port to other languages (C, Java, Rust, etc.) diff --git a/graphs.hpp b/graphs.hpp index 084078a..751b8de 100644 --- a/graphs.hpp +++ b/graphs.hpp @@ -22,7 +22,7 @@ const char *const styles[][11] = { {"━", "┃", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"}, //Heavy {"═", "║", "╔", "╦", "╗", "╠", "╬", "╣", "╚", "╩", "╝"}, //Double {"╌", "╎", "┌", "┬", "┐", "├", "┼", "┤", "└", "┴", "┘"}, //Light Dashed - {"╍", "╏", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"} //Heavy Dashed + {"╍", "╏", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"} //Heavy Dashed }; // {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}};//No border @@ -181,35 +181,38 @@ size_t outputlabel(const long double label, ostringstream &strm) } } - if (!output and fmod(label, M_PI) == 0) + if (abs(label) >= DBL_EPSILON) { - const char symbol[] = "π"; + if (!output and fmod(label, M_PI) == 0) + { + const char symbol[] = "π"; - intpart = label / M_PI; + intpart = label / M_PI; - if (intpart == -1) - strm << "-"; - else if (intpart != 1) - strm << intpart; + if (intpart == -1) + strm << "-"; + else if (intpart != 1) + strm << intpart; - strm << symbol; + strm << symbol; - output = true; - } - else if (!output and fmod(label, M_E) == 0) - { - const char symbol[] = "e"; + output = true; + } + else if (!output and fmod(label, M_E) == 0) + { + const char symbol[] = "e"; - intpart = label / M_E; + intpart = label / M_E; - if (intpart == -1) - strm << "-"; - else if (intpart != 1) - strm << intpart; + if (intpart == -1) + strm << "-"; + else if (intpart != 1) + strm << intpart; - strm << symbol; + strm << symbol; - output = true; + output = true; + } } if (!output) diff --git a/tables.hpp b/tables.hpp index 490bf30..e5f6cd1 100644 --- a/tables.hpp +++ b/tables.hpp @@ -19,7 +19,7 @@ const char *const styles[][11] = { {"━", "┃", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"}, //Heavy {"═", "║", "╔", "╦", "╗", "╠", "╬", "╣", "╚", "╩", "╝"}, //Double {"╌", "╎", "┌", "┬", "┐", "├", "┼", "┤", "└", "┴", "┘"}, //Light Dashed - {"╍", "╏", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"} //Heavy Dashed + {"╍", "╏", "┏", "┳", "┓", "┣", "╋", "┫", "┗", "┻", "┛"} //Heavy Dashed }; // {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}};//No border @@ -433,8 +433,7 @@ int table(const long double xmin, const long double xmax, const long double xscl const char *const aheaderrow[] = {"x", "y"}; // const char* const aheaderrow[] = {"", "x", "y"}; - char **headerrow = NULL; - headerrow = new char *[columns]; + char **headerrow = new char *[columns]; for (unsigned int j = 0; j < columns; ++j) {