diff --git a/svg.cpp b/svg.cpp index 35cad9a..ceb521f 100644 --- a/svg.cpp +++ b/svg.cpp @@ -29,11 +29,19 @@ void show_histogram_svg(const vector& 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;