From 773017839cc2074cdefc348af6e3e04018e1ef26 Mon Sep 17 00:00:00 2001 From: BezhenarAN Date: Sun, 5 May 2024 19:24:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D0=BD=D0=BA=D1=82=20(=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B0=D0=BD=D1=82=203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 6 +++++- svg.cpp | 16 ++++++++++++---- svg.h | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 7ae72b6..af7a402 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ using namespace std; struct Input { vector numbers; size_t bin_count{}; + size_t USER_BIN_HEIGHT{}; }; Input input_data() { @@ -32,6 +33,9 @@ Input input_data() { cin >> in.numbers[i]; } + cerr << "Enter image height: "; + cin >> in.USER_BIN_HEIGHT; + return in; } @@ -46,7 +50,7 @@ int main(){ auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); + show_histogram_svg(bins, in.USER_BIN_HEIGHT); } diff --git a/svg.cpp b/svg.cpp index dbee47e..96d572a 100644 --- a/svg.cpp +++ b/svg.cpp @@ -27,19 +27,27 @@ void svg_rect(double x, double y, double width, double height){ } void -show_histogram_svg(const std::vector& bins) { +show_histogram_svg(const std::vector& bins, std::size_t USER_BIN_HEIGHT) { const auto IMAGE_WIDTH = 400; - const auto IMAGE_HEIGHT = 300; + const auto IMAGE_HEIGHT = 700; const auto TEXT_LEFT = 20; const auto TEXT_BASELINE = 20; const auto TEXT_WIDTH = 50; - const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; + auto BIN_HEIGHT = USER_BIN_HEIGHT; + auto USER_IMAGE_HEIGHT = bins.size() * BIN_HEIGHT; + + if (USER_IMAGE_HEIGHT > IMAGE_HEIGHT){ + BIN_HEIGHT = IMAGE_HEIGHT / bins.size(); + } + const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; - svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); + svg_begin(IMAGE_WIDTH, USER_IMAGE_HEIGHT); double top = 0; + + std::size_t maxbin=bins[0]; for (std::size_t i=0; i < bins.size(); i++){ if (maxbin < bins[i]){ diff --git a/svg.h b/svg.h index c7da98d..a80dc65 100644 --- a/svg.h +++ b/svg.h @@ -4,6 +4,6 @@ #include void -show_histogram_svg(const std::vector& bins); +show_histogram_svg(const std::vector& bins, std::size_t USER_BIN_HEIGHT); #endif // SVG_H_INCLUDED