22 #include "ns3/assert.h"
34 unsigned int m_references;
42 Data(
const std::string& title);
69 m_extra (m_defaultExtra)
87 : m_data (original.m_data)
94 if (--
m_data->m_references == 0)
100 if (
this != &original)
102 if (--
m_data->m_references == 0)
142 Data2d(
const std::string& title);
151 m_style (m_defaultStyle),
152 m_errorBars (m_defaultErrorBars)
168 os <<
" title '" << m_title <<
"'";
178 os <<
" with points";
181 os <<
" with xerrorbars";
184 os <<
" with yerrorbars";
187 os <<
" with xyerrorbars";
195 os <<
" with linespoints";
198 os <<
" with errorlines";
201 os <<
" with yerrorlines";
204 os <<
" with xyerrorlines";
212 os <<
" with impulses";
218 os <<
" with fsteps";
221 os <<
" with histeps";
226 os <<
" " << m_extra;
232 for (PointSet::const_iterator i = m_pointset.begin ();
233 i != m_pointset.end (); ++i)
240 switch (m_errorBars) {
242 os << i->x <<
" " << i->y << std::endl;
245 os << i->x <<
" " << i->y <<
" " << i->dx << std::endl;
248 os << i->x <<
" " << i->y <<
" " << i->dy << std::endl;
251 os << i->x <<
" " << i->y <<
" " << i->dx <<
" " << i->dy << std::endl;
255 os <<
"e" << std::endl;
271 m_defaultStyle = style;
282 m_defaultErrorBars = errorBars;
287 reinterpret_cast<Data2d*
>(
m_data)->m_errorBars = errorBars;
301 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back (data);
308 reinterpret_cast<Data2d*>(
m_data)->m_errorBars == Y );
314 data.dx = errorDelta;
315 data.dy = errorDelta;
316 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back (data);
328 data.dx = xErrorDelta;
329 data.dy = yErrorDelta;
330 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back (data);
338 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back (data);
347 std::string m_function;
352 Function2d(
const std::string& title,
const std::string&
function);
361 m_function (function)
377 os <<
" title '" << m_title <<
"'";
380 os <<
" " << m_extra;
414 Data3d(
const std::string& title);
423 m_style (m_defaultStyle)
439 os <<
" " << m_style;
442 os <<
" title '" << m_title <<
"'";
445 os <<
" " << m_extra;
451 for (PointSet::const_iterator i = m_pointset.begin ();
452 i != m_pointset.end (); ++i)
459 os << i->x <<
" " << i->y <<
" " << i->z << std::endl;
461 os <<
"e" << std::endl;
466 std::string Gnuplot3dDataset::m_defaultStyle =
"";
476 m_defaultStyle = style;
492 reinterpret_cast<Data3d*
>(
m_data)->m_pointset.push_back (data);
500 reinterpret_cast<Data3d*
>(
m_data)->m_pointset.push_back (data);
509 std::string m_function;
514 Function3d(
const std::string& title,
const std::string&
function);
523 m_function (function)
539 os <<
" title '" << m_title <<
"'";
542 os <<
" " << m_extra;
566 : m_outputFilename (outputFilename),
567 m_terminal ( DetectTerminal (outputFilename) ),
574 std::string::size_type dotpos = filename.rfind (
'.');
575 if (dotpos == std::string::npos)
return "";
577 if (filename.substr (dotpos) ==
".png") {
580 else if (filename.substr (dotpos) ==
".pdf") {
590 m_terminal = terminal;
622 m_datasets.push_back (dataset);
628 if (m_terminal.size ())
629 os <<
"set terminal " << m_terminal << std::endl;
631 if (m_outputFilename.size ())
632 os <<
"set output '" << m_outputFilename <<
"'" << std::endl;
635 os <<
"set title '" << m_title <<
"'" << std::endl;
637 if (m_xLegend.size ())
638 os <<
"set xlabel '" << m_xLegend <<
"'" << std::endl;
640 if (m_yLegend.size ())
641 os <<
"set ylabel '" << m_yLegend <<
"'" << std::endl;
644 os << m_extra << std::endl;
646 if (m_datasets.empty ())
652 std::string command = m_datasets.begin ()->m_data->GetCommand ();
654 for (Datasets::const_iterator i = m_datasets.begin () + 1;
655 i != m_datasets.end (); ++i)
658 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
661 os << command <<
" ";
665 for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end ();)
667 i->m_data->PrintExpression (os);
671 if (i != m_datasets.end ())
680 for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++)
682 i->m_data->PrintDatafile (os);
689 : m_outputFilename (outputFilename),
690 m_terminal (
Gnuplot::DetectTerminal (outputFilename) )
697 m_terminal = terminal;
703 m_plots.push_back (plot);
709 if (
id >= m_plots.size ())
710 throw(std::range_error (
"Gnuplot id is out of range"));
718 if (m_terminal.size ())
719 os <<
"set terminal " << m_terminal << std::endl;
721 if (m_outputFilename.size ())
722 os <<
"set output '" << m_outputFilename <<
"'" << std::endl;
724 for (Plots::const_iterator i = m_plots.begin (); i != m_plots.end (); ++i)
726 i->GenerateOutput (os);
virtual void PrintDatafile(std::ostream &os) const
void AppendExtra(const std::string &extra)
Function3d(const std::string &title, const std::string &function)
void SetTitle(const std::string &title)
Change line title.
virtual void PrintExpression(std::ostream &os) const =0
Abstract class to store a plot line to be used by ns3::Gnuplot.
Gnuplot(const std::string &outputFilename="", const std::string &title="")
virtual void PrintDatafile(std::ostream &os) const =0
Gnuplot2dDataset(const std::string &title="Untitled")
void GenerateOutput(std::ostream &os) const
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
void Add(double x, double y, double z)
#define NS_ASSERT(condition)
GnuplotDataset & operator=(const GnuplotDataset &original)
virtual std::string GetCommand() const
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
void SetFunction(const std::string &function)
void AddDataset(const GnuplotDataset &dataset)
Data3d(const std::string &title)
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
void SetErrorBars(enum ErrorBars errorBars)
virtual std::string GetCommand() const
Data2d(const std::string &title)
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void SetTitle(const std::string &title)
Gnuplot3dDataset(const std::string &title="Untitled")
Function2d(const std::string &title, const std::string &function)
void Add(double x, double y)
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
void AddPlot(const Gnuplot &plot)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
static void SetDefaultErrorBars(enum ErrorBars errorBars)
virtual std::string GetCommand() const =0
GnuplotCollection(const std::string &outputFilename)
static void SetDefaultStyle(enum Style style)
virtual void PrintDatafile(std::ostream &os) const
void SetStyle(enum Style style)
void SetExtra(const std::string &extra)
void SetStyle(const std::string &style)
#define NS_ASSERT_MSG(condition, message)
void SetTerminal(const std::string &terminal)
virtual void PrintExpression(std::ostream &os) const
void SetFunction(const std::string &function)
virtual void PrintExpression(std::ostream &os) const
virtual std::string GetCommand() const
virtual void PrintExpression(std::ostream &os) const
GnuplotDataset(const GnuplotDataset &original)
virtual std::string GetCommand() const
virtual void PrintDatafile(std::ostream &os) const
static void SetDefaultStyle(const std::string &style)
static std::string DetectTerminal(const std::string &filename)
void SetTerminal(const std::string &terminal)
Data(const std::string &title)
virtual void PrintExpression(std::ostream &os) const
void GenerateOutput(std::ostream &os) const
Gnuplot & GetPlot(unsigned int id)
virtual void PrintDatafile(std::ostream &os) const