pic: Добавлено масштабирование

main
Ишутина Елизавета 2 лет назад
Родитель 9279645ea9
Сommit d8a59fdb67

@ -34,10 +34,16 @@ show_histogram_svg(const vector <size_t> &bins) {
const auto TEXT_WIDTH = 50; const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10; const auto BLOCK_WIDTH = 10;
const auto MAX_VALUE = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0; double top = 0;
size_t max_count = 0;
for (auto now: bins)
{if (now > max_count) {max_count = now;}}
for (size_t bin : bins){ for (size_t bin : bins){
const double bin_width = BLOCK_WIDTH * bin; double bin_width = BLOCK_WIDTH * bin;
if (bin == max_count) {bin_width = MAX_VALUE * 1.0;}
else {bin_width = MAX_VALUE * (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); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT; top += BIN_HEIGHT;

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