финальная версия с вариантом

master
Kuzin 2 лет назад
Родитель cfd429ae90
Сommit e2c75ef3ab

@ -75,16 +75,35 @@ download(const string& adress){
int main(int argc, char* argv[])
{
curl_global_init(CURL_GLOBAL_ALL);
Input in;
string color = "base";
Input in;
if (argc > 1) {
in = download(argv[1]);
} else {
for (size_t i = 0; i < argc; i += 1){
if (strcmp(argv[i], "-fill") == 0){
if (i - 1 < 1){
in = download(argv[i + 2]);
color = argv[i + 2];
}
else{
if (i + 1 >= argc){
cerr << "Error: please enter color";
exit(1);
}
else{
in = download(argv[i - 1]);
color = argv[i + 1];
}
}
}
}
}
else {
in = input_data(cin, true);
}
auto bins = make_histogram(in.numbers, in.bin_count);
auto borders = make_borders(in.numbers, in.bin_count);
show_histogram_svg(bins, borders, in.bin_count);
show_histogram_svg(bins, borders, in.bin_count, color);
getch();
return 0;
}

@ -42,8 +42,7 @@ svg_rect(double x, double y, double width, double height, string stroke = "black
void
show_histogram_svg(const vector<size_t>& bins, const vector<double>& borders, size_t bin_count)
{
show_histogram_svg(const vector<size_t>& bins, const std::vector<double>& borders, size_t bin_count, string filling) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
@ -51,9 +50,8 @@ show_histogram_svg(const vector<size_t>& bins, const vector<double>& borders, si
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
const auto COLOUR1 = "black";
const auto COLOUR2 = "green";
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
vector <string> colors = {"red", "blue", "gold", "lime", "aqua", "green", "orange"};
size_t border = 0;
size_t number_of_blocks;
@ -61,6 +59,8 @@ show_histogram_svg(const vector<size_t>& bins, const vector<double>& borders, si
size_t max_bin = *max_element(bins.begin(), bins.end());
double top = 0;
size_t paint_swicher = 0;
string color;
double max_count = bins[0];
for (size_t i = 0; i < bins.size(); i++)
{
@ -72,14 +72,23 @@ show_histogram_svg(const vector<size_t>& bins, const vector<double>& borders, si
for (size_t bin : bins)
{
if (filling != "base"){
color = filling;
}
else{
color = colors[paint_swicher];
}
number_of_blocks = bin;
if ((max_bin * BLOCK_WIDTH) > (IMAGE_WIDTH - TEXT_WIDTH)){
number_of_blocks = ((IMAGE_WIDTH - TEXT_WIDTH)/10) * (static_cast<double>(bin) / max_bin);
}
const double bin_width = BLOCK_WIDTH * number_of_blocks;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, COLOUR1, COLOUR2);
top += BIN_HEIGHT;
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", color);
paint_swicher += 1;
if (paint_swicher > 6){
paint_swicher = 0;
}
if (border < bin_count - 1){
top += BIN_HEIGHT;
svg_text(TEXT_LEFT / 2, top + TEXT_BASELINE , to_string(borders[border]));

@ -3,9 +3,9 @@
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
void
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<double>& borders, size_t bin_count);
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<double>& borders, size_t bin_count, std::string filling);
#endif // SVG_H_INCLUDED

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