В:18 - текстовый файл дополнен с вариантом

main
Козлов Данил 4 дней назад
Родитель 450671f5b6
Сommit ee96c90949

@ -1,8 +1,13 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <algorithm>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
#include <cctype>
#include <limits>
using namespace std; using namespace std;
struct Input struct Input
@ -39,12 +44,26 @@ int main()
{ {
Input in = input_data(); Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
double min, max; double min, max;
double bin_size = (max - min) / in.bin_count; double bin_size = (max - min) / in.bin_count;
show_histogram_text(bins, in.bin_count, bin_size); string decoration;
//show_histogram_svg(bins); vector<string> valid_decorations = {"none", "underline", "overline", "line-through"};
}
while (true) {
cerr << "Enter text decoration (none/underline/overline/line-through): ";
cin >> decoration;
if (find(valid_decorations.begin(), valid_decorations.end(), decoration)
!= valid_decorations.end()) {
break;
}
cerr << "Please choose from: none, underline, overline, line-through" << "\n";
}
show_histogram_svg(bins, decoration);
// show_histogram_text(bins, in.bin_count, bin_size);
}

@ -0,0 +1,3 @@
10
3 3 4 4 4 4 4 5 5 5 3
underline

@ -20,10 +20,9 @@ svg_end()
} }
void void
svg_text(double left, double baseline, string text) svg_text(double left, double baseline, string text, string decoration = "none")
{ {
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>"; cout << "<text x='" << left << "' y='" << baseline << "' " << "style='text-decoration: " << decoration << "'>" << text << "</text>\n";
} }
void svg_rect(double x, double y, double width, double height, void svg_rect(double x, double y, double width, double height,
@ -33,7 +32,7 @@ void svg_rect(double x, double y, double width, double height,
} }
void void
show_histogram_svg(const vector<size_t>& bins) show_histogram_svg(const vector<size_t>& bins, const string& text_decoration)
{ {
const auto IMAGE_WIDTH = 400; const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
@ -66,17 +65,14 @@ for (size_t bin : bins)
double top = 0; double top = 0;
for (size_t bin : bins) for (size_t bin : bins)
{ if (bin == max) { { if (bin == max) {
const double bin_width = BLOCK_WIDTH * bin; svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin), text_decoration);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_rect(TEXT_WIDTH, top, MAX_WIDTH, BIN_HEIGHT);
svg_rect(TEXT_WIDTH, top, MAX_WIDTH, BIN_HEIGHT); top += BIN_HEIGHT;
top += BIN_HEIGHT; } else {
} svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin), text_decoration);
else{ svg_rect(TEXT_WIDTH, top, BLOCK_WIDTH, BIN_HEIGHT);
const double bin_width = BLOCK_WIDTH * bin; top += BIN_HEIGHT;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); }
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
} }
svg_end(); svg_end();
} }

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
void show_histogram_svg(const std::vector<std::size_t>& bins); void show_histogram_svg(const std::vector<std::size_t>& bins, const std::string& text_decoration = "none");
#endif // SVG_H_INCLUDED #endif // SVG_H_INCLUDED

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