From bf531e23faec56b53a5aed625684d610bbd5a928 Mon Sep 17 00:00:00 2001 From: IvanovDA Date: Mon, 29 Apr 2024 14:50:06 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20svg=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=81=D0=B2=D0=BE=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8=D0=B4=D1=83=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/svg.cpp b/svg.cpp index aff8945..75ae8ad 100644 --- a/svg.cpp +++ b/svg.cpp @@ -18,7 +18,7 @@ svg_begin(double width, double height) { cout << "\n"; } @@ -40,13 +40,30 @@ svg_rect(double x, double y, double width, double height) { void show_histogram_svg(const vector& bins) { - double top = 0; + double top = 0.0; + double move = 0.0; svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); + double k = 1.0; + size_t max_bin = bins[0]; for (size_t bin : bins) { - const double bin_width = BLOCK_WIDTH * bin; - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); - top += BIN_HEIGHT; + if (bin > max_bin) { + max_bin = bin; + } + } + if (max_bin * 10 > IMAGE_HEIGHT) { + k = double (IMAGE_HEIGHT - 10) / (max_bin * 10); + } + for (size_t bin : bins) { + svg_text(TEXT_LEFT + move, TEXT_BASELINE, to_string(bin)); + move += BIN_HEIGHT; + } + top += 3*BLOCK_WIDTH; + move = 13.0; + for (size_t bin : bins) { + + const double bin_width = BLOCK_WIDTH * bin * k; + svg_rect(move, top, BIN_HEIGHT, bin_width); + move += BIN_HEIGHT; } svg_end(); } \ No newline at end of file