diff --git a/svg.cpp b/svg.cpp index f17f5a8..aad6f51 100644 --- a/svg.cpp +++ b/svg.cpp @@ -45,16 +45,20 @@ void show_histogram_svg(const vector& bins) { double top = 0; size_t max_count = bins[0]; + double sum = 0; for (size_t bin : bins) { if (max_count < bin) { max_count = bin; } + sum += bin; } + double average = sum / bins.size(); for (size_t bin : bins) { const double bin_width = MAX_WIDTH * (static_cast(bin) / max_count); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "red"); + string fill_color = (bin > average) ? "red" : "green"; + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill_color); top += BIN_HEIGHT; }