From a60b3a0445953ec075cbd71910a5c3c45f37221a Mon Sep 17 00:00:00 2001 From: VinogradovMA Date: Thu, 1 May 2025 14:27:39 +0300 Subject: [PATCH] code:scaling[5] --- svg.cpp | 10 ++++++---- svg.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/svg.cpp b/svg.cpp index f74bb5d..3a67cec 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,4 +1,5 @@ #include "svg.h" +#include "text.h" void svg_begin(double width, double height) { std::cout << "\n"; std::cout << "& bins) { const auto BIN_HEIGHT = 30; const auto BLOCK_WIDTH = 10; svg_begin(400, 300); - //svg_text(20, 20, std::to_string(bins[0])); - //svg_rect(50, 0, bins[0] * 10, 30,"red","FF9966"); + size_t maxCount = maxBin(bins); double top = 0; for (size_t bin : bins) { - const double bin_width = BLOCK_WIDTH * bin; + const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * (bin / double(maxCount)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C"); top += BIN_HEIGHT; @@ -36,6 +36,8 @@ void show_histogram_svg(const std::vector& bins) { 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 fills){ +void svg_rect(double x, double y, double width, double height,std::string stroke="black", std::string fills="black"){ std::cout << ""; } + + diff --git a/svg.h b/svg.h index f6023f5..c558da8 100644 --- a/svg.h +++ b/svg.h @@ -8,4 +8,5 @@ void svg_end(); void show_histogram_svg(const std::vector& bins); void svg_text(double left, double baseline, std::string text); void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills); + #endif // SVG_H_INCLUDED