-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.hpp
More file actions
76 lines (63 loc) · 2.05 KB
/
data.hpp
File metadata and controls
76 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "gnuplotpp/plot.hpp"
#include <filesystem>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
namespace gnuplotpp {
/**
* @brief Simple numeric table loaded from CSV.
*/
struct DataTable {
std::unordered_map<std::string, std::vector<double>> columns;
/** @brief Access a column by name; throws when missing. */
const std::vector<double>& column(const std::string& name) const;
/** @brief Returns true when a named column exists. */
bool has_column(const std::string& name) const;
/**
* @brief Validate that all requested columns exist.
* @param names Required column names.
* @throws std::out_of_range with available column list when missing.
*/
void require_columns(std::span<const std::string> names) const;
/** @brief Returns row count; throws when columns have inconsistent lengths. */
std::size_t row_count() const;
/**
* @brief Add a line series from named columns.
* @param ax Target axes.
* @param spec Series style.
* @param x_name X column.
* @param y_name Y column.
*/
void add_line(Axes& ax,
SeriesSpec spec,
const std::string& x_name,
const std::string& y_name) const;
/**
* @brief Add a scatter series from named columns.
* @param ax Target axes.
* @param spec Series style.
* @param x_name X column.
* @param y_name Y column.
*/
void add_scatter(Axes& ax,
SeriesSpec spec,
const std::string& x_name,
const std::string& y_name) const;
};
/**
* @brief Load numeric CSV with header row.
* @param path File path.
* @param delimiter Field delimiter.
* @return Parsed table.
*/
DataTable read_csv_numeric(const std::filesystem::path& path, char delimiter = ',');
/**
* @brief Build axis label with unit suffix.
* @param name Quantity name.
* @param unit Unit text.
* @return Label in "name [unit]" form, or just name when unit empty.
*/
std::string label_with_unit(const std::string& name, const std::string& unit);
} // namespace gnuplotpp