diff --git a/svg.cpp b/svg.cpp new file mode 100644 index 0000000..ed16f01 --- /dev/null +++ b/svg.cpp @@ -0,0 +1,57 @@ +#include "svg.h" +#include +#include +void svg_begin(double width, double height) { + std::cout << "\n"; + std::cout << "\n"; +} + +void svg_end() { + std::cout << "\n"; +} + +void +svg_text(double left, double baseline, std::string text) { + std::cout << ""<"; +} + +void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fill = "black") { + std::cout << ""; +} + +void show_histogram_svg(const std::vector& bins, size_t bin_count) { + 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; + double mxbins = bins[0]; + for (double x : bins) + { + if (x > mxbins) + mxbins = x; + } + double k; + if (mxbins > IMAGE_WIDTH-TEXT_WIDTH) + k = floor((IMAGE_WIDTH - TEXT_WIDTH) / mxbins); + else + k = 1; + svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); + double top = 0; + for (size_t bin : bins) { + std::string color = "#" + std::to_string(bin*100); + const double bin_width = BLOCK_WIDTH * bin*k; + svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,color,color); + top += BIN_HEIGHT; + } + svg_end(); +} + + diff --git a/svg.h b/svg.h new file mode 100644 index 0000000..b96b4c6 --- /dev/null +++ b/svg.h @@ -0,0 +1,4 @@ +#pragma once +#include + +void show_histogram_svg(const std::vector& bins, size_t bin_count); \ No newline at end of file diff --git a/vector.cpp b/vector.cpp index d2f610c..98efceb 100644 --- a/vector.cpp +++ b/vector.cpp @@ -3,6 +3,7 @@ #include #include "histogram.h" #include "text.h" +#include "svg.h" const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; using namespace std; @@ -34,5 +35,5 @@ int main() { Input in = input_data(); vector bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins, in.bin_count); + show_histogram_svg(bins, in.bin_count); } diff --git a/vector.vcxproj b/vector.vcxproj index 08a7898..754b146 100644 --- a/vector.vcxproj +++ b/vector.vcxproj @@ -128,12 +128,14 @@ + + diff --git a/vector.vcxproj.filters b/vector.vcxproj.filters index badcdb7..da2aad0 100644 --- a/vector.vcxproj.filters +++ b/vector.vcxproj.filters @@ -24,6 +24,9 @@ Исходные файлы + + Исходные файлы + @@ -35,5 +38,8 @@ Файлы заголовков + + Файлы заголовков + \ No newline at end of file