ind: индивидуальный вариант вар 7

master
Alice (TimoshenkoAA) 1 год назад
Родитель ce9464276f
Сommit c38bdca7b9

@ -39,8 +39,8 @@ show_histogram_svg(const vector<double>& bins) {
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
double average = 0, sum =0, scale=1;
const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
double max_count = (bins[0] * BLOCK_WIDTH);
for (double bin: bins){
if ((bin * BLOCK_WIDTH) > max_count) {
@ -50,10 +50,19 @@ show_histogram_svg(const vector<double>& bins) {
svg_begin(400, 300);
double top = 0;
for (double x : bins) {
sum += x;
}
average = sum / bins.size();
for (double bin : bins) {
const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa");
if (bin > average) {
svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "red");
}
else {
svg_rect(TEXT_WIDTH, top, bin_width / scale, BIN_HEIGHT, "yellow", "green");
}
top += BIN_HEIGHT;
}
svg_end();

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