Skip to content

Commit

Permalink
log scale basis in plots
Browse files Browse the repository at this point in the history
  • Loading branch information
aportelli committed Jan 12, 2024
1 parent 13fddf4 commit 6739019
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/Core/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,16 @@ void Dash::operator()(PlotOptions &option) const
}

// LogScale constructor ////////////////////////////////////////////////////////
LogScale::LogScale(const Axis axis)
LogScale::LogScale(const Axis axis, const double basis)
: axis_(axis)
, basis_(basis)
{}

// Logscale modifier ///////////////////////////////////////////////////////////
void LogScale::operator()(PlotOptions &option) const
{
option.scaleMode[static_cast<int>(axis_)] |= Plot::Scale::log;
option.scaleMode[static_cast<int>(axis_)] |= Plot::Scale::log;
option.logScaleBasis[static_cast<int>(axis_)] = basis_;
}

// PlotRange constructors //////////////////////////////////////////////////////
Expand Down Expand Up @@ -915,11 +917,11 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot)
out << "unset log" << endl;
if (plot.options_.scaleMode[x] & Plot::Scale::log)
{
out << "set log x" << endl;
out << "set log x " << plot.options_.logScaleBasis[x] << endl;;
}
if (plot.options_.scaleMode[y] & Plot::Scale::log)
{
out << "set log y" << endl;
out << "set log y " << plot.options_.logScaleBasis[y] << endl;
}
if (!plot.options_.label[x].empty())
{
Expand Down
4 changes: 3 additions & 1 deletion lib/Core/Plot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ struct PlotOptions
std::string caption;
std::string title;
unsigned int scaleMode[2];
double logScaleBasis[2];
Range scale[2];
std::string label[2];
std::string lineColor;
Expand Down Expand Up @@ -314,13 +315,14 @@ class LogScale: public PlotModifier
{
public:
// constructor
explicit LogScale(const Axis axis);
explicit LogScale(const Axis axis, const double basis = 10);
// destructor
virtual ~LogScale(void) = default;
// modifier
virtual void operator()(PlotOptions &option) const;
private:
const Axis axis_;
const double basis_;
};

class PlotRange: public PlotModifier
Expand Down

0 comments on commit 6739019

Please sign in to comment.