From 8ddec8f5996ff645851111641c515f40921dc6fb Mon Sep 17 00:00:00 2001 From: ShchegolikhYR Date: Fri, 2 May 2025 11:44:03 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?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=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D0=B1=D1=86=D0=BE=D0=B2=20=D0=B3=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/svg.cpp b/svg.cpp index 35cad9a..ceb521f 100644 --- a/svg.cpp +++ b/svg.cpp @@ -29,11 +29,19 @@ void show_histogram_svg(const vector& bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + const auto MAX_BIN_WIDTH = IMAGE_WIDTH - TEXT_WIDTH; + auto max_bins = bins[0]; + + for (size_t bin : bins) { + if (bin > max_bins) max_bins = bin; + } + + auto koef = MAX_BIN_WIDTH / BLOCK_WIDTH / max_bins; svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); double top = 0; for (size_t bin : bins) { - const double bin_width = BLOCK_WIDTH * bin; + const double bin_width = BLOCK_WIDTH * bin * koef; svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); top += BIN_HEIGHT;