2014-02-10 11:22:27 +00:00
|
|
|
/*
|
|
|
|
* Plot.hpp, part of LatAnalyze 3
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_Plot_hpp_
|
|
|
|
#define Latan_Plot_hpp_
|
|
|
|
|
2014-03-03 14:21:37 +00:00
|
|
|
#include <latan/Global.hpp>
|
|
|
|
#include <latan/XYStatData.hpp>
|
2014-02-10 11:22:27 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <stack>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// gnuplot default parameters
|
|
|
|
#ifndef GNUPLOT_BIN
|
|
|
|
#define GNUPLOT_BIN "gnuplot"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GNUPLOT_ARGS
|
|
|
|
#define GNUPLOT_ARGS "-p"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
2014-03-03 12:41:48 +00:00
|
|
|
* Plot objects *
|
2014-02-10 11:22:27 +00:00
|
|
|
******************************************************************************/
|
2014-03-03 12:41:48 +00:00
|
|
|
class PlotObject
|
2014-02-10 11:22:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-20 22:54:11 +00:00
|
|
|
// destructor
|
2014-03-03 12:41:48 +00:00
|
|
|
virtual ~PlotObject(void) = default;
|
2014-02-10 11:22:27 +00:00
|
|
|
// access
|
2014-03-03 12:41:48 +00:00
|
|
|
std::string popTmpFile(void);
|
|
|
|
const std::string & getCommand(void) const;
|
|
|
|
// test
|
|
|
|
bool gotTmpFile(void) const;
|
2014-02-10 11:22:27 +00:00
|
|
|
protected:
|
2014-03-03 12:41:48 +00:00
|
|
|
// access
|
|
|
|
void pushTmpFile(const std::string &fileName);
|
|
|
|
void setCommand(const std::string &command);
|
|
|
|
private:
|
|
|
|
// plot command
|
|
|
|
std::string command_;
|
|
|
|
// stack of created temporary files
|
|
|
|
std::stack<std::string> tmpFileName_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlotCommand: public PlotObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors
|
|
|
|
explicit PlotCommand(const std::string &command);
|
|
|
|
// destructor
|
|
|
|
virtual ~PlotCommand(void) = default;
|
|
|
|
private:
|
2014-02-10 11:22:27 +00:00
|
|
|
std::string command_;
|
|
|
|
};
|
|
|
|
|
2014-03-03 12:41:48 +00:00
|
|
|
class PlotData: public PlotObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors
|
|
|
|
explicit PlotData(const XYStatData &data, const int i = 0, const int j = 0);
|
|
|
|
// destructor
|
|
|
|
virtual ~PlotData(void) = default;
|
|
|
|
private:
|
|
|
|
const XYStatData &data_;
|
|
|
|
const int i_, j_;
|
|
|
|
};
|
|
|
|
|
2014-02-10 11:22:27 +00:00
|
|
|
/******************************************************************************
|
2014-03-03 12:41:48 +00:00
|
|
|
* Plot modifiers *
|
2014-02-10 11:22:27 +00:00
|
|
|
******************************************************************************/
|
2014-03-03 12:41:48 +00:00
|
|
|
enum class Axis {x = 0, y = 1};
|
|
|
|
|
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
double min, max;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PlotOptions
|
|
|
|
{
|
|
|
|
std::string terminal {""};
|
|
|
|
std::string output {""};
|
|
|
|
std::string title {""};
|
|
|
|
unsigned int scaleMode[2] {0,0};
|
|
|
|
Range scale[2] {{0.0,0.0},{0.0,0.0}};
|
|
|
|
std::string label[2] {"",""};
|
|
|
|
std::string lineColor {""};
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlotModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// destructor
|
|
|
|
virtual ~PlotModifier(void) = default;
|
|
|
|
// modifier
|
|
|
|
virtual void operator()(PlotOptions &option) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Color: public PlotModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
explicit Color(const std::string &color);
|
|
|
|
// destructor
|
|
|
|
virtual ~Color(void) = default;
|
|
|
|
// modifier
|
|
|
|
virtual void operator()(PlotOptions &option) const;
|
|
|
|
private:
|
|
|
|
const std::string color_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogScale: public PlotModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
explicit LogScale(const Axis axis);
|
|
|
|
// destructor
|
|
|
|
virtual ~LogScale(void) = default;
|
|
|
|
// modifier
|
|
|
|
virtual void operator()(PlotOptions &option) const;
|
|
|
|
private:
|
|
|
|
const Axis axis_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlotRange: public PlotModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
2014-03-03 14:21:37 +00:00
|
|
|
PlotRange(const Axis axis, const double min, const double max);
|
2014-03-03 12:41:48 +00:00
|
|
|
// destructor
|
|
|
|
virtual ~PlotRange(void) = default;
|
|
|
|
// modifier
|
|
|
|
virtual void operator()(PlotOptions &option) const;
|
|
|
|
private:
|
|
|
|
const Axis axis_;
|
|
|
|
const double min_, max_;
|
|
|
|
};
|
2014-02-10 11:22:27 +00:00
|
|
|
|
2014-03-03 12:41:48 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Plot class *
|
|
|
|
******************************************************************************/
|
2014-02-10 11:22:27 +00:00
|
|
|
class Plot
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Scale
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
reset = 0,
|
|
|
|
manual = 1 << 0,
|
|
|
|
log = 1 << 1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
// constructor/destructor
|
2014-03-03 14:21:37 +00:00
|
|
|
Plot(void) = default;
|
2014-02-10 11:22:27 +00:00
|
|
|
virtual ~Plot(void);
|
2014-03-03 12:41:48 +00:00
|
|
|
// plot operations
|
|
|
|
Plot & operator<<(PlotObject &&command);
|
|
|
|
Plot & operator<<(PlotModifier &&modifier);
|
2014-02-10 11:22:27 +00:00
|
|
|
// plot parsing and output
|
|
|
|
void display(void);
|
|
|
|
friend std::ostream & operator<<(std::ostream &out, const Plot &plot);
|
|
|
|
private:
|
|
|
|
// find gnuplot
|
|
|
|
void getProgramPath(void);
|
|
|
|
private:
|
|
|
|
// gnuplot execution parameters
|
2014-03-03 12:41:48 +00:00
|
|
|
std::string gnuplotBin_ {GNUPLOT_BIN};
|
|
|
|
std::string gnuplotArgs_ {GNUPLOT_ARGS};
|
|
|
|
std::string gnuplotPath_ {""};
|
2014-02-10 11:22:27 +00:00
|
|
|
// string buffer for commands
|
|
|
|
std::ostringstream commandBuffer_;
|
|
|
|
// stack of created temporary files
|
|
|
|
std::stack<std::string> tmpFileName_;
|
|
|
|
// plot content
|
2014-03-03 12:41:48 +00:00
|
|
|
PlotOptions options_;
|
2014-02-10 11:22:27 +00:00
|
|
|
std::vector<std::string> headCommand_;
|
|
|
|
std::vector<std::string> plotCommand_;
|
|
|
|
};
|
|
|
|
|
2014-02-13 19:23:39 +00:00
|
|
|
std::ostream & operator<<(std::ostream &out, const Plot &plot);
|
|
|
|
|
2014-02-10 11:22:27 +00:00
|
|
|
END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Latan_Plot_hpp_
|