diff --git a/lab01.cbp b/lab01.cbp index 56124be..2060d48 100644 --- a/lab01.cbp +++ b/lab01.cbp @@ -32,7 +32,23 @@ + + + + + + + + + + + + diff --git a/lab01.depend b/lab01.depend index 70046c4..b74a175 100644 --- a/lab01.depend +++ b/lab01.depend @@ -3,24 +3,35 @@ -1693205934 source:c:\users\texas\desktop\lab01\main.cpp +1694008250 source:c:\users\texas\desktop\lab01\main.cpp + + + + "histogram.h" "text.h" - - - + "svg.h" -1693204203 c:\users\texas\desktop\lab01\histogram.h +1694011777 c:\users\texas\desktop\lab01\histogram.h 1693205331 source:c:\users\texas\desktop\lab01\histogram.cpp "histogram.h" -1693205776 source:c:\users\texas\desktop\lab01\text.cpp - "histogram.h" - +1694006571 source:c:\users\texas\desktop\lab01\text.cpp + "text.h" + 1693209461 c:\users\texas\desktop\lab01\text.h +1694007845 c:\users\texas\desktop\lab01\svg.h + + + + +1694007750 source:c:\users\texas\desktop\lab01\svg.cpp + "svg.h" + + diff --git a/lab01.layout b/lab01.layout index 8a71059..f813462 100644 --- a/lab01.layout +++ b/lab01.layout @@ -2,29 +2,44 @@ - + - + - + - + - + - + + + + + + - + - + - + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index 7ac916b..4b5778f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,13 @@ +#include +#include +#include +#include + #include "histogram.h" #include "text.h" -#include -#include -#include +#include "svg.h" + + using namespace std; struct Input { @@ -43,7 +48,6 @@ int main() auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins, in.bin_count, in.n); - + show_histogram_svg(bins); return 0; } diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..dd0340b --- /dev/null +++ b/svg.cpp @@ -0,0 +1,59 @@ +#include "svg.h" +#include "histogram.h" +#include + + +using namespace std; + +void +svg_begin(double width, double height) { + cout << "\n"; + cout << "\n"; +} + +void +svg_end() { + cout << "\n"; +} +void svg_text(double left, double baseline, string text){ + cout << "" << text << ""; +} + +void svg_rect(double x, double y, double width, double height, string stroke, string fill){ + cout << ""; +} + +void +show_histogram_svg(const vector& bins) { + double max_count; + max_count = bins[0]; + for (double x : bins) { + if (x > max_count) { + max_count = x; + } + } + //10 - (bin * 9) / max_count + string fill; + 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; + 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)); + fill = "#" + to_string(int(10 - (bin * 9) / max_count))+ to_string(int(10 - (bin * 9) / max_count))+ to_string(int(10 - (bin * 9) / max_count)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red", fill); + top += BIN_HEIGHT; +} + svg_end(); +} + diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..3e193e4 --- /dev/null +++ b/svg.h @@ -0,0 +1,10 @@ +#ifndef SVG_H_INCLUDED +#define SVG_H_INCLUDED +#include +#include +#include + + +void show_histogram_svg(const std::vector& bins); + +#endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp index ff5c34c..3aa5fbf 100644 --- a/text.cpp +++ b/text.cpp @@ -1,6 +1,6 @@ #include "text.h" -#include -#include +#include + using namespace std; void diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..bffa065 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,12 @@ + + + + + diff --git a/unittest.depend b/unittest.depend new file mode 100644 index 0000000..4c97197 --- /dev/null +++ b/unittest.depend @@ -0,0 +1,59 @@ +# depslib dependency file v1.0 +1693205331 source:c:\users\texas\desktop\lab01\histogram.cpp + "histogram.h" + +1693204203 c:\users\texas\desktop\lab01\histogram.h + + +1693241917 source:c:\users\texas\desktop\lab01\unittest.cpp + "doctest.h" + "histogram_internal.h" + +1693241204 c:\users\texas\desktop\lab01\doctest.h + + + + + + + "doctest_fwd.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1693241001 c:\users\texas\desktop\lab01\histogram_internal.h + + diff --git a/unittest.layout b/unittest.layout new file mode 100644 index 0000000..6122808 --- /dev/null +++ b/unittest.layout @@ -0,0 +1,10 @@ + + + + + + + + + +