|
|
|
@ -21,6 +21,13 @@ void svg_rect(double x, double y, double width, double height,string stroke = "b
|
|
|
|
|
{
|
|
|
|
|
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' fill='" << fill << "' stroke='" << stroke << "' />";
|
|
|
|
|
}
|
|
|
|
|
int GetProc(int number_cnt, int bin)
|
|
|
|
|
{
|
|
|
|
|
if (number_cnt <= 0) return 0;
|
|
|
|
|
if (bin < 0) return 0;
|
|
|
|
|
return 100.0 * bin / number_cnt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_histogram_svg(const vector<double>& bins, int number_cnt) {
|
|
|
|
|
const auto IMAGE_WIDTH = 400;
|
|
|
|
|
const auto IMAGE_HEIGHT = 300;
|
|
|
|
@ -40,7 +47,7 @@ void show_histogram_svg(const vector<double>& bins, int number_cnt) {
|
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
|
const double bin_width = k * bin;
|
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
|
svg_text(IMAGE_WIDTH - TEXT_WIDTH + TEXT_LEFT, top + TEXT_BASELINE, to_string((int)((100.0 / (double)number_cnt) * (double)bin)) + "%");
|
|
|
|
|
svg_text(IMAGE_WIDTH - TEXT_WIDTH + TEXT_LEFT, top + TEXT_BASELINE, to_string(GetProc(number_cnt,bin)) + "%");
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,"black",colors[color_ptr]);
|
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
|
color_ptr++;
|
|
|
|
|