Robowflex  v0.1
Making MoveIt Easy
robowflex::IO::GNUPlotHelper Class Reference

Helper class to open a pipe to a GNUPlot instance for live visualization of data. More...

#include <gnuplot.h>

Classes

struct  BoxPlotOptions
 Box plotting options. More...
 
class  Instance
 
struct  PlottingOptions
 
struct  TimeSeriesOptions
 Time series plotting options. More...
 

Public Types

using Point = std::pair< double, double >
 
using Series = std::vector< Point >
 
using Values = std::vector< double >
 

Public Member Functions

 GNUPlotHelper ()=default
 
 GNUPlotHelper (GNUPlotHelper const &)=delete
 
void operator= (GNUPlotHelper const &)=delete
 
Plotting
void configurePlot (const PlottingOptions &options)
 Configure a plot using common options. More...
 
void timeseries (const TimeSeriesOptions &options)
 Plot timeseries data. More...
 
void boxplot (const BoxPlotOptions &options)
 Plot box data. More...
 

Private Member Functions

std::shared_ptr< InstancegetInstance (const std::string &name)
 Get the named GNUPlot instance. More...
 

Private Attributes

std::map< std::string, std::shared_ptr< Instance > > instances_
 Map of open GNUPlot instances. More...
 

Detailed Description

Helper class to open a pipe to a GNUPlot instance for live visualization of data.

Definition at line 20 of file gnuplot.h.

Member Typedef Documentation

◆ Point

Definition at line 23 of file gnuplot.h.

◆ Series

Definition at line 24 of file gnuplot.h.

◆ Values

Definition at line 25 of file gnuplot.h.

Constructor & Destructor Documentation

◆ GNUPlotHelper() [1/2]

robowflex::IO::GNUPlotHelper::GNUPlotHelper ( )
default

◆ GNUPlotHelper() [2/2]

robowflex::IO::GNUPlotHelper::GNUPlotHelper ( GNUPlotHelper const &  )
delete

Member Function Documentation

◆ boxplot()

void GNUPlotHelper::boxplot ( const BoxPlotOptions options)

Plot box data.

Parameters
[in]optionsPlotting options.

Definition at line 112 of file gnuplot.cpp.

113 {
114  configurePlot(options);
115  auto in = getInstance(options.instance);
116 
117  in->writeline("set datafile separator \",\"");
118 
119  in->writeline("set style data boxplot");
120  in->writeline("set style fill solid 0.5 border -1");
121  in->writeline("unset key");
122 
123  if (options.sorted)
124  in->writeline("set style boxplot sorted");
125 
126  if (options.outliers)
127  in->writeline("set style boxplot outliers pointtype 7");
128  else
129  in->writeline("set style boxplot nooutliers");
130 
131  auto n = options.values.size();
132 
133  in->write("set xtics (");
134  auto it1 = options.values.begin();
135  for (std::size_t i = 0; i < n; ++i, ++it1)
136  {
137  in->write(log::format("\"%1%\" %2%", it1->first, i + 1));
138  if (i != n - 1)
139  in->write(", ");
140  }
141  in->writeline(") scale 0.0");
142 
143  in->write("plot ");
144  for (std::size_t i = 0; i < n; ++i)
145  {
146  in->write(log::format("'%1%' using (%2%):1", //
147  (i == 0) ? "-" : "", //
148  i + 1));
149  if (i != n - 1)
150  in->write(", ");
151  }
152 
153  in->flush();
154 
155  auto it2 = options.values.begin();
156  for (std::size_t i = 0; i < n; ++i, ++it2)
157  {
158  for (const auto &point : it2->second)
159  in->writeline(log::format("%1%", point));
160 
161  in->writeline("e");
162  }
163 }
std::shared_ptr< Instance > getInstance(const std::string &name)
Get the named GNUPlot instance.
Definition: gnuplot.cpp:165
void configurePlot(const PlottingOptions &options)
Configure a plot using common options.
Definition: gnuplot.cpp:54
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Definition: log.h:60

◆ configurePlot()

void GNUPlotHelper::configurePlot ( const PlottingOptions options)

Configure a plot using common options.

Definition at line 54 of file gnuplot.cpp.

55 {
56  auto in = getInstance(options.instance);
57 
58  in->writeline(log::format("set term %1% noraise", options.mode));
59  in->writeline(log::format("set title \"%1%\"", options.title));
60 
61  if (not options.x.label.empty())
62  in->writeline(log::format("set xlabel \"%1%\"", options.x.label));
63 
64  if (std::isfinite(options.x.max))
65  in->writeline(log::format("set xrange [:%1%]", options.x.max));
66 
67  if (std::isfinite(options.x.min))
68  in->writeline(log::format("set xrange [%1%:]", options.x.min));
69 
70  if (not options.y.label.empty())
71  in->writeline(log::format("set ylabel \"%1%\"", options.y.label));
72 
73  if (std::isfinite(options.y.max))
74  in->writeline(log::format("set yrange [:%1%]", options.y.max));
75 
76  if (std::isfinite(options.y.min))
77  in->writeline(log::format("set yrange [%1%:]", options.y.min));
78 }
T isfinite(T... args)

◆ getInstance()

std::shared_ptr< GNUPlotHelper::Instance > GNUPlotHelper::getInstance ( const std::string name)
private

Get the named GNUPlot instance.

Parameters
[in]nameName of instance.
Returns
The instance.

Definition at line 165 of file gnuplot.cpp.

166 {
167  if (instances_.find(name) == instances_.end())
168  instances_.emplace(name, std::make_shared<Instance>());
169 
170  return instances_.find(name)->second;
171 }
std::map< std::string, std::shared_ptr< Instance > > instances_
Map of open GNUPlot instances.
Definition: gnuplot.h:123

◆ operator=()

void robowflex::IO::GNUPlotHelper::operator= ( GNUPlotHelper const &  )
delete

◆ timeseries()

void GNUPlotHelper::timeseries ( const TimeSeriesOptions options)

Plot timeseries data.

Parameters
[in]optionsPlotting options.

Definition at line 80 of file gnuplot.cpp.

81 {
82  configurePlot(options);
83  auto in = getInstance(options.instance);
84 
85  in->writeline("set datafile separator \",\"");
86  in->write("plot ");
87 
88  auto n = options.points.size();
89 
90  auto it1 = options.points.begin();
91  for (std::size_t i = 0; i < n; ++i, ++it1)
92  {
93  in->write(log::format("'%1%' using 1:2 with lines lw 2 title \"%2%\"", //
94  (i == 0) ? "-" : "", //
95  it1->first));
96  if (i != n - 1)
97  in->write(", ");
98  }
99 
100  in->flush();
101 
102  auto it2 = options.points.begin();
103  for (std::size_t i = 0; i < n; ++i, ++it2)
104  {
105  for (const auto &point : it2->second)
106  in->writeline(log::format("%1%,%2%", point.first, point.second));
107 
108  in->writeline("e");
109  }
110 }

Member Data Documentation

◆ instances_

std::map<std::string, std::shared_ptr<Instance> > robowflex::IO::GNUPlotHelper::instances_
private

Map of open GNUPlot instances.

Definition at line 123 of file gnuplot.h.


The documentation for this class was generated from the following files: