|
|
@ -27,13 +27,13 @@ std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bi
|
|
|
|
double min, max;
|
|
|
|
double min, max;
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
if (max == min) {
|
|
|
|
if (max == min) {
|
|
|
|
return bins; // Возвращаем пустые корзины, findтак как гистограмма не может быть построена
|
|
|
|
return bins;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double bin_width = (max - min) / bin_count;
|
|
|
|
double bin_width = (max - min) / bin_count;
|
|
|
|
for (double number : numbers) {
|
|
|
|
for (double number : numbers) {
|
|
|
|
size_t bin_index = static_cast<size_t>((number - min) / bin_width);
|
|
|
|
size_t bin_index = static_cast<size_t>((number - min) / bin_width);
|
|
|
|
if (bin_index >= bin_count) {
|
|
|
|
if (bin_index >= bin_count) {
|
|
|
|
bin_index = bin_count - 1; // Обработка крайнего случая max == number
|
|
|
|
bin_index = bin_count - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bins[bin_index]++;
|
|
|
|
bins[bin_index]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,7 +54,7 @@ void show_histogram_svg(const std::vector<size_t>& bins) {
|
|
|
|
const double bin_width = BLOCK_WIDTH * bins[i];
|
|
|
|
const double bin_width = BLOCK_WIDTH * bins[i];
|
|
|
|
const double top = i * BIN_HEIGHT;
|
|
|
|
const double top = i * BIN_HEIGHT;
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#aaffaa"); // Пример цвета
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#aaffaa");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
svg_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|