|
|
@ -30,7 +30,7 @@ void svg_rect(double x, double y, double width, double height, string stroke = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
show_histogram_svg(const vector<size_t>& bins) {
|
|
|
|
show_histogram_svg(const vector<size_t>& bins, size_t user_block_width) {
|
|
|
|
|
|
|
|
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
const auto IMAGE_HEIGHT = 300;
|
|
|
|
const auto IMAGE_HEIGHT = 300;
|
|
|
@ -38,7 +38,7 @@ show_histogram_svg(const vector<size_t>& bins) {
|
|
|
|
const auto TEXT_BASELINE = 20;
|
|
|
|
const auto TEXT_BASELINE = 20;
|
|
|
|
const auto TEXT_WIDTH = 50;
|
|
|
|
const auto TEXT_WIDTH = 50;
|
|
|
|
const auto BIN_HEIGHT = 30;
|
|
|
|
const auto BIN_HEIGHT = 30;
|
|
|
|
const auto BLOCK_WIDTH = 10;
|
|
|
|
const auto BLOCK_WIDTH = user_block_width;
|
|
|
|
|
|
|
|
|
|
|
|
const size_t MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH - 1;
|
|
|
|
const size_t MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH - 1;
|
|
|
|
|
|
|
|
|
|
|
@ -49,27 +49,24 @@ show_histogram_svg(const vector<size_t>& bins) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (maxbin > MAX_WIDTH) {
|
|
|
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
|
|
|
|
|
|
|
|
|
|
svg_begin(400, 300);
|
|
|
|
|
|
|
|
double top = 0;
|
|
|
|
double top = 0;
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
if (maxbin<=76){
|
|
|
|
const double bin_width = MAX_WIDTH * (bin / maxbin);
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
double bin_width = BLOCK_WIDTH * bin;
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
}
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
svg_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
svg_begin(400, 300);
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
double top = 0;
|
|
|
|
double bin_width= MAX_WIDTH * (static_cast<double>(bin) / maxbin);
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
const double bin_width = BLOCK_WIDTH * bin;
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
|
|
|
}
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
svg_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg_end();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|