build: добавление первичного варианта реализации гистограммы в формате SVG

main
Ivan (BeloziorovIA) 3 недель назад
Родитель af84aa5e46
Сommit 6137e81f17

@ -5,10 +5,9 @@
#include <cmath>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
//!Разделить программу на файлы (3 пункт)!
//Ñîçäàíèå ñòðóêòóðû Input äëÿ âõîäíûõ äàííûõ
struct Input {
vector<double> Numbers;
@ -26,7 +25,7 @@ Input input_data(){
vector<double> Numbers(number_count);
stct.Numbers.resize(number_count);
cerr << "Enter array:\n";
cin >> Numbers[0];
cin >> stct.Numbers[0];
for (int i = 1; i < number_count; i++) {
cin >> stct.Numbers[i];
}
@ -45,7 +44,8 @@ int main() {
vector<size_t> bins = make_histogram(in.Numbers, in.bin_count);
//Âûâîä ãèñòîãðàììû
show_histogram_text(bins);
show_histogram_svg(bins);
//show_histogram_text(bins);
return 0;
}

@ -0,0 +1,33 @@
#include <iostream>
#include "svg.h"
#include <vector>
#include <string>
void svg_begin(double width, double height) {
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
std::cout << "<svg ";
std::cout << "width='" << width << "' ";
std::cout << "height='" << height << "' ";
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void svg_end() {
std::cout << "</svg>\n";
}
void svg_text(double left, double baseline, std::string text){
std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
}
void show_histogram_svg(const std::vector<size_t>& bins){
svg_begin(400, 300);
svg_text(20, 20, std::to_string(bins[0]));
svg_end();
}
/*
void svg_rect(double x, double y, double width, double height){
std::cout << "<rect x='" << x << "' y='" width='" << width << "' height='" << height << "' />"
}
*/

12
svg.h

@ -0,0 +1,12 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <vector>
#include <string>
void svg_begin(double width, double height);
void svg_end();
void show_histogram_svg(const std::vector<size_t>& bins);
void svg_text(double left, double baseline, std::string text);
//void svg_rect(double x, double y, double width, double height)
#endif // SVG_H_INCLUDED
Загрузка…
Отмена
Сохранить