1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-04-11 03:20:46 +01:00

Plot option to set palette and category10 palette by default

This commit is contained in:
Antonin Portelli 2019-03-09 22:46:11 +00:00
parent 1a5d263512
commit 2ac6255031
2 changed files with 55 additions and 8 deletions

View File

@ -392,6 +392,31 @@ void Title::operator()(PlotOptions &option) const
option.title = title_; option.title = title_;
} }
// Palette constructor /////////////////////////////////////////////////////////
Palette::Palette(const std::vector<std::string> &palette)
: palette_(palette)
{}
// Palette modifier ////////////////////////////////////////////////////////////
void Palette::operator()(PlotOptions &option) const
{
option.palette = palette_;
}
// category10 palette //////////////////////////////////////////////////////////
const std::vector<std::string> Palette::category10 =
{
"rgb '#1f77b4'",
"rgb '#ff7f0e'",
"rgb '#2ca02c'",
"rgb '#d62728'",
"rgb '#9467bd'",
"rgb '#8c564b'",
"rgb '#e377c2'",
"rgb '#7f7f7f'",
"rgb '#bcbd22'"
};
/****************************************************************************** /******************************************************************************
* Plot implementation * * Plot implementation *
******************************************************************************/ ******************************************************************************/
@ -415,6 +440,7 @@ void Plot::initOptions(void)
options_.label[0] = ""; options_.label[0] = "";
options_.label[1] = ""; options_.label[1] = "";
options_.lineColor = ""; options_.lineColor = "";
options_.palette = Palette::category10;
} }
// plot reset ////////////////////////////////////////////////////////////////// // plot reset //////////////////////////////////////////////////////////////////
@ -695,6 +721,11 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot)
{ {
out << "set ylabel '" << plot.options_.label[y] << "'" << endl; out << "set ylabel '" << plot.options_.label[y] << "'" << endl;
} }
for (unsigned int i = 0; i < plot.options_.palette.size(); ++i)
{
out << "set linetype " << i + 1 << " lc "
<< plot.options_.palette[i] << endl;
}
for (unsigned int i = 0; i < plot.headCommand_.size(); ++i) for (unsigned int i = 0; i < plot.headCommand_.size(); ++i)
{ {
out << plot.headCommand_[i] << endl; out << plot.headCommand_[i] << endl;

View File

@ -181,14 +181,15 @@ struct Range
struct PlotOptions struct PlotOptions
{ {
std::string terminal; std::string terminal;
std::string output; std::string output;
std::string caption; std::string caption;
std::string title; std::string title;
unsigned int scaleMode[2]; unsigned int scaleMode[2];
Range scale[2]; Range scale[2];
std::string label[2]; std::string label[2];
std::string lineColor; std::string lineColor;
std::vector<std::string> palette;
}; };
class PlotModifier class PlotModifier
@ -295,6 +296,21 @@ private:
const std::string title_; const std::string title_;
}; };
class Palette: public PlotModifier
{
public:
static const std::vector<std::string> category10;
public:
// constructor
explicit Palette(const std::vector<std::string> &palette);
// destructor
virtual ~Palette(void) = default;
// modifier
virtual void operator()(PlotOptions &option) const;
private:
const std::vector<std::string> palette_;
};
/****************************************************************************** /******************************************************************************
* Plot class * * Plot class *
******************************************************************************/ ******************************************************************************/