code: добавлено масштабирование столбцов гистограммы

main
ShchegolikhYR 1 месяц назад
Родитель c1b1f9b4cd
Сommit 8ddec8f599

@ -29,11 +29,19 @@ void show_histogram_svg(const vector<size_t>& bins) {
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
const auto MAX_BIN_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
auto max_bins = bins[0];
for (size_t bin : bins) {
if (bin > max_bins) max_bins = bin;
}
auto koef = MAX_BIN_WIDTH / BLOCK_WIDTH / max_bins;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
const double bin_width = BLOCK_WIDTH * bin * koef;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;

Загрузка…
Отмена
Сохранить