From 150b595895204d3c162e87550a0c5166ed1e8a12 Mon Sep 17 00:00:00 2001
From: KireevYP <KireevYP@mpei.ru>
Date: Sun, 21 Apr 2024 22:47:07 +0300
Subject: [PATCH] =?UTF-8?q?svg:=20=D0=BC=D0=B0=D1=81=D1=88=D1=82=D0=B0?=
 =?UTF-8?q?=D0=B1=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 | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/svg.cpp b/svg.cpp
index 81efe64..2e82799 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -39,15 +39,21 @@ show_histogram_svg(const vector<double>& bins) {
     const auto TEXT_WIDTH = 50;
     const auto BIN_HEIGHT = 30;
     const auto BLOCK_WIDTH = 10;
-    string stroke = "black";
-    string fill = "black";
+    const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
+
+    double max_count = (bins[0] * BLOCK_WIDTH);
+    for (double bin: bins){
+        if ((bin * BLOCK_WIDTH) > max_count) {
+            max_count = (bin * BLOCK_WIDTH);
+        }
+    }
 
     svg_begin(400, 300);
     double top = 0;
     for (double bin : bins) {
-        const double bin_width = BLOCK_WIDTH * bin;
+        const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count);
         svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
-        svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
+        svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa");
         top += BIN_HEIGHT;
     }
     svg_end();