diff --git a/.gitignore b/.gitignore index 55ef8f6..d78297e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ cs-lab34.cbp cs-lab34.depend unittest.cbp +/unittest.layout /bin /obj diff --git a/main.cpp b/main.cpp index 7ae72b6..8b09bbc 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "histogram.h" #include "text.h" #include "svg.h" @@ -9,6 +10,7 @@ using namespace std; struct Input { vector numbers; + vector colours; size_t bin_count{}; }; @@ -25,6 +27,13 @@ Input input_data() { cin >> in.bin_count; in.numbers.resize(number_count); + in.colours.resize(in.bin_count); + + cerr << "Enter colours: (press A for choose default colour) "; + for (size_t i = 0; i < in.bin_count; i++) + { + cin >> in.colours[i]; + } cerr << "Enter numbers: "; for (size_t i = 0; i < number_count; i++) @@ -46,7 +55,7 @@ int main(){ auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); + show_histogram_svg(bins, in.colours); } diff --git a/svg.cpp b/svg.cpp index dbee47e..fb529cc 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "svg.h" void @@ -22,12 +23,12 @@ svg_text(double left, double baseline, std::string text) { std::cout << " " << text << " "; } -void svg_rect(double x, double y, double width, double height){ - std::cout << ""; +void svg_rect(double x, double y, double width, double height, std::string colour){ + std::cout << ""; } void -show_histogram_svg(const std::vector& bins) { +show_histogram_svg(const std::vector& bins, const std::vector& colours) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; @@ -51,7 +52,11 @@ show_histogram_svg(const std::vector& bins) { for (std::size_t i=0; i < bins.size(); i++) { double bin_width = BLOCK_WIDTH * bins[i]; svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + if (colours[i] != "A") { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, colours[i]); + } else { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "GREEN"); + } top += BIN_HEIGHT; } svg_end(); @@ -59,7 +64,11 @@ show_histogram_svg(const std::vector& bins) { for (std::size_t i=0; i < bins.size(); i++) { double bin_width= MAX_ASTERISK * (static_cast(bins[i]) / maxbin); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + if (colours[i] != "A") { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, colours[i]); + } else { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "GREEN"); + } top += BIN_HEIGHT; } svg_end(); diff --git a/svg.h b/svg.h index c7da98d..b6ba192 100644 --- a/svg.h +++ b/svg.h @@ -2,8 +2,9 @@ #define SVG_H_INCLUDED #include +#include void -show_histogram_svg(const std::vector& bins); +show_histogram_svg(const std::vector& bins, const std::vector& colours); #endif // SVG_H_INCLUDED