Загрузил(а) файлы в ''

master
OgarkovIA 8 месяцев назад
Родитель 2c2e4e7449
Сommit 5e0dfd755c

@ -0,0 +1,9 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED

@ -0,0 +1,10 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
#include <string>
bool find_minmax(const std::vector<double>& numbers, double& min, double& max);
std::string
bin_color(size_t bin, size_t max_count);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,45 @@
#include <iostream>
#include <vector>
#include "histogram.h"
#include "svg.h"
#include <curl/curl.h>
using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data(istream& in, bool prompt){
if (prompt == true) cerr << "Enter number_count: ";
size_t number_count;
in >> number_count;
Input data;
data.numbers.resize(number_count);
if (prompt == true) cerr << "Enter numbers: ";
for (size_t i = 0; i < number_count; i++){
in >> data.numbers[i];
}
if (prompt == true) cerr << "Enter bin count: ";
in >> data.bin_count;
return data;
}
int
main()
{
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin, false);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
}

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="my_project" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/my_project" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="curl/include" />
</Compiler>
<Linker>
<Add library="curl/lib/libcurl.dill.a" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/my_project" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add directory="curl/include" />
</Compiler>
<Linker>
<Add library="curl/lib/libcurl.dll.a" />
</Linker>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="mainmain.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,62 @@
#include <iostream>
#include "svg.h"
using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_end() {
cout << "</svg>\n";
}
void
svg_text(double left, double baseline, string text){
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
}
void
svg_rect(double x, double y, double width, double height, string stroke, string fil){
cout << "<rect x = '" << x << "' y = '" << y << "' width = '" << width << "' height = '" << height << "' stroke = '" << stroke << "' fill = '" << fil << "' />";
}
//string bin_color(size_t bin, size_t max_count){
// return ("#" + to_string(10 - (bin * 9) / max_count) + to_string(10 - (bin * 9) / max_count) + to_string(10 - (bin * 9) / max_count));
//}
void
show_histogram_svg(const 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(IMAGE_WIDTH, IMAGE_HEIGHT);
size_t max_count = 0;
for (size_t x: bins) {
if (x > max_count) {
max_count = x;
}
}
double top = 0;
for (size_t bin : bins) {
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * bin / max_count;
//const auto color = bin_color(bin,max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red", "#ffeeee");
top += BIN_HEIGHT;
}
svg_end();
}
Загрузка…
Отмена
Сохранить