KalenskovaDA 2 дней назад
Родитель fd47eaab64
Сommit 703a7496c9

@ -92,7 +92,7 @@
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h 1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
<vector> <vector>
1749627705 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp 1749630788 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp
<iostream> <iostream>
<vector> <vector>
<string> <string>

@ -1,5 +1,6 @@
#include "svg.h" #include "svg.h"
#include <iostream> #include <iostream>
#include <numeric>
using namespace std; using namespace std;
void svg_begin(double width, double height) { void svg_begin(double width, double height) {
@ -10,7 +11,8 @@ void svg_begin(double width, double height) {
// Ñòèëè äëÿ SVG // Ñòèëè äëÿ SVG
cout << "<style>\n" cout << "<style>\n"
<< " .bar { fill: #4CAF50; stroke: #388E3C; stroke-width: 1; }\n" << " .bar-green { fill: #4CAF50; stroke: #388E3C; stroke-width: 1; }\n"
<< " .bar-red { fill: #F44336; stroke: #D32F2F; stroke-width: 1; }\n"
<< " .text { font: 12px sans-serif; fill: #333; }\n" << " .text { font: 12px sans-serif; fill: #333; }\n"
<< "</style>\n"; << "</style>\n";
} }
@ -24,9 +26,10 @@ void svg_text(double left, double baseline, string text) {
<< text << "</text>"; << text << "</text>";
} }
void svg_rect(double x, double y, double width, double height) { void svg_rect(double x, double y, double width, double height, bool is_above_average) {
cout << "<rect class='bar' x='" << x << "' y='" << y << "' width='" << width string bar_class = is_above_average ? "bar-red" : "bar-green";
<< "' height='" << height << "' />"; cout << "<rect class='" << bar_class << "' x='" << x << "' y='" << y
<< "' width='" << width << "' height='" << height << "' />";
} }
void show_histogram_svg(const vector<size_t>& bins) { void show_histogram_svg(const vector<size_t>& bins) {
@ -46,10 +49,16 @@ void show_histogram_svg(const vector<size_t>& bins) {
if (count > max_count) max_count = count; if (count > max_count) max_count = count;
} }
// Âû÷èñëÿåì ñðåäíþþ âûñîòó ñòîëáöà
double average_height = 0;
if (!bins.empty()) {
average_height = accumulate(bins.begin(), bins.end(), 0.0) / bins.size();
}
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count); const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, bin > average_height);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }

@ -78,11 +78,11 @@
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h 1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
<vector> <vector>
1748876656 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp 1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
"svg.h" "svg.h"
<iostream> <iostream>
1748810901 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h 1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
<vector> <vector>
<cstddef> <cstddef>

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