From 5be7f8fb93690f0696b29a31a57530bbddcd2a1b Mon Sep 17 00:00:00 2001 From: GordiyevskikDA Date: Sat, 16 Mar 2024 16:27:35 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B3?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B=20?= =?UTF-8?q?=D0=B2=20SVG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LABA1.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/LABA1.cpp b/LABA1.cpp index f2241f1..cfa8558 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -1,9 +1,52 @@ #include +#include #include #include "histogram.h" #include "text.h" using namespace std; + +void svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void svg_text(double left, double baseline, string text) { + cout << "" << text <<"\n"; +} + +void svg_rect(double x, double y, double width, double height, string stroke = "red", string fill = "red") { + cout << "\n"; +} + +void svg_end() { + cout << "\n"; +} + +void show_histogram_svg(const vector& marks, const vector& chart) { + 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 (double bin : chart) { + const double bin_width = BLOCK_WIDTH * bin; + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string((int)bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + top += BIN_HEIGHT; + } + svg_end(); +} + + struct Input { vector marks; int NCharts = 0; @@ -25,5 +68,6 @@ int main() { Input in = input_data(); vector chart = MakeHistogram(in.marks, in.NCharts); - show_histogram_text(in.marks, chart); + //show_histogram_text(in.marks, chart); + show_histogram_svg(in.marks, chart); } \ No newline at end of file