From dd5f5263719be3e625e9a30512e4402ae3005020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Sun, 23 Apr 2023 19:47:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B8=D0=BD=D0=B4.=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F(=D0=92=D0=B0=D1=80=D0=B8=D0=B0=D0=BD?= =?UTF-8?q?=D1=824)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programm/svg.cpp | 16 ++++++++++++++-- Programm/text.cpp | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Programm/svg.cpp b/Programm/svg.cpp index 0837c45..d89966f 100644 --- a/Programm/svg.cpp +++ b/Programm/svg.cpp @@ -23,7 +23,7 @@ void svg_text(double left, double baseline, std::string text) void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black") { - std::cout << ""; } @@ -45,13 +45,25 @@ void show_histogram_svg(const std::vector &bins) if (bin > max_count) max_count = bin; } - const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / max_count; + const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH * 2 - TEXT_LEFT) / max_count; + const auto TEXT_RATIO_SHIFT = IMAGE_WIDTH - TEXT_WIDTH; + auto summ = 0; + for (size_t bin : bins) + { + summ += bin; + } for (size_t bin : bins) { const double bin_width = BLOCK_WIDTH * bin; svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa"); + auto ratio = (bin * 100) / summ; + if (bin == bins.back() && summ % 2 != 0) + { + ratio ++; + } + svg_text(TEXT_RATIO_SHIFT, top + TEXT_BASELINE, (std::to_string(ratio) + "%")); top += BIN_HEIGHT; } // svg_text(20, 20, std::to_string(bins[0])); diff --git a/Programm/text.cpp b/Programm/text.cpp index d32b4eb..037f0eb 100644 --- a/Programm/text.cpp +++ b/Programm/text.cpp @@ -4,7 +4,7 @@ void show_histogram_text(const std::vector &bins, const std::vector