From 3e45abdc53562c51898f7b62c246db168a722b99 Mon Sep 17 00:00:00 2001 From: LedovskojMM Date: Sun, 28 May 2023 12:23:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=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=B4=D0=BE=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=B2?= =?UTF-8?q?=D0=B8=D0=B4=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab1.depend | 4 ++-- lab1.layout | 2 +- main.cpp | 2 +- svg.cpp | 25 ++++++++++++++++++++++--- unittest.layout | 5 +++++ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 unittest.layout diff --git a/lab1.depend b/lab1.depend index 9a01243..fdb4d65 100644 --- a/lab1.depend +++ b/lab1.depend @@ -3,7 +3,7 @@ -1682281166 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp +1682338069 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp @@ -37,7 +37,7 @@ 1682273796 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h -1682280585 source:c:\users\admin\onedrive\Рабочий стол\lab1\svg.cpp +1682339808 source:c:\users\admin\onedrive\Рабочий стол\lab1\svg.cpp diff --git a/lab1.layout b/lab1.layout index fdcb6d6..5c910e8 100644 --- a/lab1.layout +++ b/lab1.layout @@ -4,7 +4,7 @@ - + diff --git a/main.cpp b/main.cpp index cbc6fa6..d399bf6 100644 --- a/main.cpp +++ b/main.cpp @@ -26,7 +26,7 @@ input_data() { cin >> in.numbers[i]; } - cout << "Enter number of bins"; + cerr<< "Enter number of bins"; cin >> in.bin_count; return in; } diff --git a/svg.cpp b/svg.cpp index f32c103..f81e0c2 100644 --- a/svg.cpp +++ b/svg.cpp @@ -26,12 +26,31 @@ svg_text(double left, double baseline, string text) { cout << "" << text << ""; } - - +void svg_rect(double x, double y, double width, double height, string colour = "black", string fill = "black"){ + cout << ""; +} void show_histogram_svg(const vector& bins) { + const auto IMAGE_WIDTH = 400; + const auto IMAGE_HEIGHT = 300; + 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; + double top = 0; + double max_count = bins[0]; + for (size_t i = 0; i < bins.size(); i++) { + if (bins[i] > max_count) + max_count = bins[i]; + } svg_begin(400, 300); - svg_text(20, 20, to_string(bins[0])); + for (size_t bin : bins) { + const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF"); + top += BIN_HEIGHT; + } svg_end(); } diff --git a/unittest.layout b/unittest.layout new file mode 100644 index 0000000..593c06e --- /dev/null +++ b/unittest.layout @@ -0,0 +1,5 @@ + + + + +