VinogradovMA 2 месяцев назад
Родитель adcd8e719a
Сommit a60b3a0445

@ -1,4 +1,5 @@
#include "svg.h" #include "svg.h"
#include "text.h"
void svg_begin(double width, double height) { void svg_begin(double width, double height) {
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n"; std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
std::cout << "<svg "; std::cout << "<svg ";
@ -21,12 +22,11 @@ void show_histogram_svg(const std::vector<size_t>& bins) {
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10; const auto BLOCK_WIDTH = 10;
svg_begin(400, 300); 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; double top = 0;
for (size_t bin : bins) { 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_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C"); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C");
top += BIN_HEIGHT; top += BIN_HEIGHT;
@ -36,6 +36,8 @@ void show_histogram_svg(const std::vector<size_t>& bins) {
void svg_text(double left, double baseline, std::string text) { void svg_text(double left, double baseline, std::string text) {
std::cout << "<text x='" << left << "' y='"<< baseline <<"'>" << text<<"</text>"; std::cout << "<text x='" << left << "' y='"<< baseline <<"'>" << text<<"</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 << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fills<<"' />"; std::cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fills<<"' />";
} }

@ -8,4 +8,5 @@ void svg_end();
void show_histogram_svg(const std::vector<size_t>& bins); void show_histogram_svg(const std::vector<size_t>& bins);
void svg_text(double left, double baseline, std::string text); 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); void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);
#endif // SVG_H_INCLUDED #endif // SVG_H_INCLUDED

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