code: вывод гистограммы в формате SVG + хеддер-файлы проекта

master
EfremovSI 1 год назад
Родитель 74edc12b97
Сommit 15fb696925

2
.gitignore поставляемый

@ -0,0 +1,2 @@
/bin
/obj

@ -0,0 +1,7 @@
#ifndef HIST_PROC_H_INCLUDED
#define HIST_PROC_H_INCLUDED
std::vector<size_t>
make_histogram_proc(const std::vector<double> numbers, size_t bin_count, std::vector<size_t> bins);
#endif // HIST_PROC_H_INCLUDED

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

@ -38,6 +38,10 @@
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions>

@ -1,5 +1,6 @@
#include <iostream>
#include <vector>
#include <string>
#include <hist_proc.h>
#include "histogram.h"
#include <text.h>

@ -1,5 +1,6 @@
#include <iostream>
#include <vector>
#include <string>
#include <svg.h>
using namespace std;
@ -19,8 +20,59 @@ 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){
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke ='cyan' fill='#fce166' />\n";
}
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;
const double SCALE = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(400, 300);
double max_count = 0;
for (double x: bins) {
if (x > max_count) {
max_count = x;
}
}
double top = 0;
if ((max_count*BLOCK_WIDTH)>SCALE){
for (size_t bin : bins) {
const double bin_width = SCALE * ( bin / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
cout << endl;
cout << bin_width;
}
}
else{
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
cout << endl;
cout << bin_width;
}
}
svg_end();
}

@ -1,12 +1,6 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
void
svg_begin(double width, double height);
void
svg_end();
void
show_histogram_svg(const std::vector<size_t>& bins);

@ -0,0 +1,7 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
void
show_histogram(size_t bin_count, std::vector<size_t> bins, std::vector<size_t> procent);
#endif // TEXT_H_INCLUDED
Загрузка…
Отмена
Сохранить