From 0fb272d86218955c7f94cfe2ff18edbf3ee8a312 Mon Sep 17 00:00:00 2001 From: BezhenarAN Date: Sun, 19 May 2024 14:59:47 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B=20=D0=BD=D0=B0=20=D0=BE=D1=80=D0=B8=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D1=8E(=D0=BD=D0=B5=20=D0=B2=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B0=D0=BD=D1=82=20=D0=B8=D0=B7=203=20=D0=BB=D0=B0=D0=B1.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 8 +------- svg.cpp | 35 +++-------------------------------- svg.h | 2 +- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/main.cpp b/main.cpp index 498a824..e2b7482 100644 --- a/main.cpp +++ b/main.cpp @@ -12,7 +12,6 @@ using namespace std; struct Input { vector numbers; size_t bin_count{}; - double USER_BIN_HEIGHT{}; }; Input input_data(istream& stream, bool prompt) { @@ -41,11 +40,6 @@ Input input_data(istream& stream, bool prompt) { } stream >> in.bin_count; - if (prompt){ - cerr << "Enter image height: "; - } - stream >> in.USER_BIN_HEIGHT; - return in; } @@ -78,7 +72,7 @@ int main(int argc, char* argv[]){ auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins, in.USER_BIN_HEIGHT); + show_histogram_svg(bins); } diff --git a/svg.cpp b/svg.cpp index f0ea4ab..3c2b78c 100644 --- a/svg.cpp +++ b/svg.cpp @@ -26,34 +26,8 @@ void svg_rect(double x, double y, double width, double height){ std::cout << ""; } -double calculate_bin_height (const std::vector& bins, double USER_BIN_HEIGHT, double IMAGE_HEIGHT){ - - double BIN_HEIGHT; - - if ( USER_BIN_HEIGHT < 0 ){ - - BIN_HEIGHT = 0; - - } else { - - 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(); - } - - return BIN_HEIGHT; - -} - void -show_histogram_svg(const std::vector& bins, double USER_BIN_HEIGHT) { +show_histogram_svg(const std::vector& bins) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 700; @@ -61,16 +35,13 @@ show_histogram_svg(const std::vector& bins, double USER_BIN_HEIGHT) const auto TEXT_BASELINE = 20; const auto TEXT_WIDTH = 50; const auto BLOCK_WIDTH = 10; + const auto BIN_HEIGHT = 50; - auto BIN_HEIGHT = calculate_bin_height (bins, USER_BIN_HEIGHT, IMAGE_HEIGHT); - - auto USER_IMAGE_HEIGHT = bins.size() * BIN_HEIGHT; - const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; - svg_begin(IMAGE_WIDTH, USER_IMAGE_HEIGHT); + svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); double top = 0; diff --git a/svg.h b/svg.h index 7d9b273..c7da98d 100644 --- a/svg.h +++ b/svg.h @@ -4,6 +4,6 @@ #include void -show_histogram_svg(const std::vector& bins, double USER_BIN_HEIGHT); +show_histogram_svg(const std::vector& bins); #endif // SVG_H_INCLUDED