ind: индивидуальное задание
Этот коммит содержится в:
@@ -32,7 +32,13 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
15
svg.cpp
15
svg.cpp
@@ -41,6 +41,7 @@ show_histogram_svg(const vector<double>& bins) {
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
|
||||
|
||||
double sum = 0;
|
||||
double max_count = (bins[0] * BLOCK_WIDTH);
|
||||
for (double bin: bins){
|
||||
if ((bin * BLOCK_WIDTH) > max_count) {
|
||||
@@ -48,12 +49,24 @@ show_histogram_svg(const vector<double>& bins) {
|
||||
}
|
||||
}
|
||||
|
||||
for (double bin: bins){
|
||||
sum = sum + (MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count));
|
||||
}
|
||||
|
||||
double avg_width = sum/bins.size();
|
||||
|
||||
|
||||
svg_begin(400, 300);
|
||||
double top = 0;
|
||||
for (double bin : bins) {
|
||||
const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count);
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaffaa");
|
||||
if (bin_width > avg_width){
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#e71320");
|
||||
}
|
||||
else {
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#2fe713");
|
||||
}
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
Ссылка в новой задаче
Block a user