code: финальная версия 2 вариант

master
ArtyushinaVV 2 лет назад
Родитель 560d928711
Сommit f20aee6f7f

@ -1,6 +1,7 @@
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include "svg.h"
using namespace std;
void
@ -29,13 +30,6 @@ cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"'
}
void color_find(double bin, int maxb, int& color){
color = (10 - (bin * 9) / maxb);
if (color < 0) { cout << "cant take color";
color = 9;
}
}
void
show_histogram_svg(const vector<size_t>& bins) {
@ -52,7 +46,7 @@ show_histogram_svg(const vector<size_t>& 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<size_t>& bins) {
double bin_width;
color_find(bin, maxb, color);
if (maxb1 > MAX_ASTERISK)
{
@ -73,9 +66,12 @@ show_histogram_svg(const vector<size_t>& 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();

@ -3,7 +3,7 @@
using namespace std;
void
color_find(double bin, int maxb, int& color);
color_find(vector<size_t>& bins, int maxb, int& color);
void
svg_begin(double width, double height);

@ -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)
}

Загрузка…
Отмена
Сохранить