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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: L. Felipe Perrone (perrone@bucknell.edu)
7 *
8 * Modified by: Mitch Watrous (watrous@u.washington.edu)
9 *
10 */
11
12#ifndef GNUPLOT_AGGREGATOR_H
13#define GNUPLOT_AGGREGATOR_H
14
16#include "gnuplot.h"
17
18#include <map>
19#include <string>
20
21namespace ns3
22{
23
24/**
25 * \ingroup aggregator
26 * This aggregator produces output used to make gnuplot plots.
27 **/
29{
30 public:
31 /// The location of the key in the plot.
39
40 /**
41 * \brief Get the type ID.
42 * \return the object TypeId
43 */
44 static TypeId GetTypeId();
45
46 /**
47 * \param outputFileNameWithoutExtension name of gnuplot related
48 * files to write with no extension
49 *
50 * Constructs a gnuplot file aggregator that will create a space
51 * separated gnuplot data file named outputFileNameWithoutExtension
52 * + ".dat", a gnuplot control file named
53 * outputFileNameWithoutExtension + ".plt", and a shell script to
54 * generate the gnuplot named outputFileNameWithoutExtension +
55 * ".sh".
56 */
57 GnuplotAggregator(const std::string& outputFileNameWithoutExtension);
58
59 ~GnuplotAggregator() override;
60
61 // Below are hooked to connectors exporting data
62 // They are not overloaded since it confuses the compiler when made
63 // into callbacks
64
65 /**
66 * \param context specifies the gnuplot 2D dataset for these values
67 * \param x x coordinate for the new data point
68 * \param y y coordinate for the new data point
69 *
70 * \brief Writes a 2D value to a 2D gnuplot dataset.
71 *
72 * Use this method with error bar style NONE.
73 */
74 void Write2d(std::string context, double x, double y);
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 * \param errorDelta x data point uncertainty
81 *
82 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
83 * in the x direction.
84 *
85 * Use this method with error bar style X.
86 */
87 void Write2dWithXErrorDelta(std::string context, double x, double y, double errorDelta);
88
89 /**
90 * \param context specifies the gnuplot 2D dataset for these values
91 * \param x x coordinate for the new data point
92 * \param y y coordinate for the new data point
93 * \param errorDelta y data point uncertainty
94 *
95 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
96 * in the y direction.
97 *
98 * Use this method with error bar style Y.
99 */
100 void Write2dWithYErrorDelta(std::string context, double x, double y, double errorDelta);
101
102 /**
103 * \param context specifies the gnuplot 2D dataset for these values
104 * \param x x coordinate for the new data point
105 * \param y y coordinate for the new data point
106 * \param xErrorDelta x data point uncertainty
107 * \param yErrorDelta y data point uncertainty
108 *
109 * \brief Writes a 2D value to a 2D gnuplot dataset with error bars
110 * in the x and y directions.
111 *
112 * Use this method with error bar style XY.
113 */
114 void Write2dWithXYErrorDelta(std::string context,
115 double x,
116 double y,
117 double xErrorDelta,
118 double yErrorDelta);
119
120 // Methods to configure the plot
121
122 /**
123 * \param terminal terminal setting string for output. The default terminal
124 * string is "png"
125 */
126 void SetTerminal(const std::string& terminal);
127
128 /**
129 * \param title set new plot title string to use for this plot.
130 */
131 void SetTitle(const std::string& title);
132
133 /**
134 * \param xLegend the legend for the x horizontal axis
135 * \param yLegend the legend for the y vertical axis
136 */
137 void SetLegend(const std::string& xLegend, const std::string& yLegend);
138
139 /**
140 * \param extra set extra gnuplot directive for output.
141 */
142 void SetExtra(const std::string& extra);
143
144 /**
145 * \param extra append extra gnuplot directive for output.
146 */
147 void AppendExtra(const std::string& extra);
148
149 // Methods for datasets
150
151 /**
152 * \param dataset the gnuplot 2D dataset to be plotted.
153 * \param title the title to be associated to this dataset.
154 *
155 * \brief Adds a 2D dataset to the plot.
156 *
157 * Creates an empty dataset. Usually, the dataset's title is
158 * displayed in the legend box.
159 *
160 * The string in dataset should match the context for the Collector
161 * it is connected to.
162 */
163 void Add2dDataset(const std::string& dataset, const std::string& title);
164
165 /**
166 * \param extra extra formatting
167 *
168 * \brief Change extra formatting style parameters for newly created
169 * objects.
170 */
171 static void Set2dDatasetDefaultExtra(const std::string& extra);
172
173 /**
174 * \param dataset the gnuplot 2D dataset to be plotted.
175 * \param extra extra formatting
176 *
177 * \brief Add extra formatting parameters to this dataset.
178 *
179 * The string in dataset should match the context for the Collector
180 * it is connected to.
181 */
182 void Set2dDatasetExtra(const std::string& dataset, const std::string& extra);
183
184 /**
185 * \param dataset the gnuplot 2D dataset to be plotted.
186 *
187 * \brief Add an empty line in the data output sequence.
188 *
189 * Writes an empty line in the plot data, which breaks continuous
190 * lines and does other things in the output.
191 *
192 * The string in dataset should match the context for the Collector
193 * it is connected to.
194 */
195 void Write2dDatasetEmptyLine(const std::string& dataset);
196
197 /**
198 * \param style the style of plotting to use for newly created datasets.
199 *
200 * \brief Change default style for all newly created objects.
201 */
203
204 /**
205 * \param dataset the gnuplot 2D dataset to be plotted.
206 * \param style the style of plotting to use for this dataset.
207 *
208 * \brief Set the style of plotting to use for this dataset.
209 *
210 * The string in dataset should match the context for the Collector
211 * it is connected to.
212 */
213 void Set2dDatasetStyle(const std::string& dataset, Gnuplot2dDataset::Style style);
214
215 /**
216 * \param errorBars the style of errorbars to use for newly created datasets.
217 *
218 * \brief Change default errorbars style for all newly created objects.
219 */
221
222 /**
223 * \param dataset the gnuplot 2D dataset to be plotted.
224 * \param errorBars the style of errorbars to display.
225 *
226 * \brief Set the error bars to use for this dataset.
227 *
228 * If you use any style other than none, you need
229 * to make sure you store the delta information in
230 * this dataset with the right GnuplotDataset::Add
231 * method.
232 *
233 * The string in dataset should match the context for the Collector
234 * it is connected to.
235 */
236 void Set2dDatasetErrorBars(const std::string& dataset, Gnuplot2dDataset::ErrorBars errorBars);
237
238 /**
239 * \param keyLocation the location of the key in the plot.
240 *
241 * \brief Set the location of the key in the plot.
242 */
243 void SetKeyLocation(KeyLocation keyLocation);
244
245 private:
246 /// The output file name without any extension.
248
249 /// The graphics file name with its extension.
251
252 /// The title.
253 std::string m_title;
254
255 /// The terminal.
256 std::string m_terminal;
257
258 /// The x legend.
259 std::string m_xLegend;
260
261 /// The y legend.
262 std::string m_yLegend;
263
264 /// The extra gnuplot command that will be added to the gnuplot
265 /// control statements.
266 std::string m_extra;
267
268 /// Set equal to true after setting the title.
270
271 /// Set equal to true after setting the x and y legends.
273
274 /// Used to create gnuplot files.
276
277 /// Maps context strings to 2D datasets.
278 std::map<std::string, Gnuplot2dDataset> m_2dDatasetMap;
279
280}; // class GnuplotAggregator
281
282} // namespace ns3
283
284#endif // GNUPLOT_AGGREGATOR_H
Base class for data collection framework objects.
ErrorBars
Whether errorbars should be used for this dataset.
Definition gnuplot.h:126
Style
The plotting style to use for this dataset.
Definition gnuplot.h:111
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.
GnuplotAggregator(const std::string &outputFileNameWithoutExtension)
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:359
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.