|
|
@ -22,26 +22,12 @@ 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 fill = "black", std::string stroke = "black")
|
|
|
|
void svg_rect(double x, double y, double width, double height, std::string fill = "purple", std::string stroke = "black")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' fill='" << fill << "' stroke='" << stroke << "' />\n";
|
|
|
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' fill='" << fill << "' stroke='" << stroke << "' />\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string check_color(const std::string& color)
|
|
|
|
void show_histogram_svg(const std::vector<std::size_t>& bins)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (color.find(" ") == -1 || color.find('#') == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return color;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return "black";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_histogram_svg(const std::vector<std::size_t>& bins, const std::vector<std::string>& colors)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
@ -68,7 +54,7 @@ void show_histogram_svg(const std::vector<std::size_t>& bins, const std::vector<
|
|
|
|
for (std::size_t j=0; j < bins.size(); j++) {
|
|
|
|
for (std::size_t j=0; j < bins.size(); j++) {
|
|
|
|
const double bin_width= MAX_ASTERISK * (static_cast<double>(bins[j]) / maxbin);
|
|
|
|
const double bin_width= MAX_ASTERISK * (static_cast<double>(bins[j]) / maxbin);
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[j]));
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[j]));
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, check_color(colors[j]), "black");
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
svg_end();
|
|
|
@ -77,9 +63,10 @@ void show_histogram_svg(const std::vector<std::size_t>& bins, const std::vector<
|
|
|
|
for (std::size_t j=0; j < bins.size(); j++) {
|
|
|
|
for (std::size_t j=0; j < bins.size(); j++) {
|
|
|
|
const double bin_width= MAX_ASTERISK * (static_cast<double>(bins[j]) / maxbin);
|
|
|
|
const double bin_width= MAX_ASTERISK * (static_cast<double>(bins[j]) / maxbin);
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[j]));
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[j]));
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, check_color(colors[j]), "black");
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
svg_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|