22#include "ns3/assert.h"
51 Data(
const std::string& title);
77 bool generateOneOutputFile,
78 unsigned int dataFileDatasetIndex,
79 std::string& dataFileName)
const = 0;
88 virtual void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const = 0;
100 m_extra(m_defaultExtra)
118 : m_data(original.m_data)
134 if (
this != &original)
185 Data2d(
const std::string& title);
189 bool generateOneOutputFile,
190 unsigned int dataFileDatasetIndex,
191 std::string& dataFileName)
const override;
192 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
198 m_style(m_defaultStyle),
199 m_errorBars(m_defaultErrorBars)
211 bool generateOneOutputFile,
212 unsigned int dataFileDatasetIndex,
213 std::string& dataFileName)
const
217 if (generateOneOutputFile)
223 os <<
"\"" << dataFileName <<
"\" index " << dataFileDatasetIndex;
226 if (!m_title.empty())
228 os <<
" title \"" << m_title <<
"\"";
240 os <<
" with points";
243 os <<
" with xerrorbars";
246 os <<
" with yerrorbars";
249 os <<
" with xyerrorbars";
257 os <<
" with linespoints";
260 os <<
" with errorlines";
263 os <<
" with yerrorlines";
266 os <<
" with xyerrorlines";
274 os <<
" with impulses";
280 os <<
" with fsteps";
283 os <<
" with histeps";
287 if (!m_extra.empty())
289 os <<
" " << m_extra;
296 for (PointSet::const_iterator i = m_pointset.begin(); i != m_pointset.end(); ++i)
307 os << i->x <<
" " << i->y << std::endl;
310 os << i->x <<
" " << i->y <<
" " << i->dx << std::endl;
313 os << i->x <<
" " << i->y <<
" " << i->dy << std::endl;
316 os << i->x <<
" " << i->y <<
" " << i->dx <<
" " << i->dy << std::endl;
323 if (generateOneOutputFile)
325 os <<
"e" << std::endl;
337 return m_pointset.empty();
373 reinterpret_cast<Data2d*
>(
m_data)->m_errorBars = errorBars;
400 data.dx = errorDelta;
401 data.dy = errorDelta;
414 data.dx = xErrorDelta;
415 data.dy = yErrorDelta;
446 Function2d(
const std::string& title,
const std::string& function);
450 bool generateOneOutputFile,
451 unsigned int dataFileDatasetIndex,
452 std::string& dataFileName)
const override;
453 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
471 bool generateOneOutputFile,
472 unsigned int dataFileDatasetIndex,
473 std::string& dataFileName)
const
477 if (!m_title.empty())
479 os <<
" title \"" << m_title <<
"\"";
482 if (!m_extra.empty())
484 os <<
" " << m_extra;
531 Data3d(
const std::string& title);
535 bool generateOneOutputFile,
536 unsigned int dataFileDatasetIndex,
537 std::string& dataFileName)
const override;
538 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
544 m_style(m_defaultStyle)
556 bool generateOneOutputFile,
557 unsigned int dataFileDatasetIndex,
558 std::string& dataFileName)
const
562 if (!m_style.empty())
564 os <<
" " << m_style;
567 if (!m_title.empty())
569 os <<
" title \"" << m_title <<
"\"";
572 if (!m_extra.empty())
574 os <<
" " << m_extra;
581 for (PointSet::const_iterator i = m_pointset.begin(); i != m_pointset.end(); ++i)
589 os << i->x <<
" " << i->y <<
" " << i->z << std::endl;
591 os <<
"e" << std::endl;
597 return m_pointset.empty();
659 Function3d(
const std::string& title,
const std::string& function);
663 bool generateOneOutputFile,
664 unsigned int dataFileDatasetIndex,
665 std::string& dataFileName)
const override;
666 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
684 bool generateOneOutputFile,
685 unsigned int dataFileDatasetIndex,
686 std::string& dataFileName)
const
690 if (!m_title.empty())
692 os <<
" title \"" << m_title <<
"\"";
695 if (!m_extra.empty())
697 os <<
" " << m_extra;
728 : m_outputFilename(outputFilename),
729 m_terminal(DetectTerminal(outputFilename)),
731 m_generateOneOutputFile(false),
732 m_dataFileDatasetIndex(0)
745 std::string::size_type dotpos = filename.rfind(
'.');
746 if (dotpos == std::string::npos)
751 if (filename.substr(dotpos) ==
".png")
755 else if (filename.substr(dotpos) ==
".pdf")
817 osControl <<
"set terminal " <<
m_terminal << std::endl;
827 osControl <<
"set title \"" <<
m_title <<
"\"" << std::endl;
832 osControl <<
"set xlabel \"" <<
m_xLegend <<
"\"" << std::endl;
837 osControl <<
"set ylabel \"" <<
m_yLegend <<
"\"" << std::endl;
842 osControl <<
m_extra << std::endl;
853 std::string command =
m_datasets.begin()->m_data->GetCommand();
858 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
861 osControl << command <<
" ";
869 isDataEmpty = i->m_data->IsEmpty();
874 i->m_data->PrintExpression(osControl,
888 osControl << std::endl;
907 : m_outputFilename(outputFilename),
908 m_terminal(
Gnuplot::DetectTerminal(outputFilename))
929 throw(std::range_error(
"Gnuplot id is out of range"));
945 os <<
"set terminal " <<
m_terminal << std::endl;
953 for (Plots::iterator i =
m_plots.begin(); i !=
m_plots.end(); ++i)
955 i->GenerateOutput(os);
961 std::ostream& osData,
962 std::string dataFileName)
969 osControl <<
"set terminal " <<
m_terminal << std::endl;
977 for (Plots::iterator i =
m_plots.begin(); i !=
m_plots.end(); ++i)
979 i->GenerateOutput(osControl, osData, dataFileName);
void AddEmptyLine()
Add an empty line in the data output sequence.
static Style m_defaultStyle
default plot style
static void SetDefaultStyle(Style style)
Change default style for all newly created objects.
ErrorBars
Whether errorbars should be used for this dataset.
static void SetDefaultErrorBars(ErrorBars errorBars)
Change default errorbars style for all newly created objects.
void SetErrorBars(ErrorBars errorBars)
std::vector< Point > PointSet
The set of points in the dataset.
void SetStyle(Style style)
void Add(double x, double y)
Style
The plotting style to use for this dataset.
static ErrorBars m_defaultErrorBars
default error bars type
Gnuplot2dDataset(const std::string &title="Untitled")
void SetFunction(const std::string &function)
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
void AddEmptyLine()
Add an empty line in the data output sequence.
Gnuplot3dDataset(const std::string &title="Untitled")
std::vector< Point > PointSet
The set of points in the dataset.
static std::string m_defaultStyle
default plot style
void Add(double x, double y, double z)
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
void SetStyle(const std::string &style)
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
void SetFunction(const std::string &function)
std::string m_outputFilename
Output file name.
GnuplotCollection(const std::string &outputFilename)
void AddPlot(const Gnuplot &plot)
void SetTerminal(const std::string &terminal)
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
std::string m_terminal
Gnuplot "terminal" to use.
Plots m_plots
Plots in the collection.
void GenerateOutput(std::ostream &os)
Abstract class to store a plot line to be used by ns3::Gnuplot.
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Data * m_data
Reference counted data object.
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
void SetTitle(const std::string &title)
Change line title.
~GnuplotDataset()
Reference-counting destructor.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
std::string m_yLegend
Y axis legend.
void AddDataset(const GnuplotDataset &dataset)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void SetTerminal(const std::string &terminal)
std::string m_terminal
Gnuplot "terminal" to use.
std::string m_extra
extra parameters for the plot
unsigned int m_dataFileDatasetIndex
Data set index to plot.
void AppendExtra(const std::string &extra)
Datasets m_datasets
Data sets.
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
std::string m_title
Plot title.
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
std::string m_xLegend
X axis legend.
std::string m_outputFilename
Output file name.
Gnuplot(const std::string &outputFilename="", const std::string &title="")
void SetExtra(const std::string &extra)
void SetTitle(const std::string &title)
void SetOutputFilename(const std::string &outputFilename)
bool m_generateOneOutputFile
true if only one plot will be generated
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename's extension.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure storing the data to for a 2D plot.
Style m_style
The plotting style to use for this dataset.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
PointSet m_pointset
The set of points in this data set.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
ErrorBars m_errorBars
Whether errorbars should be used for this dataset.
Structure storing the function to be used for a 2D plot.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
std::string m_function
Function to use.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Structure storing the data for a 3D plot.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
std::string m_style
The plotting style to use for this dataset.
PointSet m_pointset
The set of points in this data set.
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
Structure storing the function to be used for a 3D plot.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
std::string m_function
Function to use.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Structure storing the data to plot.
unsigned int m_references
ref/unref counter for garbage collection
std::string m_extra
Extra parameters for the plot.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const =0
Prints the plot description used as argument to (s)plot.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const =0
Print the inline data file contents trailing the plot command.
virtual bool IsEmpty() const =0
Checks to see if this GnuplotDataset is empty.
Data(const std::string &title)
Initializes the reference counter to 1 and sets m_title and m_extra.
std::string m_title
Dataset title.
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").