From 549f896fc536cb6e9cb396e0e22c1f1944534c90 Mon Sep 17 00:00:00 2001 From: Yarocvet Date: Sat, 10 Jun 2023 02:19:31 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=B4=D0=BE=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8=D0=B4=D1=83=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab3.depend | 14 ++++++++++++-- main.cpp | 3 ++- svg.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ svg.h | 9 +++++++++ text.cpp | 4 ++-- 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 svg.cpp create mode 100644 svg.h diff --git a/lab3.depend b/lab3.depend index 0000d22..1c68264 100644 --- a/lab3.depend +++ b/lab3.depend @@ -1,8 +1,9 @@ # depslib dependency file v1.0 -1686343289 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp +1686350213 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp "histogram.h" "text.h" + "svg.h" 1686342281 source:c:\users\kostello\desktop\lubs\lab03.2\histogram.cpp "histogram.h" @@ -10,10 +11,19 @@ 1686342254 c:\users\kostello\desktop\lubs\lab03.2\histogram.h -1686342636 source:c:\users\kostello\desktop\lubs\lab03.2\text.cpp +1686349618 source:c:\users\kostello\desktop\lubs\lab03.2\text.cpp "text.h" + 1686343275 c:\users\kostello\desktop\lubs\lab03.2\text.h +1686349467 c:\users\kostello\desktop\lubs\lab03.2\svg.h + + + +1686349791 source:c:\users\kostello\desktop\lubs\lab03.2\svg.cpp + "svg.h" + + diff --git a/main.cpp b/main.cpp index 229373f..4d721e6 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; @@ -42,7 +43,7 @@ int main() { auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins, in.bin_count); + show_histogram_svg(bins); return 0; } diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..c619323 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,53 @@ +#include "svg.h" +#include + + +using namespace std; + +void +svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void +svg_end() { + cout << "\n"; +} + +void +svg_text(double left, double baseline, string text) { + cout << "" << text << ""; +} + +void svg_rect(double x, double y, double width, double height, string stroke, string fill){ +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; + + svg_begin(400, 300); + double top = 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, "red", "#ffeeee"); + top += BIN_HEIGHT; + } + svg_end(); +} + diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..06048d0 --- /dev/null +++ b/svg.h @@ -0,0 +1,9 @@ +#ifndef SVG_H_INCLUDED +#define SVG_H_INCLUDED + +#include +#include + +void show_histogram_svg(const std::vector& bins); + +#endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp index 9ec5fd4..ac1e7b7 100644 --- a/text.cpp +++ b/text.cpp @@ -1,7 +1,7 @@ #include "text.h" -#include + #include -#include + using namespace std;