A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gnuplot-aggregator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Bucknell University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: L. Felipe Perrone (perrone@bucknell.edu)
18 *
19 * Modified by: Mitch Watrous (watrous@u.washington.edu)
20 *
21 */
22
23#ifndef GNUPLOT_AGGREGATOR_H
24#define GNUPLOT_AGGREGATOR_H
25
27#include "gnuplot.h"
28
29#include <map>
30#include <string>
31
32namespace ns3
33{
34
35/**
36 * \ingroup aggregator
37 * This aggregator produces output used to make gnuplot plots.
38 **/
40{
41 public:
42 /// The location of the key in the plot.
44 {
49 };
50
51 /**
52 * \brief Get the type ID.
53 * \return the object TypeId
54 */
55 static TypeId GetTypeId();
56
57 /**
58 * \param outputFileNameWithoutExtension name of gnuplot related
59 * files to write with no extension
60 *
61 * Constructs a gnuplot file aggregator that will create a space
62 * separated gnuplot data file named outputFileNameWithoutExtension
63 * + ".dat", a gnuplot control file named
64 * outputFileNameWithoutExtension + ".plt", and a shell script to
65 * generate the gnuplot named outputFileNameWithoutExtension +
66 * ".sh".
67 */
68 GnuplotAggregator(const std::string& outputFileNameWithoutExtension);
69
70 ~GnuplotAggregator() override;
71
72 // Below are hooked to connectors exporting data
73 // They are not overloaded since it confuses the compiler when made
74 // into callbacks
75
76 /**
77 * \param context specifies the gnuplot 2D dataset for these values
78 * \param x x coordinate for the new data point
79 * \param y y coordinate for the new data point
80 *
81 * \brief Writes a 2D value to a 2D gnuplot dataset.
82 *
83 * Use this method with error bar style NONE.
84 */
85 void Write2d(std::string context, double x, double y);
86
87 /**
88 * \param context specifies the gnuplot 2D dataset for these values
89 * \param x x coordinate for the new data point
90 * \param y y coordinate for the new data point
91 * \param errorDelta x data point uncertainty
92 *
93 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
94 * in the x direction.
95 *
96 * Use this method with error bar style X.
97 */
98 void Write2dWithXErrorDelta(std::string context, double x, double y, double errorDelta);
99
100 /**
101 * \param context specifies the gnuplot 2D dataset for these values
102 * \param x x coordinate for the new data point
103 * \param y y coordinate for the new data point
104 * \param errorDelta y data point uncertainty
105 *
106 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
107 * in the y direction.
108 *
109 * Use this method with error bar style Y.
110 */
111 void Write2dWithYErrorDelta(std::string context, double x, double y, double errorDelta);
112
113 /**
114 * \param context specifies the gnuplot 2D dataset for these values
115 * \param x x coordinate for the new data point
116 * \param y y coordinate for the new data point
117 * \param xErrorDelta x data point uncertainty
118 * \param yErrorDelta y data point uncertainty
119 *
120 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
121 * in the x and y directions.
122 *
123 * Use this method with error bar style XY.
124 */
125 void Write2dWithXYErrorDelta(std::string context,
126 double x,
127 double y,
128 double xErrorDelta,
129 double yErrorDelta);
130
131 // Methods to configure the plot
132
133 /**
134 * \param terminal terminal setting string for output. The default terminal
135 * string is "png"
136 */
137 void SetTerminal(const std::string& terminal);
138
139 /**
140 * \param title set new plot title string to use for this plot.
141 */
142 void SetTitle(const std::string& title);
143
144 /**
145 * \param xLegend the legend for the x horizontal axis
146 * \param yLegend the legend for the y vertical axis
147 */
148 void SetLegend(const std::string& xLegend, const std::string& yLegend);
149
150 /**
151 * \param extra set extra gnuplot directive for output.
152 */
153 void SetExtra(const std::string& extra);
154
155 /**
156 * \param extra append extra gnuplot directive for output.
157 */
158 void AppendExtra(const std::string& extra);
159
160 // Methods for datasets
161
162 /**
163 * \param dataset the gnuplot 2D dataset to be plotted.
164 * \param title the title to be associated to this dataset.
165 *
166 * \brief Adds a 2D dataset to the plot.
167 *
168 * Creates an empty dataset. Usually, the dataset's title is
169 * displayed in the legend box.
170 *
171 * The string in dataset should match the context for the Collector
172 * it is connected to.
173 */
174 void Add2dDataset(const std::string& dataset, const std::string& title);
175
176 /**
177 * \param extra extra formatting
178 *
179 * \brief Change extra formatting style parameters for newly created
180 * objects.
181 */
182 static void Set2dDatasetDefaultExtra(const std::string& extra);
183
184 /**
185 * \param dataset the gnuplot 2D dataset to be plotted.
186 * \param extra extra formatting
187 *
188 * \brief Add extra formatting parameters to this dataset.
189 *
190 * The string in dataset should match the context for the Collector
191 * it is connected to.
192 */
193 void Set2dDatasetExtra(const std::string& dataset, const std::string& extra);
194
195 /**
196 * \param dataset the gnuplot 2D dataset to be plotted.
197 *
198 * \brief Add an empty line in the data output sequence.
199 *
200 * Writes an empty line in the plot data, which breaks continuous
201 * lines and does other things in the output.
202 *
203 * The string in dataset should match the context for the Collector
204 * it is connected to.
205 */
206 void Write2dDatasetEmptyLine(const std::string& dataset);
207
208 /**
209 * \param style the style of plotting to use for newly created datasets.
210 *
211 * \brief Change default style for all newly created objects.
212 */
214
215 /**
216 * \param dataset the gnuplot 2D dataset to be plotted.
217 * \param style the style of plotting to use for this dataset.
218 *
219 * \brief Set the style of plotting to use for this dataset.
220 *
221 * The string in dataset should match the context for the Collector
222 * it is connected to.
223 */
224 void Set2dDatasetStyle(const std::string& dataset, Gnuplot2dDataset::Style style);
225
226 /**
227 * \param errorBars the style of errorbars to use for newly created datasets.
228 *
229 * \brief Change default errorbars style for all newly created objects.
230 */
232
233 /**
234 * \param dataset the gnuplot 2D dataset to be plotted.
235 * \param errorBars the style of errorbars to display.
236 *
237 * \brief Set the error bars to use for this dataset.
238 *
239 * If you use any style other than none, you need
240 * to make sure you store the delta information in
241 * this dataset with the right GnuplotDataset::Add
242 * method.
243 *
244 * The string in dataset should match the context for the Collector
245 * it is connected to.
246 */
247 void Set2dDatasetErrorBars(const std::string& dataset, Gnuplot2dDataset::ErrorBars errorBars);
248
249 /**
250 * \param keyLocation the location of the key in the plot.
251 *
252 * \brief Set the location of the key in the plot.
253 */
254 void SetKeyLocation(KeyLocation keyLocation);
255
256 private:
257 /// The output file name without any extension.
259
260 /// The graphics file name with its extension.
262
263 /// The title.
264 std::string m_title;
265
266 /// The terminal.
267 std::string m_terminal;
268
269 /// The x legend.
270 std::string m_xLegend;
271
272 /// The y legend.
273 std::string m_yLegend;
274
275 /// The extra gnuplot command that will be added to the gnuplot
276 /// control statements.
277 std::string m_extra;
278
279 /// Set equal to true after setting the title.
281
282 /// Set equal to true after setting the x and y legends.
284
285 /// Used to create gnuplot files.
287
288 /// Maps context strings to 2D datasets.
289 std::map<std::string, Gnuplot2dDataset> m_2dDatasetMap;
290
291}; // class GnuplotAggregator
292
293} // namespace ns3
294
295#endif // GNUPLOT_AGGREGATOR_H
Base class for data collection framework objects.
ErrorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.h:137
Style
The plotting style to use for this dataset.
Definition: gnuplot.h:122
This aggregator produces output used to make gnuplot plots.
void Write2dDatasetEmptyLine(const std::string &dataset)
Add an empty line in the data output sequence.
std::string m_title
The title.
void Write2dWithXErrorDelta(std::string context, double x, double y, double errorDelta)
Writes a 2D value to a 2D gnuplot dataset with error bars in the x direction.
static void Set2dDatasetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Gnuplot m_gnuplot
Used to create gnuplot files.
void Write2d(std::string context, double x, double y)
Writes a 2D value to a 2D gnuplot dataset.
std::string m_graphicsFileName
The graphics file name with its extension.
bool m_xAndYLegendsSet
Set equal to true after setting the x and y legends.
void Set2dDatasetExtra(const std::string &dataset, const std::string &extra)
Add extra formatting parameters to this dataset.
std::string m_yLegend
The y legend.
void AppendExtra(const std::string &extra)
void Write2dWithYErrorDelta(std::string context, double x, double y, double errorDelta)
Writes a 2D value to a 2D gnuplot dataset with error bars in the y direction.
std::string m_outputFileNameWithoutExtension
The output file name without any extension.
static TypeId GetTypeId()
Get the type ID.
bool m_titleSet
Set equal to true after setting the title.
static void Set2dDatasetDefaultStyle(Gnuplot2dDataset::Style style)
Change default style for all newly created objects.
std::string m_terminal
The terminal.
std::string m_xLegend
The x legend.
void Write2dWithXYErrorDelta(std::string context, double x, double y, double xErrorDelta, double yErrorDelta)
Writes a 2D value to a 2D gnuplot dataset with error bars in the x and y directions.
std::string m_extra
The extra gnuplot command that will be added to the gnuplot control statements.
KeyLocation
The location of the key in the plot.
void SetTerminal(const std::string &terminal)
void Add2dDataset(const std::string &dataset, const std::string &title)
Adds a 2D dataset to the plot.
std::map< std::string, Gnuplot2dDataset > m_2dDatasetMap
Maps context strings to 2D datasets.
static void Set2dDatasetDefaultErrorBars(Gnuplot2dDataset::ErrorBars errorBars)
Change default errorbars style for all newly created objects.
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void Set2dDatasetErrorBars(const std::string &dataset, Gnuplot2dDataset::ErrorBars errorBars)
Set the error bars to use for this dataset.
void Set2dDatasetStyle(const std::string &dataset, Gnuplot2dDataset::Style style)
Set the style of plotting to use for this dataset.
void SetKeyLocation(KeyLocation keyLocation)
Set the location of the key in the plot.
void SetTitle(const std::string &title)
void SetExtra(const std::string &extra)
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:370
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.