master
Alexander (AntonovichAN) 7 месяцев назад
Родитель d22efb57b9
Сommit eb56bffa6c

@ -32,8 +32,15 @@ void show_histogram_svg(const vector<size_t>& bins) {
double top = 0; double top = 0;
const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH; const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
double top = 0;
double max_count;
max_count = bins[0];
for (double x : bins) {
if (x > max_count) {
max_count = x;
}
}
string fill;
size_t maxbin=bins[0]; size_t maxbin=bins[0];
for (size_t i=0; i < bins.size(); i++){ for (size_t i=0; i < bins.size(); i++){
if (maxbin < bins[i]){ if (maxbin < bins[i]){
@ -45,7 +52,8 @@ void show_histogram_svg(const vector<size_t>& bins) {
for (size_t i=0; i < bins.size(); i++) { for (size_t i=0; i < bins.size(); i++) {
double bin_width = BLOCK_WIDTH * bins[i]; double bin_width = BLOCK_WIDTH * bins[i];
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); fill = "#" + to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
svg_end(); svg_end();
@ -53,7 +61,8 @@ void show_histogram_svg(const vector<size_t>& bins) {
for (size_t i=0; i < bins.size(); i++) { for (size_t i=0; i < bins.size(); i++) {
double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin); double bin_width= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); fill = "#" + to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count))+ to_string(int(10 - (bins[i] * 9) / max_count));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", fill);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
} }

Загрузка…
Отмена
Сохранить