Alexey (MinovAS) 2 лет назад
Родитель 6f0e95f56f
Сommit 843707a695

@ -10,6 +10,7 @@
35EA3A982A2D54F400ED69F1 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35EA3A972A2D54F400ED69F1 /* main.cpp */; };
35EA3AA02A2D58E700ED69F1 /* histogram.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35EA3A9E2A2D58E700ED69F1 /* histogram.cpp */; };
35EA3AA32A2D591600ED69F1 /* text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35EA3AA12A2D591600ED69F1 /* text.cpp */; };
35EA3ADA2A2D6B2100ED69F1 /* svg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35EA3AD82A2D6B2100ED69F1 /* svg.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -32,6 +33,8 @@
35EA3AA12A2D591600ED69F1 /* text.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = text.cpp; sourceTree = "<group>"; };
35EA3AA22A2D591600ED69F1 /* text.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = text.hpp; sourceTree = "<group>"; };
35EA3AA92A2D5D8400ED69F1 /* histogram_internal.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = histogram_internal.hpp; sourceTree = "<group>"; };
35EA3AD82A2D6B2100ED69F1 /* svg.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = svg.cpp; sourceTree = "<group>"; };
35EA3AD92A2D6B2100ED69F1 /* svg.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = svg.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -49,6 +52,8 @@
isa = PBXGroup;
children = (
35EA3A972A2D54F400ED69F1 /* main.cpp */,
35EA3AD82A2D6B2100ED69F1 /* svg.cpp */,
35EA3AD92A2D6B2100ED69F1 /* svg.hpp */,
35EA3AA12A2D591600ED69F1 /* text.cpp */,
35EA3AA22A2D591600ED69F1 /* text.hpp */,
35EA3A9E2A2D58E700ED69F1 /* histogram.cpp */,
@ -123,6 +128,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
35EA3ADA2A2D6B2100ED69F1 /* svg.cpp in Sources */,
35EA3AA02A2D58E700ED69F1 /* histogram.cpp in Sources */,
35EA3A982A2D54F400ED69F1 /* main.cpp in Sources */,
35EA3AA32A2D591600ED69F1 /* text.cpp in Sources */,

Двоичный файл не отображается.

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "69208B9D-68E3-4BC2-BE40-287FBD678D84"
type = "1"
version = "2.0">
</Bucket>

@ -3,6 +3,7 @@
#include <ctime>
#include "histogram.hpp"
#include "text.hpp"
#include "svg.hpp"
using namespace std;
@ -15,7 +16,7 @@ struct Input
Input input_data()
{
size_t number_count;
cerr << "Enter number count: ";
cout << "Enter number count: ";
cin >> number_count; // Кол-во чисел
Input in;
in.numbers.resize(number_count);
@ -23,7 +24,7 @@ Input input_data()
{
cin >> in.numbers[i];
}
cerr << "Enter bin count: ";
cout << "Enter bin count: ";
cin >> in.bin_count;
return in;
}
@ -32,6 +33,6 @@ int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count);
show_histogram_svg(bins);
return 0;
}

@ -0,0 +1,76 @@
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include "svg.hpp"
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 = "black", string fill = "black")
{
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fill<<"'";
}
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 BOARD_COLOR = "black";
const auto FILL_COLOR = "red";
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
double top = 0;
double max_count = bins[0];
for (size_t i = 0; i < bins.size(); i++)
{
if (max_count<bins[i])
{
max_count=bins[i];
}
}
for (size_t i=0; i < bins.size(); i++)
{
double bin_width = (MAX_WIDTH)*(bins[i]/max_count);
double opacity = (bins[i]/max_count);
string fill_opacity = to_string(opacity);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BOARD_COLOR, FILL_COLOR);
cout << " fill-opacity ='" << fill_opacity << "'" << " /> ";
top += BIN_HEIGHT;
}
svg_end();
}

@ -0,0 +1,9 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <vector>
void
show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H_INCLUDED

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить