svg: масштабирование
Этот коммит содержится в:
14
svg.cpp
14
svg.cpp
@@ -39,15 +39,21 @@ show_histogram_svg(const vector<double>& bins) {
|
|||||||
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 = 10;
|
||||||
string stroke = "black";
|
const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
|
||||||
string fill = "black";
|
|
||||||
|
double max_count = (bins[0] * BLOCK_WIDTH);
|
||||||
|
for (double bin: bins){
|
||||||
|
if ((bin * BLOCK_WIDTH) > max_count) {
|
||||||
|
max_count = (bin * BLOCK_WIDTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
svg_begin(400, 300);
|
svg_begin(400, 300);
|
||||||
double top = 0;
|
double top = 0;
|
||||||
for (double bin : bins) {
|
for (double bin : bins) {
|
||||||
const double bin_width = BLOCK_WIDTH * bin;
|
const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count);
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa");
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user