From a29a4bde21e60425305543de7d7fb5d5d1b6a1bf Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 2 Jun 2014 17:04:20 +0200 Subject: [PATCH] Plot: caption modifier --- lib/Plot.cpp | 20 ++++++++++++++++++-- lib/Plot.hpp | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/Plot.cpp b/lib/Plot.cpp index bc031e2..e5f8889 100644 --- a/lib/Plot.cpp +++ b/lib/Plot.cpp @@ -162,6 +162,17 @@ PlotPredBand::PlotPredBand(const DoubleFunctionSample &function, /****************************************************************************** * Plot modifiers * ******************************************************************************/ +// Caption constructor ///////////////////////////////////////////////////////// +Caption::Caption(const string &caption) +: caption_(caption) +{} + +// Caption modifier //////////////////////////////////////////////////////////// +void Caption::operator()(PlotOptions &option) const +{ + option.caption = caption_; +} + // Color constructor /////////////////////////////////////////////////////////// Color::Color(const string &color) : color_(color) @@ -201,12 +212,12 @@ void PlotRange::operator()(PlotOptions &option) const option.scale[a].max = max_; } -// Title constructor /////////////////////////////////////////////////////////// +// Terminal constructor //////////////////////////////////////////////////////// Terminal::Terminal(const string &terminal, const std::string &options) : terminalCmd_(terminal + " " + options) {} -// Title modifier ////////////////////////////////////////////////////////////// +// Terminal modifier /////////////////////////////////////////////////////////// void Terminal::operator()(PlotOptions &option) const { option.terminal = terminalCmd_; @@ -257,6 +268,7 @@ void Plot::initOptions(void) { options_.terminal = ""; options_.output = ""; + options_.caption = ""; options_.title = ""; options_.scaleMode[0] = Plot::Scale::reset; options_.scaleMode[1] = Plot::Scale::reset; @@ -415,6 +427,10 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot) { out << "set output '" << plot.options_.terminal << "'" << endl; } + if (!plot.options_.caption.empty()) + { + out << "set title '" << plot.options_.caption << "'" << endl; + } if (plot.options_.scaleMode[x] & Plot::Scale::manual) { out << "xMin = " << plot.options_.scale[x].min << endl; diff --git a/lib/Plot.hpp b/lib/Plot.hpp index 75a16af..9e4154d 100644 --- a/lib/Plot.hpp +++ b/lib/Plot.hpp @@ -117,6 +117,7 @@ struct PlotOptions { std::string terminal; std::string output; + std::string caption; std::string title; unsigned int scaleMode[2]; Range scale[2]; @@ -133,6 +134,19 @@ public: virtual void operator()(PlotOptions &option) const = 0; }; +class Caption: public PlotModifier +{ +public: + // constructor + explicit Caption(const std::string &title); + // destructor + virtual ~Caption(void) = default; + // modifier + virtual void operator()(PlotOptions &option) const; +private: + const std::string caption_; +}; + class Color: public PlotModifier { public: @@ -186,7 +200,6 @@ private: const std::string terminalCmd_; }; - class Title: public PlotModifier { public: