From 1b67cc676715bdbba2133a3e486b43a093bdda62 Mon Sep 17 00:00:00 2001 From: Jan Kuhlmann <33833587+M2-TE@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:07:10 +0100 Subject: [PATCH] changed signature of single+multi histo draw --- graphs.hpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/graphs.hpp b/graphs.hpp index 8763ae3..dfc2e2e 100644 --- a/graphs.hpp +++ b/graphs.hpp @@ -171,8 +171,6 @@ namespace graphs bool check = true; }; - - // Number of columns needed to represent the string // Adapted from: https://stackoverflow.com/a/31124065 inline int strcol(const string &str) @@ -787,24 +785,21 @@ namespace graphs struct Axis { double min = 0; // Start of axis. Set to 0 for automatic size based on data. double max = 0; // End of axis. Set to 0 for automatic size based on data. - bool enabled = true; - bool label = true; + bool drawn = true; + bool label = true; // TODO: allow setting custom label string? bool ticks = true; bool tick_labels = true; units_type tick_label_type = units_fracts; }; Axis x = {}; Axis y = {}; - + type_type character_set = type_braille; style_type style = style_light; - ColorBits color_type = ColorBits::e4; + ColorBits color_type = ColorBits::e4; // bit depth of color representation bool validate = true; // validate sizes for graph draw - bool border = false; - - // some idea?: - std::vector colors; - std::vector x_offset; // x-axis offset for each data point of graph at that index + bool border = false; // draw border around the graph + /* 5 bytes padding */ // graph-specific options struct Histogram { @@ -814,8 +809,9 @@ namespace graphs std::ostream &ostr = std::cout; const char* title = nullptr; }; + // print histogram using single data set, drawn on top of existing texture template - auto histogram_experimental(const Options& options, const std::vector& data, const Color& color = {color_red}, Texture&& texture = std::make_unique>()) -> Texture&& { + auto histogram_experimental(const std::vector& data, Texture&& texture, const Options& options = {}, const Color& color = {color_red}) -> Texture&& { static_assert(std::numeric_limits::is_integer, "Only integer types are supported for histogram data"); cout << "Experimental histogram\n"; @@ -909,16 +905,26 @@ namespace graphs } return std::move(texture); } - // print histogram using multiple data sets + // print histogram using single data set template - void histogram_experimental(const Options& options, const std::vector>& datasets, const std::vector& colors = {}) { - Texture texture = std::make_unique>(); - // recursively call for extra data sets + auto histogram_experimental(const std::vector& data, const Options& options = {}, const Color& color = {color_red}) -> Texture&& { + return histogram_experimental(data, std::make_unique(), options, color); + } + // print histogram using multiple data sets, drawn on top of existing texture + template + auto histogram_experimental(const std::vector>& datasets, Texture&& texture, const Options& options = {}, const std::vector& colors = {}) -> Texture&& { + // recursively call for each data set for (size_t i = 0; i < datasets.size(); i++) { // pick default color if not enough colors are provided Color color = i < colors.size() ? colors[i] : Color{color_red}; - texture = histogram_experimental(options, datasets[i], color, std::move(texture)); + texture = histogram_experimental(datasets[i], std::move(texture), options, colors[i]); } + return std::move(texture); + } + // print histogram using multiple data sets + template + auto histogram_experimental(const std::vector>& datasets, const Options& options = {}, const std::vector& colors = {}) -> Texture&& { + return histogram_experimental(datasets, std::make_unique(), options, colors); } // EXPERIMENTAL END