code:svg_output_rectangle3.0[5]

Этот коммит содержится в:
2025-05-01 02:15:59 +03:00
родитель 76c58a3c2e
Коммит adcd8e719a
2 изменённых файлов: 6 добавлений и 6 удалений

10
svg.cpp
Просмотреть файл

@@ -21,14 +21,14 @@ 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_text(20, 20, std::to_string(bins[0]));
svg_rect(50, 0, bins[0] * 10, 30); //svg_rect(50, 0, bins[0] * 10, 30,"red","FF9966");
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 = BLOCK_WIDTH * bin;
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); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"red","#006B3C");
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
svg_end(); svg_end();
@@ -36,6 +36,6 @@ 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){ void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills){
std::cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' fill='#ffaaaa' />"; std::cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fills<<"' />";
} }

2
svg.h
Просмотреть файл

@@ -7,5 +7,5 @@ void svg_begin(double width, double height);
void svg_end(); 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); 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