From ce9464276f7f2d9c1736e2918fa217d2f155dd5d Mon Sep 17 00:00:00 2001 From: "Alice (TimoshenkoAA)" Date: Sat, 27 Apr 2024 21:59:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B0=D1=81=D1=88=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab01/svg.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lab01/svg.cpp b/lab01/svg.cpp index 748bf82..b44551c 100644 --- a/lab01/svg.cpp +++ b/lab01/svg.cpp @@ -39,15 +39,21 @@ show_histogram_svg(const vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; - string stroke = "black"; - string fill = "black"; + 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) { + max_count = (bin * BLOCK_WIDTH); + } + } svg_begin(400, 300); double top = 0; for (double bin : bins) { - const double bin_width = BLOCK_WIDTH * bin; + 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, stroke, fill); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa"); top += BIN_HEIGHT; } svg_end();