Пользователь № 10 аудитории Ж-115 4 месяцев назад
Родитель 0811f94592 78090ebb98
Сommit 13dd4af630

@ -45,16 +45,20 @@ void show_histogram_svg(const vector<size_t>& bins) {
double top = 0; double top = 0;
size_t max_count = bins[0]; size_t max_count = bins[0];
double sum = 0;
for (size_t bin : bins) { for (size_t bin : bins) {
if (max_count < bin) { if (max_count < bin) {
max_count = bin; max_count = bin;
} }
sum += bin;
} }
double average = sum / bins.size();
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count); const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "red"); string fill_color = (bin > average) ? "red" : "green";
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill_color);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }

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