code:scaling[5]
Этот коммит содержится в:
10
svg.cpp
10
svg.cpp
@@ -1,4 +1,5 @@
|
||||
#include "svg.h"
|
||||
#include "text.h"
|
||||
void svg_begin(double width, double height) {
|
||||
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
std::cout << "<svg ";
|
||||
@@ -21,12 +22,11 @@ void show_histogram_svg(const std::vector<size_t>& 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<size_t>& bins) {
|
||||
void svg_text(double left, double baseline, std::string 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<<"' />";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
svg.h
1
svg.h
@@ -8,4 +8,5 @@ void svg_end();
|
||||
void show_histogram_svg(const std::vector<size_t>& 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
|
||||
|
||||
Ссылка в новой задаче
Block a user