#include "text.h"

using namespace std;

void show_histogram_text(const vector<size_t>& bins, size_t bin_count) {
    const size_t SCREEN_WIDTH = 80;
    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;

    size_t max_count = bins[0];
    for (size_t i = 0; i < bin_count; i++)
    {
        if (bins[i] > max_count) {
            max_count = bins[i];
        }
    }

    for (size_t i = 0; i < bin_count; i++)
    {
        if (bins[i]<10) {
            cout << "  " << bins[i] << "|";
            }
        else if (bins[i]<100) {
            cout << " " << bins[i] << "|";
        }
        else if (bins[i]<1000) {
            cout << bins[i] << "|";
        }

        size_t height;

        if (max_count<=MAX_ASTERISK) {
            height = bins[i];
        }
        else {
            height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
        }

        for (size_t j = 0; j < height; j++) {
            cout << "*";
        }
        cout << endl;
    }
}