From 0af2ad9d0780c4bd5afb3c35dc94beab18b44142 Mon Sep 17 00:00:00 2001 From: "Alice (TimoshenkoAA)" Date: Sat, 25 May 2024 12:43:11 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=BE=D1=88=D0=BB=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab01/main.cpp | 1 + lab01/svg.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lab01/main.cpp b/lab01/main.cpp index 7c9247e..4bbab47 100644 --- a/lab01/main.cpp +++ b/lab01/main.cpp @@ -36,6 +36,7 @@ int main() { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + bool prompt = true; auto in = input_data(cin, prompt); auto bins = make_histogram(in.numbers, in.bin_count); diff --git a/lab01/svg.cpp b/lab01/svg.cpp index e9695df..434873e 100644 --- a/lab01/svg.cpp +++ b/lab01/svg.cpp @@ -41,12 +41,19 @@ show_histogram_svg(const vector& bins) { const auto BLOCK_WIDTH = 10; double average = 0, sum =0, scale=1; const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH); + double sum = 0; double max_count = (bins[0] * BLOCK_WIDTH); for (double bin: bins){ if ((bin * BLOCK_WIDTH) > max_count) { max_count = (bin * BLOCK_WIDTH); } } + for (double bin: bins){ + sum = sum + (MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count)); + } + + double avg_width = sum/bins.size(); + svg_begin(400, 300); double top = 0; @@ -56,7 +63,12 @@ show_histogram_svg(const vector& bins) { average = sum / bins.size(); for (double bin : bins) { const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count); - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + if (bin_width > avg_width){ + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#e71320"); + } + else { + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#2fe713"); + } if (bin > average) { svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "red"); }