Сравнить коммиты
6 Коммитов
c7252e212a
...
a60b3a0445
| Автор | SHA1 | Дата | |
|---|---|---|---|
| a60b3a0445 | |||
| adcd8e719a | |||
| 76c58a3c2e | |||
| e28c2321bc | |||
| f7e2afa797 | |||
| 30a95a6811 |
7
main.cpp
7
main.cpp
@@ -17,7 +17,7 @@ int main()
|
|||||||
|
|
||||||
Input in = input_data();
|
Input in = input_data();
|
||||||
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_text(bins, in.bin_count);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Input input_data() {
|
Input input_data() {
|
||||||
@@ -27,15 +27,14 @@ Input input_data() {
|
|||||||
cin >> countOfNumbers;
|
cin >> countOfNumbers;
|
||||||
|
|
||||||
input_struct.numbers.resize(countOfNumbers);
|
input_struct.numbers.resize(countOfNumbers);
|
||||||
|
|
||||||
cerr << "Input bin count:\n";
|
|
||||||
cin >> input_struct.bin_count;
|
|
||||||
cerr << "Input numbers:\n";
|
cerr << "Input numbers:\n";
|
||||||
for (int i = 0; i < countOfNumbers; i++) {
|
for (int i = 0; i < countOfNumbers; i++) {
|
||||||
cerr << i << ":" << endl;
|
cerr << i << ":" << endl;
|
||||||
cin >> input_struct.numbers[i];
|
cin >> input_struct.numbers[i];
|
||||||
}
|
}
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
|
cerr << "Input bin count:\n";
|
||||||
|
cin >> input_struct.bin_count;
|
||||||
return input_struct;
|
return input_struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
svg.cpp
25
svg.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "text.h"
|
||||||
void svg_begin(double width, double height) {
|
void svg_begin(double width, double height) {
|
||||||
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
std::cout << "<svg ";
|
std::cout << "<svg ";
|
||||||
@@ -13,6 +14,30 @@ void svg_end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins) {
|
void show_histogram_svg(const std::vector<size_t>& bins) {
|
||||||
|
const auto IMAGE_WIDTH = 400;
|
||||||
|
const auto IMAGE_HEIGHT = 300;
|
||||||
|
const auto TEXT_LEFT = 20;
|
||||||
|
const auto TEXT_BASELINE = 20;
|
||||||
|
const auto TEXT_WIDTH = 50;
|
||||||
|
const auto BIN_HEIGHT = 30;
|
||||||
|
const auto BLOCK_WIDTH = 10;
|
||||||
svg_begin(400, 300);
|
svg_begin(400, 300);
|
||||||
|
|
||||||
|
size_t maxCount = maxBin(bins);
|
||||||
|
double top = 0;
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * (bin / double(maxCount));
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C");
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
}
|
}
|
||||||
|
void svg_text(double left, double baseline, std::string text) {
|
||||||
|
std::cout << "<text x='" << left << "' y='"<< baseline <<"'>" << text<<"</text>";
|
||||||
|
}
|
||||||
|
void svg_rect(double x, double y, double width, double height,std::string stroke="black", std::string fills="black"){
|
||||||
|
std::cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fills<<"' />";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -6,5 +6,7 @@
|
|||||||
void svg_begin(double width, double height);
|
void svg_begin(double width, double height);
|
||||||
void svg_end();
|
void svg_end();
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||||
|
void svg_text(double left, double baseline, std::string text);
|
||||||
|
void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);
|
||||||
|
|
||||||
#endif // SVG_H_INCLUDED
|
#endif // SVG_H_INCLUDED
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user