|
|
|
@ -17,7 +17,7 @@ svg_text(double left, double baseline, string text) {
|
|
|
|
|
cout << "<text x='" << left << "' y='"<<baseline<<"'>"<<text<<"</text>";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void svg_rect(double x, double y, double width, double height,string stroke,string fill){
|
|
|
|
|
void svg_rect(double x, double y, double width, double height,string stroke = "black",string fill = "black"){
|
|
|
|
|
cout<<"<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height <<"' stroke='" << stroke <<"' fill= '"<< fill <<"'/>";
|
|
|
|
|
}
|
|
|
|
|
void show_histogram_svg(const vector<size_t>& bins) {
|
|
|
|
@ -29,15 +29,13 @@ void show_histogram_svg(const vector<size_t>& bins) {
|
|
|
|
|
const auto BIN_HEIGHT = 30;
|
|
|
|
|
const auto BLOCK_WIDTH = 10;
|
|
|
|
|
svg_begin(400, 300);
|
|
|
|
|
svg_text(20, 20, to_string(bins[0]));
|
|
|
|
|
svg_rect(50, 0, bins[0] * 10, 30,"red","#ffeeee");
|
|
|
|
|
double top = 0;
|
|
|
|
|
for (size_t bin : bins) {
|
|
|
|
|
const double bin_width = BLOCK_WIDTH * bin;
|
|
|
|
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
|
|
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", "#ffeeee");
|
|
|
|
|
svg_text(top + TEXT_BASELINE,TEXT_LEFT , to_string(bin));
|
|
|
|
|
svg_rect((top+10),(TEXT_WIDTH-20) , BIN_HEIGHT,bin_width , "green", "#aaffee");
|
|
|
|
|
top += BIN_HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
svg_end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|