diff --git a/svg01.cpp b/svg01.cpp index 9aa27ab..f0714c1 100644 --- a/svg01.cpp +++ b/svg01.cpp @@ -42,8 +42,14 @@ show_histogram_svg(const vector& bins) { svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); double top = 0; + double maxel = bins[0]; for (size_t bin : bins) { - const double bin_width = BLOCK_WIDTH * bin; + if (maxel > bin){ + maxel = bin; + } + } + for (size_t bin : bins) { + const double bin_width = (( IMAGE_WIDTH - TEXT_WIDTH ) / BLOCK_WIDTH ) * ( bin / maxel ); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); top += BIN_HEIGHT; @@ -51,3 +57,5 @@ show_histogram_svg(const vector& bins) { svg_end(); } + +