|
|
@ -1,5 +1,6 @@
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "svg.h"
|
|
|
|
#include "svg.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
@ -22,12 +23,12 @@ 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 colour){
|
|
|
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='#33A220' ></rect>";
|
|
|
|
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << " ' stroke='black' fill='"<< colour <<"' ></rect>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
show_histogram_svg(const std::vector<std::size_t>& bins) {
|
|
|
|
show_histogram_svg(const std::vector<std::size_t>& bins, const std::vector<std::string>& colours) {
|
|
|
|
|
|
|
|
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
const auto IMAGE_HEIGHT = 300;
|
|
|
|
const auto IMAGE_HEIGHT = 300;
|
|
|
@ -51,7 +52,11 @@ show_histogram_svg(const std::vector<std::size_t>& bins) {
|
|
|
|
for (std::size_t i=0; i < bins.size(); i++) {
|
|
|
|
for (std::size_t i=0; i < bins.size(); i++) {
|
|
|
|
double bin_width = BLOCK_WIDTH * bins[i];
|
|
|
|
double bin_width = BLOCK_WIDTH * bins[i];
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
if (colours[i] != "A") {
|
|
|
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, colours[i]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "GREEN");
|
|
|
|
|
|
|
|
}
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
svg_end();
|
|
|
@ -59,7 +64,11 @@ show_histogram_svg(const std::vector<std::size_t>& bins) {
|
|
|
|
for (std::size_t i=0; i < bins.size(); i++) {
|
|
|
|
for (std::size_t i=0; i < bins.size(); i++) {
|
|
|
|
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
|
|
|
|
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
if (colours[i] != "A") {
|
|
|
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, colours[i]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "GREEN");
|
|
|
|
|
|
|
|
}
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
svg_end();
|
|
|
|