diff --git a/lab1.cbp b/lab1.cbp
index a01ffa6..3525dcd 100644
--- a/lab1.cbp
+++ b/lab1.cbp
@@ -14,6 +14,11 @@
+
+
+
+
+
@@ -32,7 +37,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main.cpp b/main.cpp
index 90ac791..a32c127 100644
--- a/main.cpp
+++ b/main.cpp
@@ -33,11 +33,24 @@ input_data() {
}
-int main() {
- auto in = input_data();
+//int main (){
+ // auto in = input_data();
+ //auto bins = make_histogram(in.numbers, in.bin_count);
+ // svg_rect(50, 0, bins[0] * 10, 30);
+ // show_histogram_svg(bins);
+
+ // return 0;
+//}
+
+int main(){
+
+ bool res = false;
+
+ Input in = input_data();
+
auto bins = make_histogram(in.numbers, in.bin_count);
- svg_rect(50, 0, bins[0] * 10, 30);
+
show_histogram_svg(bins);
- return 0;
-}
+
+ }
diff --git a/svg.cpp b/svg.cpp
index fd50152..a78fbf3 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -2,29 +2,33 @@
#include
#include "svg.h"
-void svg_begin(double width, double height) {
+void
+svg_begin(double width, double height) {
std::cout << "\n";
std::cout << "\n";
}
-void svg_text(double left, double baseline, std::string text) {
- std::cout << "" << text << "\n";
+void
+svg_text(double left, double baseline, std::string text) {
+ std::cout << " " << text << " ";
}
-void svg_rect(double x, double y, double width, double height, std::string stroke, std::string fill) {
- std::cout << "\n";
+void svg_rect(double x, double y, double width, double height){
+ std::cout << "";
}
-void show_histogram_svg(const std::vector& bins) {
+void
+show_histogram_svg(const std::vector& bins) {
+
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
@@ -32,20 +36,34 @@ void show_histogram_svg(const std::vector& bins) {
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
-
+ const std::size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
-
double top = 0;
- for (size_t bin : bins) {
- const double bin_width = BLOCK_WIDTH * bin;
- svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
- svg_rect(TEXT_WIDTH, top, bin_width);
- top += BIN_HEIGHT;
+
+ std::size_t maxbin=bins[0];
+ for (std::size_t i=0; i < bins.size(); i++){
+ if (maxbin < bins[i]){
+ maxbin=bins[i];
+ }
}
- svg_end();
+ if (maxbin<=76){
+ for (std::size_t i=0; i < bins.size(); i++) {
+ double bin_width = BLOCK_WIDTH * bins[i];
+ svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
+ top += BIN_HEIGHT;
+ }
+ svg_end();
+ } else {
+ for (std::size_t i=0; i < bins.size(); i++) {
+ double bin_width= MAX_ASTERISK * (static_cast(bins[i]) / maxbin);
+ svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
+ svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
+ top += BIN_HEIGHT;
+ }
+ svg_end();
+ }
}
-
-
diff --git a/svg.h b/svg.h
index ed10ffd..1df1092 100644
--- a/svg.h
+++ b/svg.h
@@ -1,15 +1,11 @@
-#ifndef SVG_H
-#define SVG_H
+#ifndef SVG_H_INCLUDED
+#define SVG_H_INCLUDED
-#include
-#include
#include
-//void svg_begin(double width, double height);
-//void svg_end();
-//void svg_text(double left, double baseline, std::string text);
-void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
-void show_histogram_svg(const std::vector& bins);
+void
+show_histogram_svg(const std::vector& bins);
+
+#endif // SVG_H_INCLUDED
-#endif // SVG_H
diff --git a/unittest.cbp b/unittest.cbp
index 7f9621b..1fa0b37 100644
--- a/unittest.cbp
+++ b/unittest.cbp
@@ -31,6 +31,10 @@
+
+
+
+