From f20aee6f7f04b8a0617a58531dfaadd09545ad8f Mon Sep 17 00:00:00 2001 From: ArtyushinaVV Date: Mon, 24 Apr 2023 11:37:29 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=202?= =?UTF-8?q?=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg.cpp | 20 ++++++++------------ svg.h | 2 +- unittest.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) 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) +} +