From d8a59fdb67217740690bd949fcb64af33d207cf9 Mon Sep 17 00:00:00 2001 From: IshutinaYI Date: Sun, 23 Apr 2023 18:24:05 +0300 Subject: [PATCH] =?UTF-8?q?pic:=20=D0=94=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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/svg.cpp b/svg.cpp index e15ff44..cbbb04c 100644 --- a/svg.cpp +++ b/svg.cpp @@ -34,10 +34,16 @@ show_histogram_svg(const vector &bins) { const auto TEXT_WIDTH = 50; const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + const auto MAX_VALUE = IMAGE_WIDTH - TEXT_WIDTH; svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); double top = 0; + size_t max_count = 0; + for (auto now: bins) + {if (now > max_count) {max_count = now;}} for (size_t bin : bins){ - const double bin_width = BLOCK_WIDTH * bin; + double bin_width = BLOCK_WIDTH * bin; + if (bin == max_count) {bin_width = MAX_VALUE * 1.0;} + else {bin_width = MAX_VALUE * (static_cast (bin) / max_count);} svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); top += BIN_HEIGHT;