From c130a5db8683fdbace118fd6d74c4d9c5b6fb57d Mon Sep 17 00:00:00 2001 From: "lab34 (BakaikinKV)" Date: Wed, 16 Apr 2025 19:15:03 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20svg.h=20svg.cpp=20=D0=B8=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=20main.cpp(show=5Fhistogram=5Fsvg)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 4 +-- svg.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ svg.h | 9 +++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 svg.cpp create mode 100644 svg.h diff --git a/main.cpp b/main.cpp index 86eba5f..198e246 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" using namespace std; struct Input { @@ -20,7 +21,6 @@ input_data(){ cerr << "Enter Num[" << i << "]: "; cin >> in.numbers[i]; } - cerr << "Enter bin count: "; cin >> bin_count; cerr << "Enter bin count: "; cin >> in.bin_count; return in; @@ -33,7 +33,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..2cc6d1d --- /dev/null +++ b/svg.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include "svg.h" + +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 = "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; + const auto BLACK = "black"; + const auto RED = "red"; + const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH; + + + svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); + + double top = 0; + double max_count = bins[0]; + for (size_t i = 0; i < bins.size(); i++) + { + if (max_count + +void +show_histogram_svg(const std::vector& bins); + + +#endif // SVG_H_INCLUDED