#include "svg.h" #include #include using namespace std; namespace svg { void begin(ostream& out, double width, double height) { out << "\n"; out << "\n"; } void end(ostream& out) { out << "\n"; } void text(ostream& out, double left, double baseline, const string& text) { out << "" << text << "\n"; } void rect(ostream& out, double x, double y, double width, double height, const string& stroke, const string& fill) { out << "\n"; } void line(ostream& out, double x1, double y1, double x2, double y2, const string& stroke, int dash_length, int gap_length) { out << "\n"; } void show_histogram_svg(ofstream& out, const vector& bins, int dash_length, int gap_length) { begin(out, IMAGE_WIDTH, IMAGE_HEIGHT); if (bins.empty()) { end(out); return; } size_t max_count = *max_element(bins.begin(), bins.end()); if (max_count == 0) { end(out); return; } // Увеличиваем максимальную ширину для лучшего отображения double max_width = IMAGE_WIDTH - TEXT_WIDTH - 100; double scale = max_width / max_count; double top = 0; for (size_t bin : bins) { double width = bin * scale; // Подпись значения (крупнее и четче) out << "" << bin << "\n"; // Основной столбец rect(out, TEXT_WIDTH, top, width, BIN_HEIGHT, "#333333", "#4CAF50"); // Пунктирная линия (толще и контрастнее) out << "\n"; top += BIN_HEIGHT + 10; // Добавляем отступ между столбцами } // Добавляем рамку вокруг всей гистограммы out << "\n"; end(out); } }