diff --git a/README.md b/README.md index 78d3e6a..ec5f275 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,27 @@ These header only libraries use [box-drawing](https://en.wikipedia.org/wiki/Box- See the [python](python) directory for Python ports of the libraries. +For command-line tools using these respective libraries, see the [Tables and Graphs CLI](https://github.com/tdulcet/Tables-and-Graphs-CLI). + ❤️ Please visit [tealdulcet.com](https://www.tealdulcet.com/) to support these libraries and my other software development. ## Table of Contents * [Tables](#tables) * [Usage](#usage) + * [Output char array as table](#output-char-array-as-table) + * [Output array as table with separate header row and column](#output-array-as-table-with-separate-header-row-and-column) + * [Output array as table](#output-array-as-table) + * [Output sorted array as table](#output-sorted-array-as-table) + * [Output single function as table](#output-single-function-as-table) + * [Output multiple functions as table](#output-multiple-functions-as-table) * [Options](#options) * [Graphs/Plots](#graphsplots) * [Usage](#usage-1) + * [Output array as histogram](#output-array-as-histogram) + * [Output single array as plot](#output-single-array-as-plot) + * [Output multiple arrays as plot](#output-single-array-as-plot) + * [Output single function as graph](#output-single-function-as-graph) + * [Output multiple functions as graph](#output-multiple-functions-as-graph) * [Options](#options-1) * [Contributing](#contributing) @@ -34,6 +47,8 @@ Compile with: * GCC: `g++ -std=c++14 -Wall -g -O3 tables.cpp -o tables` * Clang: `clang++ -std=c++14 -Wall -g -O3 tables.cpp -o tables` +Other compilers should work as well, but are not (yet) tested. + Run with: `./tables` #### Output char array as table @@ -95,7 +110,7 @@ int main() } ``` -Table cells can contain [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters), but not newlines and tabs. +Table cells can contain [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters) and formatted text with [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code), but not newlines and tabs. ![](images/char%20array%20to%20table.png) @@ -501,6 +516,7 @@ Values: 4. `style_double`: Double ![](images/double%20table.png) 5. `style_arc`: Light Arc + ![](images/light%20arc%20table.png) 6. `style_light_dashed`: Light Dashed ![](images/light%20dashed%20table.png) 7. `style_heavy_dashed`: Heavy Dashed @@ -531,6 +547,8 @@ Compile with: * GCC: `g++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs` * Clang: `clang++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs` +Other compilers should work as well, but are not (yet) tested. + Run with: `./graphs` If `height` is `0`, it will be set to the current height of the terminal (number of rows times four). If `width` is `0`, it will be set to the current width of the terminal (number of columns times two). @@ -599,6 +617,8 @@ int main() If `xmin` and `xmax` are both `0`, they will be set to the respective minimum and maximum values of x in the array. If `ymin` and `ymax` are both `0`, they will be set to the respective minimum and maximum values of y in the resulting histogram. +![](images/array%20to%20histogram.png) + #### Output single array as plot ##### C style pointer @@ -860,7 +880,9 @@ Option: `type`\ Values: 1. `type_braille`: Braille (default) + ![](images/type%20braille%20graph.png) 2. `type_block`: Block + ![](images/type%20block%20graph.png) The Braille type has the highest resolution of 2×4 pixels per character, while the block type uses 2×2. This option is only used for plots and graphs. Histograms use 1×8 pixels per character. @@ -870,8 +892,11 @@ Option: `mark`\ Values: 1. `mark_dot`: Dot (default) + ![](images/mark%20dot%20graph.png) 2. `mark_plus`: Plus + ![](images/mark%20plus%20graph.png) 3. `mark_square`: Square + ![](images/mark%20square%20graph.png) The dot mark type uses a single pixel per mark, the plus uses five pixels and the square uses eight pixels. This option is only used for plots and graphs. @@ -898,6 +923,7 @@ Values: 4. `style_double`: Double ![](images/double%20graph.png) 5. `style_arc`: Light Arc + ![](images/light%20arc%20graph.png) 6. `style_light_dashed`: Light Dashed ![](images/light%20dashed%20graph.png) 7. `style_heavy_dashed`: Heavy Dashed @@ -926,9 +952,9 @@ Values: 15. `color_light_cyan`: Light Cyan 16. `color_white`: White -See [here](https://misc.flogisoft.com/bash/tip_colors_and_formatting#foreground_text) for examples of the colors. +See here for [examples of the colors](https://misc.flogisoft.com/bash/tip_colors_and_formatting#foreground_text). -Only used when plotting a single array and when graphing a single function. When plotting multiple arrays or graphing multiple functions, colors 2 - 16 are used inorder. The system default color is used where the plots cross. +This option is only used when plotting a single array and when graphing a single function. When plotting multiple arrays or graphing multiple functions, colors 2 - 16 are used inorder. The system default color is used where the plots cross. ##### Plot @@ -958,7 +984,6 @@ Both: * Add options to word wrap and truncate long text in table cells * Add option to center text in table cells * Add more examples -* Update screenshots of existing examples * Improve the performance * Handle newlines and tabs in the tables * Handle formatted text in the table and graph/plot titles @@ -966,8 +991,8 @@ Both: * Support 256 and 24-bit color * Support combining/blending colors when functions cross * 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.) C++: +* Update the CI to test with more compilers * Support tables with the `wchar_t`, `char16_t` and `char32_t` C data types and the `wstring`, `u16string` and `u32string` C++ data types. diff --git a/graphs.cpp b/graphs.cpp index 9cd50c6..3ddcdb7 100644 --- a/graphs.cpp +++ b/graphs.cpp @@ -8,6 +8,7 @@ #include #include #include + #include "graphs.hpp" using namespace std; diff --git a/graphs.hpp b/graphs.hpp index c9320e2..a35c2a1 100644 --- a/graphs.hpp +++ b/graphs.hpp @@ -271,7 +271,7 @@ namespace graphs // Adapted from: https://github.com/coreutils/coreutils/blob/master/src/numfmt.c void outputunit(long double number, const units_type scale, ostringstream &strm) { - unsigned int x = 0; + unsigned x = 0; long double val = number; if (val >= -LDBL_MAX and val <= LDBL_MAX) { @@ -309,7 +309,7 @@ namespace graphs break; } - unsigned int power = 0; + unsigned power = 0; if (number >= -LDBL_MAX and number <= LDBL_MAX) { while (abs(number) >= scale_base) @@ -329,7 +329,7 @@ namespace graphs strm << setprecision(LDBL_DIG) << number; string str = strm.str(); - const unsigned int length = 5 + (number < 0 ? 1 : 0); + const unsigned length = 5 + (number < 0 ? 1 : 0); if (str.length() > length) { const int prec = anumber < 10 ? 3 : anumber < 100 ? 2 @@ -856,7 +856,7 @@ namespace graphs vector> aaarray(width, vector(height, 0)); - const unsigned int acolor = color + 1; + const unsigned acolor = color + 1; for (size_t x = 0; x < graphs::size(histogram); ++x) { diff --git a/images/ASCII graph.png b/images/ASCII graph.png index 219656d..6dd9c9a 100644 Binary files a/images/ASCII graph.png and b/images/ASCII graph.png differ diff --git a/images/ASCII table.png b/images/ASCII table.png index ea3edf8..14c90ee 100644 Binary files a/images/ASCII table.png and b/images/ASCII table.png differ diff --git a/images/array to histogram.png b/images/array to histogram.png new file mode 100644 index 0000000..3a397d0 Binary files /dev/null and b/images/array to histogram.png differ diff --git a/images/array to plot.png b/images/array to plot.png index 137866a..fdd5d6f 100644 Binary files a/images/array to plot.png and b/images/array to plot.png differ diff --git a/images/array to table.png b/images/array to table.png index 678d81a..f4cc3d8 100644 Binary files a/images/array to table.png and b/images/array to table.png differ diff --git a/images/basic graph.png b/images/basic graph.png index 096bb6c..26292d0 100644 Binary files a/images/basic graph.png and b/images/basic graph.png differ diff --git a/images/basic table.png b/images/basic table.png index b360586..8b407d0 100644 Binary files a/images/basic table.png and b/images/basic table.png differ diff --git a/images/char array to table.png b/images/char array to table.png index 2deca89..52f87f1 100644 Binary files a/images/char array to table.png and b/images/char array to table.png differ diff --git a/images/double graph.png b/images/double graph.png index 19e0d03..ac66a98 100644 Binary files a/images/double graph.png and b/images/double graph.png differ diff --git a/images/double table.png b/images/double table.png index 06eb704..ed94356 100644 Binary files a/images/double table.png and b/images/double table.png differ diff --git a/images/function to graph.png b/images/function to graph.png index 9a934fa..8c49585 100644 Binary files a/images/function to graph.png and b/images/function to graph.png differ diff --git a/images/function to table.png b/images/function to table.png index f7cb9d4..fa2b97a 100644 Binary files a/images/function to table.png and b/images/function to table.png differ diff --git a/images/graph colors.png b/images/graph colors.png index f099713..745e7d7 100644 Binary files a/images/graph colors.png and b/images/graph colors.png differ diff --git a/images/heavy dashed graph.png b/images/heavy dashed graph.png index b884fd7..cab3b2c 100644 Binary files a/images/heavy dashed graph.png and b/images/heavy dashed graph.png differ diff --git a/images/heavy dashed table.png b/images/heavy dashed table.png index 5d406a6..adaef76 100644 Binary files a/images/heavy dashed table.png and b/images/heavy dashed table.png differ diff --git a/images/heavy graph.png b/images/heavy graph.png index 458abb1..c561fc1 100644 Binary files a/images/heavy graph.png and b/images/heavy graph.png differ diff --git a/images/heavy table.png b/images/heavy table.png index d02b477..b6519cd 100644 Binary files a/images/heavy table.png and b/images/heavy table.png differ diff --git a/images/light arc graph.png b/images/light arc graph.png new file mode 100644 index 0000000..e67c045 Binary files /dev/null and b/images/light arc graph.png differ diff --git a/images/light arc table.png b/images/light arc table.png new file mode 100644 index 0000000..5e6dfb9 Binary files /dev/null and b/images/light arc table.png differ diff --git a/images/light dashed graph.png b/images/light dashed graph.png index e540fa0..53a57da 100644 Binary files a/images/light dashed graph.png and b/images/light dashed graph.png differ diff --git a/images/light dashed table.png b/images/light dashed table.png index ed10789..4d7c227 100644 Binary files a/images/light dashed table.png and b/images/light dashed table.png differ diff --git a/images/light graph.png b/images/light graph.png index 669a529..fdd5d6f 100644 Binary files a/images/light graph.png and b/images/light graph.png differ diff --git a/images/light table.png b/images/light table.png index c097dbe..52f87f1 100644 Binary files a/images/light table.png and b/images/light table.png differ diff --git a/images/mark dot graph.png b/images/mark dot graph.png new file mode 100644 index 0000000..fdd5d6f Binary files /dev/null and b/images/mark dot graph.png differ diff --git a/images/mark plus graph.png b/images/mark plus graph.png new file mode 100644 index 0000000..f6eb16e Binary files /dev/null and b/images/mark plus graph.png differ diff --git a/images/mark square graph.png b/images/mark square graph.png new file mode 100644 index 0000000..d3976a7 Binary files /dev/null and b/images/mark square graph.png differ diff --git a/images/multiple functions to graph.png b/images/multiple functions to graph.png index b998860..ae7ef2d 100644 Binary files a/images/multiple functions to graph.png and b/images/multiple functions to graph.png differ diff --git a/images/multiple functions to table.png b/images/multiple functions to table.png index a139a87..95e2421 100644 Binary files a/images/multiple functions to table.png and b/images/multiple functions to table.png differ diff --git a/images/plot colors.png b/images/plot colors.png index 17188de..d3ac7b9 100644 Binary files a/images/plot colors.png and b/images/plot colors.png differ diff --git a/images/sorted array to table.png b/images/sorted array to table.png index ed79a46..94e55a9 100644 Binary files a/images/sorted array to table.png and b/images/sorted array to table.png differ diff --git a/images/type block graph.png b/images/type block graph.png new file mode 100644 index 0000000..ea45e12 Binary files /dev/null and b/images/type block graph.png differ diff --git a/images/type braille graph.png b/images/type braille graph.png new file mode 100644 index 0000000..fdd5d6f Binary files /dev/null and b/images/type braille graph.png differ diff --git a/python/README.md b/python/README.md index 6dda2ea..9276a1f 100644 --- a/python/README.md +++ b/python/README.md @@ -1,9 +1,24 @@ ## Table of Contents * [Tables](#tables) * [Usage](#usage) + * [Output str array as table](#output-str-array-as-table) + * [Output array as table with separate header row and column](#output-array-as-table-with-separate-header-row-and-column) + * [Output array as table](#output-array-as-table) + * [Output sorted array as table](#output-sorted-array-as-table) + * [Output single function as table](#output-single-function-as-table) + * [Output lambda function as table](#output-lambda-function-as-table) + * [Output multiple functions as table](#output-multiple-functions-as-table) + * [Output multiple lambda functions as table](#output-multiple-lambda-functions-as-table) * [Options](#options) * [Graphs/Plots](#graphsplots) * [Usage](#usage-1) + * [Output array as histogram](#output-array-as-histogram) + * [Output single array as plot](#output-single-array-as-plot) + * [Output multiple arrays as plot](#output-single-array-as-plot) + * [Output single function as graph](#output-single-function-as-graph) + * [Output lambda function as graph](#output-lambda-function-as-graph) + * [Output multiple functions as graph](#output-multiple-functions-as-graph) + * [Output multiple lambda functions as graph](#output-multiple-lambda-functions-as-graph) * [Options](#options-1) ## Tables @@ -32,7 +47,7 @@ import tables tables.array(array, headerrow=True, headercolumn=True) ``` -Table cells can contain [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters), but not newlines and tabs. +Table cells can contain [Unicode characters](https://en.wikipedia.org/wiki/List_of_Unicode_characters) and formatted text with [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code), but not newlines and tabs. ![](../images/char%20array%20to%20table.png) @@ -215,6 +230,7 @@ Values: 4. `style_types.double`: Double ![](../images/double%20table.png) 5. `style_types.arc`: Light Arc + ![](../images/light%20arc%20table.png) 6. `style_types.light_dashed`: Light Dashed ![](../images/light%20dashed%20table.png) 7. `style_types.heavy_dashed`: Heavy Dashed @@ -265,6 +281,8 @@ graphs.histogram(height, width, xmin, xmax, ymin, ymax, array) If `xmin` and `xmax` are both `0`, they will be set to the respective minimum and maximum values of x in the array. If `ymin` and `ymax` are both `0`, they will be set to the respective minimum and maximum values of y in the resulting histogram. +![](../images/array%20to%20histogram.png) + #### Output single array as plot ```py @@ -440,7 +458,9 @@ Option: `type`\ Values: 1. `type_types.braille`: Braille (default) + ![](../images/type%20braille%20graph.png) 2. `type_types.block`: Block + ![](../images/type%20block%20graph.png) The Braille type has the highest resolution of 2×4 pixels per character, while the block type uses 2×2. This option is only used for plots and graphs. Histograms use 1×8 pixels per character. @@ -450,8 +470,11 @@ Option: `mark`\ Values: 1. `mark_types.dot`: Dot (default) + ![](../images/mark%20dot%20graph.png) 2. `mark_types.plus`: Plus + ![](../images/mark%20plus%20graph.png) 3. `mark_types.square`: Square + ![](../images/mark%20square%20graph.png) The dot mark type uses a single pixel per mark, the plus uses five pixels and the square uses eight pixels. This option is only used for plots and graphs. @@ -478,6 +501,7 @@ Values: 4. `style_types.double`: Double ![](../images/double%20graph.png) 5. `style_types.arc`: Light Arc + ![](../images/light%20arc%20graph.png) 6. `style_types.light_dashed`: Light Dashed ![](../images/light%20dashed%20graph.png) 7. `style_types.heavy_dashed`: Heavy Dashed @@ -506,9 +530,9 @@ Values: 15. `color_types.light_cyan`: Light Cyan 16. `color_types.white`: White -See [here](https://misc.flogisoft.com/bash/tip_colors_and_formatting#foreground_text) for examples of the colors. +See here for [examples of the colors](https://misc.flogisoft.com/bash/tip_colors_and_formatting#foreground_text). -Only used when plotting a single array and when graphing a single function. When plotting multiple arrays or graphing multiple functions, colors 2 - 16 are used inorder. The system default color is used where the plots cross. +This option is only used when plotting a single array and when graphing a single function. When plotting multiple arrays or graphing multiple functions, colors 2 - 16 are used inorder. The system default color is used where the plots cross. ##### Plot diff --git a/tables.cpp b/tables.cpp index 816ecf7..84625af 100644 --- a/tables.cpp +++ b/tables.cpp @@ -9,6 +9,7 @@ #include #include #include + #include "tables.hpp" using namespace std; diff --git a/tables.hpp b/tables.hpp index 3e2c833..4b86a79 100644 --- a/tables.hpp +++ b/tables.hpp @@ -52,7 +52,7 @@ namespace tables bool headercolumn = false; bool tableborder = true; bool cellborder = false; - unsigned int padding = 1; + unsigned padding = 1; ios_base &(*alignment)(ios_base &) = left; bool boolalpha = false; const char *title = nullptr; @@ -177,7 +177,7 @@ namespace tables const bool headercolumn = aoptions.headercolumn; const bool tableborder = aoptions.tableborder; const bool cellborder = aoptions.cellborder; - const unsigned int padding = aoptions.padding; + const unsigned padding = aoptions.padding; const char *const title = aoptions.title; const style_type style = aoptions.style;