revert 15fb696925
revert code: вывод гистограммы в формате SVG + хеддер-файлы проекта
Этот коммит содержится в:
2
.gitignore
поставляемый
2
.gitignore
поставляемый
@@ -1,2 +0,0 @@
|
||||
/bin
|
||||
/obj
|
||||
@@ -1,7 +0,0 @@
|
||||
#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
|
||||
@@ -1,9 +0,0 @@
|
||||
#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,10 +38,6 @@
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
|
||||
1
main.cpp
1
main.cpp
@@ -1,6 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <hist_proc.h>
|
||||
#include "histogram.h"
|
||||
#include <text.h>
|
||||
|
||||
52
svg.cpp
52
svg.cpp
@@ -1,6 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <svg.h>
|
||||
|
||||
using namespace std;
|
||||
@@ -20,59 +19,8 @@ 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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
6
svg.h
6
svg.h
@@ -1,6 +1,12 @@
|
||||
#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);
|
||||
|
||||
|
||||
7
text.h
7
text.h
@@ -1,7 +0,0 @@
|
||||
#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
|
||||
Ссылка в новой задаче
Block a user