From e2c75ef3abff2ab1803ddf2fdcddf3c20c35c8e6 Mon Sep 17 00:00:00 2001 From: Kuzin Date: Wed, 7 Jun 2023 10:03:43 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 27 +++++++++++++++++++++++---- svg.cpp | 21 +++++++++++++++------ svg.h | 4 ++-- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 9134cfa..bf9f2b4 100644 --- a/main.cpp +++ b/main.cpp @@ -75,16 +75,35 @@ download(const string& adress){ int main(int argc, char* argv[]) { curl_global_init(CURL_GLOBAL_ALL); - Input in; + string color = "base"; + Input in; if (argc > 1) { - in = download(argv[1]); - } else { + for (size_t i = 0; i < argc; i += 1){ + if (strcmp(argv[i], "-fill") == 0){ + if (i - 1 < 1){ + in = download(argv[i + 2]); + color = argv[i + 2]; + } + else{ + if (i + 1 >= argc){ + cerr << "Error: please enter color"; + exit(1); + } + else{ + in = download(argv[i - 1]); + color = argv[i + 1]; + } + } + } + } + } + else { in = input_data(cin, true); } auto bins = make_histogram(in.numbers, in.bin_count); auto borders = make_borders(in.numbers, in.bin_count); - show_histogram_svg(bins, borders, in.bin_count); + show_histogram_svg(bins, borders, in.bin_count, color); getch(); return 0; } diff --git a/svg.cpp b/svg.cpp index 348e9e4..2e89986 100644 --- a/svg.cpp +++ b/svg.cpp @@ -42,8 +42,7 @@ svg_rect(double x, double y, double width, double height, string stroke = "black void -show_histogram_svg(const vector& bins, const vector& borders, size_t bin_count) -{ +show_histogram_svg(const vector& bins, const std::vector& borders, size_t bin_count, string filling) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; const auto TEXT_LEFT = 20; @@ -51,9 +50,8 @@ show_histogram_svg(const vector& bins, const vector& borders, si const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; - const auto COLOUR1 = "black"; - const auto COLOUR2 = "green"; const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH; + vector colors = {"red", "blue", "gold", "lime", "aqua", "green", "orange"}; size_t border = 0; size_t number_of_blocks; @@ -61,6 +59,8 @@ show_histogram_svg(const vector& bins, const vector& borders, si size_t max_bin = *max_element(bins.begin(), bins.end()); double top = 0; + size_t paint_swicher = 0; + string color; double max_count = bins[0]; for (size_t i = 0; i < bins.size(); i++) { @@ -72,14 +72,23 @@ show_histogram_svg(const vector& bins, const vector& borders, si for (size_t bin : bins) { + if (filling != "base"){ + color = filling; + } + else{ + color = colors[paint_swicher]; + } number_of_blocks = bin; if ((max_bin * BLOCK_WIDTH) > (IMAGE_WIDTH - TEXT_WIDTH)){ number_of_blocks = ((IMAGE_WIDTH - TEXT_WIDTH)/10) * (static_cast(bin) / max_bin); } const double bin_width = BLOCK_WIDTH * number_of_blocks; svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, COLOUR1, COLOUR2); - top += BIN_HEIGHT; + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", color); + paint_swicher += 1; + if (paint_swicher > 6){ + paint_swicher = 0; + } if (border < bin_count - 1){ top += BIN_HEIGHT; svg_text(TEXT_LEFT / 2, top + TEXT_BASELINE , to_string(borders[border])); diff --git a/svg.h b/svg.h index 38ceecf..add33f2 100644 --- a/svg.h +++ b/svg.h @@ -3,9 +3,9 @@ #include #include #include - +#include void -show_histogram_svg(const std::vector& bins, const std::vector& borders, size_t bin_count); +show_histogram_svg(const std::vector& bins, const std::vector& borders, size_t bin_count, std::string filling); #endif // SVG_H_INCLUDED