From 3327f8a5968634f944a43ca7c0aa2efde5197999 Mon Sep 17 00:00:00 2001 From: ChernyukVS Date: Tue, 16 Sep 2025 17:56:27 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 svg.cpp diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..cbdc05d --- /dev/null +++ b/svg.cpp @@ -0,0 +1,69 @@ +#include +#include +#include "svg.h" +#include +#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, const string &text) { + cout << "" << text << "\n"; +} + +void svg_rect(double x, double y, double width, double height, + string stroke = "black", string fill = "black") { + cout << "\n"; +} + +void show_histogram_svg(const vector& bins) { + const auto IMAGE_WIDTH = 800; + const auto IMAGE_HEIGHT = 600; + const auto TEXT_LEFT = 30; + const auto TEXT_BASELINE = 20; + const auto TEXT_WIDTH = 50; + const auto BIN_HEIGHT = 40; + + svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); + + size_t max_bin = 0; + if (!bins.empty()) { + max_bin = *max_element(bins.begin(), bins.end()); + } + + + cout << "// Debug: max_bin = " << max_bin << endl; + + double max_bar_width = IMAGE_WIDTH - TEXT_WIDTH ; + double scaling_factor = 1.0; + if (max_bin > 0) { + scaling_factor = max_bar_width / static_cast(max_bin); + + cout << "// Debug: scaling_factor = " << scaling_factor << endl; + } + + double top = 0; + for (size_t bin : bins) { + double bar_width = bin * scaling_factor; + svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); + svg_rect(TEXT_WIDTH, top, bar_width, BIN_HEIGHT, "pink", "000000"); + top += BIN_HEIGHT; + } + + svg_end(); +}