pic: Добавлено масштабирование
Этот коммит содержится в:
8
svg.cpp
8
svg.cpp
@@ -34,10 +34,16 @@ show_histogram_svg(const vector <size_t> &bins) {
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto MAX_VALUE = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
double top = 0;
|
||||
size_t max_count = 0;
|
||||
for (auto now: bins)
|
||||
{if (now > max_count) {max_count = now;}}
|
||||
for (size_t bin : bins){
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
double bin_width = BLOCK_WIDTH * bin;
|
||||
if (bin == max_count) {bin_width = MAX_VALUE * 1.0;}
|
||||
else {bin_width = MAX_VALUE * (static_cast <double> (bin) / max_count);}
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||
top += BIN_HEIGHT;
|
||||
|
||||
Ссылка в новой задаче
Block a user