Yarocvet 2 лет назад
Родитель 549f896fc5
Сommit 7a9a003842

@ -35,6 +35,8 @@
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions>

@ -1,5 +1,5 @@
# depslib dependency file v1.0
1686350213 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp
1686359317 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp
<string>
"histogram.h"
"text.h"
@ -19,11 +19,11 @@
<vector>
<iostream>
1686349467 c:\users\kostello\desktop\lubs\lab03.2\svg.h
1686357236 c:\users\kostello\desktop\lubs\lab03.2\svg.h
<iostream>
<vector>
1686349791 source:c:\users\kostello\desktop\lubs\lab03.2\svg.cpp
1686357236 source:c:\users\kostello\desktop\lubs\lab03.2\svg.cpp
"svg.h"
<math.h>

@ -1,5 +1,4 @@
#include <string>
#include "histogram.h"
#include "text.h"
#include "svg.h"
@ -10,7 +9,7 @@ using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
// vector<string> colour;
vector<string> colour;
};
Input
@ -29,11 +28,11 @@ for (size_t i = 0; i < number_count; i++) {
cin >> in.bin_count;
/*in.numbers.resize(in.bin_count);
in.colour.resize(in.bin_count+1);
for (size_t i = 0; i < in.bin_count; i++) {
cin >> in.colour[i];*/
cin >> in.colour[i];
}
return in;
}
@ -43,7 +42,7 @@ int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
show_histogram_svg(bins, in.colour);
return 0;
}

@ -30,7 +30,7 @@ cout << "<rect x='" << x << "' y='" << y << "' width='" << width * 3 << "' heigh
void
show_histogram_svg(const vector<size_t>& bins) {
show_histogram_svg(const vector<size_t>& bins, const vector<string>& colour) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
@ -42,10 +42,10 @@ show_histogram_svg(const vector<size_t>& bins) {
svg_begin(400, 300);
double top = 0;
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, "red", "#ffeeee");
for (size_t i=0; i< bins.size(); i++) {
const double bin_width = BLOCK_WIDTH * bins[i];
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", colour[i]);
top += BIN_HEIGHT;
}
svg_end();

@ -3,7 +3,8 @@
#include <iostream>
#include <vector>
#include <string>
void show_histogram_svg(const std::vector<size_t>& bins);
void show_histogram_svg(const std::vector<size_t>& bins, const std::vector<std::string>& colour);
#endif // SVG_H_INCLUDED

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