dummy_data.cpp
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 #include "dummy_data.h"
8 #include <QColor>
9 
10 using namespace PJ;
11 
13 {
14  size_t SIZE = 1000;
15  QStringList words_list;
16  words_list << "world/siam"
17  << "world/tre"
18  << "walk/piccoli"
19  << "walk/porcellin"
20  << "fly/high/mai"
21  << "fly/high/nessun"
22  << "fly/low/ci"
23  << "fly/low/dividera"
24  << "data_1"
25  << "data_2"
26  << "data_3"
27  << "data_10";
28 
29  for (int i = 0; i < 100; i++)
30  {
31  words_list.append(QString("data_vect/%1").arg(i));
32  }
33 
34  for (const QString& name : words_list)
35  {
36  double A = 6 * ((double)rand() / (double)RAND_MAX) - 3;
37  double B = 3 * ((double)rand() / (double)RAND_MAX);
38  double C = 3 * ((double)rand() / (double)RAND_MAX);
39  double D = 20 * ((double)rand() / (double)RAND_MAX);
40 
41  auto it = datamap.addNumeric(name.toStdString());
42  PlotData& plot = it->second;
43 
44  double t = 0;
45  for (unsigned indx = 0; indx < SIZE; indx++)
46  {
47  t += 0.01;
48  plot.pushBack(PlotData::Point(t + 35, A * sin(B * t + C) + D * t * 0.02));
49  }
50  }
51 
52  //-------------------------------
53  auto tcGroup = datamap.getOrCreateGroup("myGroup/subGroup");
54  tcGroup->setAttribute(PJ::TEXT_COLOR, QColor(Qt::blue));
55  tcGroup->setAttribute(PJ::TOOL_TIP, QString("This is a group"));
56 
57  auto& tc_default = datamap.addNumeric("color/default", tcGroup)->second;
58  auto& tc_red = datamap.addNumeric("color/red", tcGroup)->second;
59 
60  tc_red.setAttribute(PJ::TEXT_COLOR, QColor(Qt::red));
61 
62  PlotData& sin_plot = datamap.addNumeric("_sin")->second;
63  PlotData& cos_plot = datamap.addNumeric("_cos")->second;
64  StringSeries& str_plot = datamap.addStringSeries("str_value")->second;
65 
66  sin_plot.setAttribute(PJ::TOOL_TIP, QString("sine"));
67  cos_plot.setAttribute(PJ::TOOL_TIP, QString("cosine"));
68  str_plot.setAttribute(PJ::TOOL_TIP, QString("this is a string"));
69 
70  sin_plot.setAttribute(PJ::ITALIC_FONTS, true);
71 
72  //--------------------------------
73  double t = 0;
74  for (unsigned indx = 0; indx < SIZE; indx++)
75  {
76  t += 0.01;
77  sin_plot.pushBack(PlotData::Point(t + 20, sin(t * 0.4)));
78  cos_plot.pushBack(PlotData::Point(t + 20, cos(t * 0.4)));
79  tc_default.pushBack(PlotData::Point(t + 20, indx));
80  tc_default.pushBack(PlotData::Point(t + 20, indx));
81 
82  switch (indx % 3)
83  {
84  case 0:
85  str_plot.pushBack({ t + 20, "Blue" });
86  break;
87  case 1:
88  str_plot.pushBack({ t + 20, "Red" });
89  break;
90  case 2:
91  str_plot.pushBack({ t + 20, "Green" });
92  break;
93  }
94  }
95 
96  PlotDataXY& octagon = datamap.addScatterXY("octagon_trajectory")->second;
97  for (unsigned i = 0; i < 8; i++)
98  {
99  double angle = double(i) * M_PI / 4;
100  octagon.pushBack(PlotData::Point(cos(angle), sin(angle)));
101  }
102 }
PJ::PlotDataMapRef::addScatterXY
ScatterXYMap::iterator addScatterXY(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:45
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::PlotDataMapRef::addStringSeries
StringSeriesMap::iterator addStringSeries(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:63
PJ::StringSeries::pushBack
void pushBack(const Point &p) override
Definition: stringseries.h:39
PJ::TimeseriesBase::pushBack
void pushBack(const Point &p) override
Definition: timeseries.h:61
PJ::PlotDataMapRef::addNumeric
TimeseriesMap::iterator addNumeric(const std::string &name, PlotGroup::Ptr group={})
Definition: plotdata.cpp:51
arg
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1875
PJ::PlotDataMapRef::getOrCreateGroup
PlotGroup::Ptr getOrCreateGroup(const std::string &name)
Definition: plotdata.cpp:93
PJ::PlotDataBase::setAttribute
void setAttribute(PlotAttribute id, const QVariant &value)
Definition: plotdatabase.h:230
M_PI
#define M_PI
Definition: qwt_math.h:56
PJ::ITALIC_FONTS
@ ITALIC_FONTS
Definition: plotdatabase.h:47
PJ::TimeseriesBase::Point
typename PlotDataBase< double, Value >::Point Point
Definition: timeseries.h:23
dummy_data.h
PJ::PlotDataBase::pushBack
virtual void pushBack(const Point &p)
Definition: plotdatabase.h:325
PJ::TEXT_COLOR
@ TEXT_COLOR
Definition: plotdatabase.h:43
BuildDummyData
void BuildDummyData(PlotDataMapRef &datamap)
Definition: dummy_data.cpp:12
PJ::TOOL_TIP
@ TOOL_TIP
Definition: plotdatabase.h:51
C
#define C(name, bit)
Definition: zstd.c:4811
B
#define B(name, bit)
PJ
Definition: dataloader_base.h:16
PJ::PlotDataMapRef
Definition: plotdata.h:34
PJ::PlotDataBase
Definition: plotdatabase.h:122
D
#define D(name, bit)
PJ::StringSeries
Definition: stringseries.h:17


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44