From e8b58d50badf7006b7067df6e82d5fb0238127be Mon Sep 17 00:00:00 2001 From: KhodiukMR Date: Mon, 29 Apr 2024 16:37:52 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=82=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9(=D1=81=D0=BE=D0=B3=D0=BB=D0=B0=D1=81=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D1=83=2010)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/svg.cpp b/svg.cpp index 7fba8f8..64380e5 100644 --- a/svg.cpp +++ b/svg.cpp @@ -38,25 +38,25 @@ void SvgRect(double x, double y, double width, double height, string stroke = "b void ShowHistogramSvg(const vector& bins) { - double top = 0; - SvgBegin(400, 300); - - size_t MaxCount = 0; - for (auto bin : bins) { - if (MaxCount < bin) { - MaxCount = bin; + double move = 0; + SvgBegin(IMAGE_WIDTH, IMAGE_HEIGHT); + double k = 1; + size_t max_bin = bins[0]; + for (size_t bin : bins) { + if (bin > max_bin) { + max_bin = bin; } } - int k = (IMAGE_WIDTH - TEXT_WIDTH) / MaxCount * BLOCK_WIDTH; + if (max_bin * 10 > IMAGE_HEIGHT) { + k = double(IMAGE_HEIGHT - TEXT_WIDTH) / (max_bin * 10); + } if (k > 1) k = 1; - for (size_t bin : bins) { - bin = bin * k; - const double bin_width = BLOCK_WIDTH * bin; - SvgText(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - SvgRect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", "#FF69B4"); - top += BIN_HEIGHT; + const double bin_width = BLOCK_WIDTH * bin * k; + SvgText(TEXT_LEFT + move, TEXT_BASELINE, to_string(bin)); + SvgRect(move+13, 3*BLOCK_WIDTH, BIN_HEIGHT, bin_width,"red","#FFD700"); + move += BIN_HEIGHT; } SvgEnd(); }