#include <iostream>
#include <vector>
#include "svg.h"

using namespace std;

void show_histogram_svg(const std::vector<unsigned int>& 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;

    cout << "<?xml version='1.0' encoding='UTF-8'?>" << endl;
    cout << "<svg width='" << IMAGE_WIDTH << "' height='" << IMAGE_HEIGHT << "' xmlns='http://www.w3.org/2000/svg'>" << endl;
    cout << "<rect fill='#eee' stroke='#ccc' width='100%' height='100%'/>" << endl;

    double top = 0;
    for (size_t i = 0; i < bins.size(); i++) {
        top = TEXT_BASELINE + i * BIN_HEIGHT;

        cout << "<text x='" << TEXT_LEFT << "' y='" << top << "'>" << i << "</text>" << endl;

        // зер стл
        for (size_t j = 0; j < bins[i]; j++) {
            // Х право-лево
            size_t x_position = bins[i] - j - 1;
            cout << "<rect x='" << (TEXT_LEFT + TEXT_WIDTH + x_position * BLOCK_WIDTH)
                 << "' y='" << (top - TEXT_BASELINE)
                 << "' width='" << (BLOCK_WIDTH - 1)
                 << "' height='" << (BIN_HEIGHT - 1)
                 << "' fill='blue' stroke='black'/>" << endl;
        }
    }

    cout << "</svg>" << endl;
}
