From 3dae9289ff989837f1aac305ff935dc1e4d2ac0e Mon Sep 17 00:00:00 2001 From: MatusSV Date: Mon, 13 May 2024 10:25:42 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=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=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B3=D0=B8=D1=81=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0=20SVG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1.cbp | 2 ++ svg.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Lab1.cbp b/Lab1.cbp index 0277582..b1a3849 100644 --- a/Lab1.cbp +++ b/Lab1.cbp @@ -38,6 +38,8 @@ + + diff --git a/svg.cpp b/svg.cpp index b37f5a1..1c62c07 100644 --- a/svg.cpp +++ b/svg.cpp @@ -48,6 +48,20 @@ show_histogram_svg(const vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH; + size_t max_count = 0; + for (size_t x : bins) { + if (x > max_count) { + max_count = x; + } + } + if (max_count == 0) { + max_count = 1; + } + auto scale_factor = static_cast(MAX_WIDTH) / (max_count * BLOCK_WIDTH); + if (scale_factor > 1) { + scale_factor = 1; + } svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); double top = 0; for (size_t bin : bins) {