diff --git a/histogram.svg b/histogram.svg
index fe91e9f..c4bca7f 100644
--- a/histogram.svg
+++ b/histogram.svg
@@ -1,9 +1,13 @@
diff --git a/lab1.depend b/lab1.depend
index 1925996..4a96dde 100644
--- a/lab1.depend
+++ b/lab1.depend
@@ -1,26 +1,25 @@
# depslib dependency file v1.0
-1750444036 source:c:\users\taa41\desktop\прога\lab1\main.cpp
+1750586188 source:c:\users\taa41\desktop\прога\lab1\main.cpp
+
"histogram.h"
"svg.h"
-
1749173822 c:\users\taa41\desktop\прога\lab1\histogram.h
-1750443911 source:c:\users\taa41\desktop\прога\lab1\svg.cpp
+1750586035 source:c:\users\taa41\desktop\прога\lab1\svg.cpp
"svg.h"
-
-1750442384 c:\users\taa41\desktop\прога\lab1\svg.h
+1750586140 c:\users\taa41\desktop\прога\lab1\svg.h
-1750443947 source:c:\users\taa41\desktop\прога\lab1\histogram.cpp
+1750444430 source:c:\users\taa41\desktop\прога\lab1\histogram.cpp
"histogram.h"
"histogram_internal.h"
diff --git a/lab1.layout b/lab1.layout
index e471d9c..6b37ae0 100644
--- a/lab1.layout
+++ b/lab1.layout
@@ -2,29 +2,29 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/main.cpp b/main.cpp
index 5353335..9211ca1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,24 +1,25 @@
#include
+#include
#include "histogram.h"
#include "svg.h"
-#include
using namespace std;
int main() {
Input data = input_data();
-
-
- size_t block_width = svg::input_block_width();
-
auto bins = make_histogram(data.numbers, data.bin_count);
+ // Запрос параметров пунктира
+ int dash_len, gap_len;
+ cout << "Enter dash length (e.g., 20): ";
+ cin >> dash_len;
+ cout << "Enter gap length (e.g., 10): ";
+ cin >> gap_len;
- show_histogram_text(bins, block_width);
+ show_histogram_text(bins);
ofstream svg_file("histogram.svg");
- svg::show_histogram_svg(svg_file, bins, block_width);
+ svg::show_histogram_svg(svg_file, bins, dash_len, gap_len);
svg_file.close();
-
return 0;
}
diff --git a/svg.cpp b/svg.cpp
index 3e843ab..034e8af 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -1,34 +1,10 @@
#include "svg.h"
#include
#include
-#include
using namespace std;
namespace svg {
- size_t BLOCK_WIDTH = 10;
-
- size_t input_block_width() {
- size_t width;
- while (true) {
- cout << "Введите ширину блока гистограммы (3-30px): ";
- cin >> width;
-
- if (width < 3) {
- cout << "Ширина слишком мала. Минимальное значение: 3px. Пожалуйста, повторите ввод.\n";
- } else if (width > 30) {
- cout << "Ширина слишком велика. Максимальное значение: 30px. Пожалуйста, повторите ввод.\n";
- } else {
- break;
- }
- }
- return width;
- }
-
- void set_block_width(size_t width) {
- BLOCK_WIDTH = width;
- }
-
void begin(ostream& out, double width, double height) {
out << "\n";
out << "\n";
}
-void show_histogram_svg(ofstream& out, const vector& bins, size_t block_width) {
- begin(out, IMAGE_WIDTH, IMAGE_HEIGHT);
-
- if (bins.empty()) {
- end(out);
- return;
+ void line(ostream& out, double x1, double y1, double x2, double y2,
+ const string& stroke, int dash_length, int gap_length) {
+ out << "\n";
}
- const size_t max_count = *max_element(bins.begin(), bins.end());
- if (max_count == 0) {
- end(out);
- return;
- }
+ void show_histogram_svg(ofstream& out, const vector& bins, int dash_length, int gap_length) {
+ begin(out, IMAGE_WIDTH, IMAGE_HEIGHT);
+ if (bins.empty()) {
+ end(out);
+ return;
+ }
- const double max_svg_width = IMAGE_WIDTH - TEXT_WIDTH - 40;
+ size_t max_count = *max_element(bins.begin(), bins.end());
+ if (max_count == 0) {
+ end(out);
+ return;
+ }
+ // Увеличиваем максимальную ширину для лучшего отображения
+ double max_width = IMAGE_WIDTH - TEXT_WIDTH - 100;
+ double scale = max_width / max_count;
- const double scale = max_svg_width / max_count;
+ double top = 0;
+ for (size_t bin : bins) {
+ double width = bin * scale;
- double top = 0;
- for (size_t bin : bins) {
+ // Подпись значения (крупнее и четче)
+ out << "" << bin << "\n";
- double width = bin * scale * (block_width / 10.0);
+ // Основной столбец
+ rect(out, TEXT_WIDTH, top, width, BIN_HEIGHT, "#333333", "#4CAF50");
- text(out, TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
- rect(out, TEXT_WIDTH, top, width, BIN_HEIGHT, "black", "#aaffaa");
+ // Пунктирная линия (толще и контрастнее)
+ out << "\n";
- top += BIN_HEIGHT;
- }
+ top += BIN_HEIGHT + 10; // Добавляем отступ между столбцами
+ }
- end(out);
-}
+ // Добавляем рамку вокруг всей гистограммы
+ out << "\n";
+
+ end(out);
+ }
}
diff --git a/svg.h b/svg.h
index f70f8eb..8c31345 100644
--- a/svg.h
+++ b/svg.h
@@ -19,9 +19,8 @@ namespace svg {
void text(std::ostream& out, double left, double baseline, const std::string& text);
void rect(std::ostream& out, double x, double y, double width, double height,
const std::string& stroke = "black", const std::string& fill = "#dddddd");
- void show_histogram_svg(std::ofstream& out, const std::vector& bins, size_t block_width);
- size_t input_block_width();
- void set_block_width(size_t width);
+ void line(std::ostream& out, double x1, double y1, double x2, double y2,
+ const std::string& stroke, int dash_length, int gap_length);
+ void show_histogram_svg(std::ofstream& out, const std::vector& bins, int dash_length, int gap_length);
}
-
#endif