code: изменения 2
Этот коммит содержится в:
@@ -92,7 +92,7 @@
|
||||
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1749627705 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp
|
||||
1749630788 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<string>
|
||||
|
||||
19
svg.cpp
19
svg.cpp
@@ -1,5 +1,6 @@
|
||||
#include "svg.h"
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
using namespace std;
|
||||
|
||||
void svg_begin(double width, double height) {
|
||||
@@ -10,7 +11,8 @@ void svg_begin(double width, double height) {
|
||||
|
||||
// Ñòèëè äëÿ SVG
|
||||
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"
|
||||
<< "</style>\n";
|
||||
}
|
||||
@@ -24,9 +26,10 @@ void svg_text(double left, double baseline, string text) {
|
||||
<< text << "</text>";
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height) {
|
||||
cout << "<rect class='bar' x='" << x << "' y='" << y << "' width='" << width
|
||||
<< "' height='" << height << "' />";
|
||||
void svg_rect(double x, double y, double width, double height, bool is_above_average) {
|
||||
string bar_class = is_above_average ? "bar-red" : "bar-green";
|
||||
cout << "<rect class='" << bar_class << "' x='" << x << "' y='" << y
|
||||
<< "' width='" << width << "' height='" << height << "' />";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Âû÷èñëÿåì ñðåäíþþ âûñîòó ñòîëáöà
|
||||
double average_height = 0;
|
||||
if (!bins.empty()) {
|
||||
average_height = accumulate(bins.begin(), bins.end(), 0.0) / bins.size();
|
||||
}
|
||||
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,11 +78,11 @@
|
||||
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1748876656 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||
1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
|
||||
1748810901 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||
1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user