From c38bdca7b9b78e53ebd2849f3d852eec5ac661fa Mon Sep 17 00:00:00 2001 From: "Alice (TimoshenkoAA)" Date: Mon, 29 Apr 2024 14:52:21 +0300 Subject: [PATCH] =?UTF-8?q?ind:=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8?= =?UTF-8?q?=D0=B4=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D0=B2=D0=B0=D1=80=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab01/svg.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lab01/svg.cpp b/lab01/svg.cpp index b44551c..e9695df 100644 --- a/lab01/svg.cpp +++ b/lab01/svg.cpp @@ -39,8 +39,8 @@ show_histogram_svg(const vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + double average = 0, sum =0, scale=1; const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH); - double max_count = (bins[0] * BLOCK_WIDTH); for (double bin: bins){ if ((bin * BLOCK_WIDTH) > max_count) { @@ -50,10 +50,19 @@ show_histogram_svg(const vector& bins) { svg_begin(400, 300); double top = 0; + for (double x : bins) { + sum += x; + } + 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)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa"); + if (bin > average) { + svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "red"); + } + else { + svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "green"); + } top += BIN_HEIGHT; } svg_end();