diff --git a/svg.cpp b/svg.cpp index 78ffcb8..b8a310a 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "svg.h" using namespace std; void @@ -29,13 +30,6 @@ cout << "& bins) { @@ -52,7 +46,7 @@ show_histogram_svg(const vector& bins) { double top = 0; const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; int maxb = bins[0]; - int color; + int color_value; for (size_t j = 1; j < bins.size(); j++) { @@ -65,7 +59,6 @@ show_histogram_svg(const vector& bins) { double bin_width; - color_find(bin, maxb, color); if (maxb1 > MAX_ASTERISK) { @@ -73,9 +66,12 @@ show_histogram_svg(const vector& bins) { } else bin_width = BLOCK_WIDTH * bin; - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "violet", to_string(color)); - top += BIN_HEIGHT; + color_value = (10 - (bin * 9) / maxb); + string color = "#" + to_string(color_value) + to_string(color_value) + to_string(color_value); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "violet", color); + top += BIN_HEIGHT; + } svg_end(); diff --git a/svg.h b/svg.h index a0d983d..5754dcc 100644 --- a/svg.h +++ b/svg.h @@ -3,7 +3,7 @@ using namespace std; void -color_find(double bin, int maxb, int& color); +color_find(vector& bins, int maxb, int& color); void svg_begin(double width, double height); diff --git a/unittest.cpp b/unittest.cpp index df65d28..7e27517 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -34,3 +34,16 @@ TEST_CASE("distinct negative numbers") { CHECK(min == -3); CHECK(max == -1); } + + +TEST_CASE("take color"){ + show_histogram_svg({1,2,3}); + CHECK(color_value>0) +} + + +TEST_CASE("take color"){ + show_histogram_svg({3,4,5,6}); + CHECK(color_value<10) +} +