diff --git a/svg.cpp b/svg.cpp index 19eb452..13e3106 100644 --- a/svg.cpp +++ b/svg.cpp @@ -32,8 +32,15 @@ void show_histogram_svg(const vector& bins) { double top = 0; const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); - double top = 0; + double max_count; + max_count = bins[0]; + for (double x : bins) { + if (x > max_count) { + max_count = x; + } + } + string fill; size_t maxbin=bins[0]; for (size_t i=0; i < bins.size(); i++){ if (maxbin < bins[i]){ @@ -45,7 +52,8 @@ void show_histogram_svg(const vector& bins) { for (size_t i=0; i < bins.size(); i++) { double bin_width = BLOCK_WIDTH * bins[i]; svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + fill = "#" + to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill); top += BIN_HEIGHT; } svg_end(); @@ -53,7 +61,8 @@ void show_histogram_svg(const vector& bins) { for (size_t i=0; i < bins.size(); i++) { double bin_width= MAX_ASTERISK * (static_cast(bins[i]) / maxbin); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + fill = "#" + to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill); top += BIN_HEIGHT; } }