plotdata.h
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #ifndef PJ_PLOTDATA_H
8 #define PJ_PLOTDATA_H
9 
10 #include "plotdatabase.h"
11 #include "timeseries.h"
12 #include "stringseries.h"
13 #include <any>
14 
15 namespace PJ
16 {
20 
26 // obsolate. For back compatibility only
27 // using PlotDataMap = std::unordered_map<std::string, PlotData>;
28 
29 using TimeseriesMap = std::unordered_map<std::string, PlotData>;
30 using ScatterXYMap = std::unordered_map<std::string, PlotDataXY>;
31 using AnySeriesMap = std::unordered_map<std::string, PlotDataAny>;
32 using StringSeriesMap = std::unordered_map<std::string, StringSeries>;
33 
35 {
37 
40 
44 
47 
52  std::unordered_map<std::string, PlotGroup::Ptr> groups;
53 
54  ScatterXYMap::iterator addScatterXY(const std::string& name, PlotGroup::Ptr group = {});
55 
56  TimeseriesMap::iterator addNumeric(const std::string& name, PlotGroup::Ptr group = {});
57 
58  AnySeriesMap::iterator addUserDefined(const std::string& name,
59  PlotGroup::Ptr group = {});
60 
61  StringSeriesMap::iterator addStringSeries(const std::string& name,
62  PlotGroup::Ptr group = {});
63 
64  PlotDataXY& getOrCreateScatterXY(const std::string& name, PlotGroup::Ptr group = {});
65 
66  PlotData& getOrCreateNumeric(const std::string& name, PlotGroup::Ptr group = {});
67 
68  StringSeries& getOrCreateStringSeries(const std::string& name,
69  PlotGroup::Ptr group = {});
70 
71  PlotDataAny& getOrCreateUserDefined(const std::string& name, PlotGroup::Ptr group = {});
72 
73  PlotGroup::Ptr getOrCreateGroup(const std::string& name);
74 
75  std::unordered_set<std::string> getAllNames() const;
76 
77  void clear();
78 
79  void setMaximumRangeX(double range);
80 
81  bool erase(const std::string& name);
82 };
83 
84 template <typename Value>
85 inline void AddPrefixToPlotData(const std::string& prefix,
86  std::unordered_map<std::string, Value>& data)
87 {
88  if (prefix.empty())
89  {
90  return;
91  }
92 
93  std::vector<std::string> temp_key;
94  temp_key.reserve(data.size());
95  std::vector<Value> temp_value;
96  temp_value.reserve(data.size());
97 
98  for (auto& it : data)
99  {
100  std::string key;
101  key.reserve(prefix.size() + 2 + it.first.size());
102  key = (it.first.front() == '/') ? (prefix + it.first) : (prefix + "/" + it.first);
103 
104  temp_key.emplace_back(key);
105  temp_value.emplace_back(std::move(it.second));
106  }
107 
108  data.clear();
109 
110  for (size_t i = 0; i < temp_key.size(); i++)
111  {
112  const std::string& key = temp_key[i];
113 
114  auto it = data.emplace(std::piecewise_construct, std::forward_as_tuple(key),
115  std::forward_as_tuple(key, PlotGroup::Ptr()))
116  .first;
117 
118  it->second = std::move(temp_value[i]);
119  }
120 }
121 
122 } // namespace PJ
123 
124 #endif // PJ_PLOTDATA_H
PJ::PlotDataMapRef::getOrCreateUserDefined
PlotDataAny & getOrCreateUserDefined(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:87
PJ::PlotDataMapRef::addScatterXY
ScatterXYMap::iterator addScatterXY(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:45
detail::first
auto first(const T &value, const Tail &...) -> const T &
Definition: compile.h:60
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::PlotDataMapRef::addStringSeries
StringSeriesMap::iterator addStringSeries(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:63
timeseries.h
PJ::PlotDataMapRef::addNumeric
TimeseriesMap::iterator addNumeric(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:51
stringseries.h
PJ::TimeseriesMap
std::unordered_map< std::string, PlotData > TimeseriesMap
The PlotDataMapRef is the main data structure used to store all the timeseries in a single place.
Definition: plotdata.h:29
PJ::PlotDataMapRef::erase
bool erase(const std::string &name)
Definition: plotdata.cpp:148
PJ::PlotDataMapRef::getOrCreateGroup
PlotGroup::Ptr getOrCreateGroup(const std::string &name)
Definition: plotdata.cpp:93
PJ::PlotDataMapRef::numeric
TimeseriesMap numeric
Numerical timeseries.
Definition: plotdata.h:39
PJ::PlotDataMapRef::setMaximumRangeX
void setMaximumRangeX(double range)
Definition: plotdata.cpp:132
PJ::PlotGroup::Ptr
std::shared_ptr< PlotGroup > Ptr
Definition: plotdatabase.h:83
PJ::AnySeriesMap
std::unordered_map< std::string, PlotDataAny > AnySeriesMap
Definition: plotdata.h:31
PJ::PlotData
TimeseriesBase< double > PlotData
Definition: plotdata.h:18
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:394
PJ::StringSeriesMap
std::unordered_map< std::string, StringSeries > StringSeriesMap
Definition: plotdata.h:32
PJ::PlotDataMapRef::getOrCreateScatterXY
PlotDataXY & getOrCreateScatterXY(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:69
PJ::PlotDataMapRef::scatter_xy
ScatterXYMap scatter_xy
Definition: plotdata.h:36
PJ::PlotDataMapRef::clear
void clear()
Definition: plotdata.cpp:125
PJ::PlotDataMapRef::addUserDefined
AnySeriesMap::iterator addUserDefined(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:57
PJ::PlotDataMapRef::groups
std::unordered_map< std::string, PlotGroup::Ptr > groups
Each series can have (optionally) a group. Groups can have their own properties.
Definition: plotdata.h:52
PJ::PlotDataMapRef::getOrCreateNumeric
PlotData & getOrCreateNumeric(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:75
plotdatabase.h
PJ::AddPrefixToPlotData
void AddPrefixToPlotData(const std::string &prefix, std::unordered_map< std::string, Value > &data)
Definition: plotdata.h:85
PJ
Definition: dataloader_base.h:16
PJ::ScatterXYMap
std::unordered_map< std::string, PlotDataXY > ScatterXYMap
Definition: plotdata.h:30
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
PJ::PlotDataMapRef::getAllNames
std::unordered_set< std::string > getAllNames() const
Definition: plotdata.cpp:107
PJ::PlotDataMapRef::getOrCreateStringSeries
StringSeries & getOrCreateStringSeries(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:81
PJ::PlotDataMapRef
Definition: plotdata.h:34
PJ::PlotDataMapRef::user_defined
AnySeriesMap user_defined
Definition: plotdata.h:43
PJ::PlotDataBase
Definition: plotdatabase.h:122
PJ::PlotDataXY
PlotDataBase< double, double > PlotDataXY
Definition: plotdata.h:17
PJ::PlotDataAny
TimeseriesBase< std::any > PlotDataAny
Definition: plotdata.h:19
PJ::PlotDataMapRef::strings
StringSeriesMap strings
Series of strings.
Definition: plotdata.h:46


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:23