svg: масштабирование

main
KireevYP 1 год назад
Родитель ff87a522c9
Сommit 150b595895

@ -39,15 +39,21 @@ show_histogram_svg(const vector<double>& bins) {
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
string stroke = "black";
string fill = "black";
const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
double max_count = (bins[0] * BLOCK_WIDTH);
for (double bin: bins){
if ((bin * BLOCK_WIDTH) > max_count) {
max_count = (bin * BLOCK_WIDTH);
}
}
svg_begin(400, 300);
double top = 0;
for (double bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa");
top += BIN_HEIGHT;
}
svg_end();

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