Skip to content
Snippets Groups Projects
Commit c4333e49 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

improved ticks and tacks for small log ranges

parent 8efd9814
No related branches found
No related tags found
No related merge requests found
......@@ -309,20 +309,31 @@ double CAxis::pc(double v) const { return 10 * value2plotcoord(v); }
double CAxis::pcerr(double v, double dv) const { return 10 * value2ploterror(v, dv); }
//! Sets Tacks, *ntpt, *ticklim to a nice division of the plot range.
//! Sets Tacks, ntpt, nt4t, *ticklim to a nice division of the plot range.
void CAxis::calc_ticks(vector<double>& Tacks, int& ntpt, double* ticklim) const
void CAxis::calc_ticks(vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const
{
if (logflag)
calc_logticks(Tacks, ntpt, ticklim);
calc_logticks(Tacks, ntpt, nt4t, ticklim);
else
calc_linticks(Tacks, ntpt, ticklim);
calc_linticks(Tacks, ntpt, nt4t, ticklim);
}
//! Sets Tacks, *ntpt, *ticklim to a nice division of the plot range.
//! Sets Tacks, ntpt, nt4t, *ticklim to a nice division of the plot range.
void CAxis::calc_linticks(vector<double>& Tacks, int& ntpt, double* ticklim) const
void CAxis::calc_linticks(vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const
{
double dtack;
calc_lintacks(Tacks, ntpt, dtack);
ticklim[0] = Tacks.front() - dtack;
ticklim[1] = Tacks.back() + dtack;
nt4t = Tacks.size() + 2;
}
//! Sets Tacks, *ntpt, and dtack
void CAxis::calc_lintacks(vector<double>& Tacks, int& ntpt, double& dtack) const
{
if (inf >= sup)
throw "BUG detected by calc_linticks: inf=" + S(inf) + " >= sup=" + S(sup);
......@@ -330,7 +341,6 @@ void CAxis::calc_linticks(vector<double>& Tacks, int& ntpt, double* ticklim) con
int ir = (int)((r < 0) ? r - 1 : r);
double rd = r - ir; // fractional part of r
double rdr = pow(10., rd);
double dtack;
if (rdr > 9.99999) {
dtack = 2.5 * pow(10., ir); // spacing between tacks
ntpt = 5; // ticks per tack
......@@ -356,14 +366,12 @@ void CAxis::calc_linticks(vector<double>& Tacks, int& ntpt, double* ticklim) con
for (double d = dtack * (floor(inf/dtack)-1); d < dtack * (ceil(sup/dtack)+1); d += dtack)
if (vsub <= d && d <= vsup)
Tacks.push_back(d);
ticklim[0] = Tacks.front() - dtack;
ticklim[1] = Tacks.back() + dtack;
}
//! Sets Tacks, *ntpt, *ticklim to a nice division of the plot range.
//! Sets Tacks, ntpt, nt4t, *ticklim to a nice division of the plot range.
void CAxis::calc_logticks(vector<double>& Tacks, int& ntpt, double* ticklim) const
void CAxis::calc_logticks(vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const
{
if (inf >= sup)
throw "BUG detected by calc_logticks: inf=" + S(inf) + " >= sup=" + S(sup);
......@@ -404,6 +412,7 @@ void CAxis::calc_logticks(vector<double>& Tacks, int& ntpt, double* ticklim) con
if (d1 <= r0 && r0 <= d2)
Tacks.push_back(r0);
}
nt4t = Tacks.size() + 2;
// set tick limits (may exceed actual tick range)
int ntack = Tacks.size();
......@@ -426,4 +435,11 @@ void CAxis::calc_logticks(vector<double>& Tacks, int& ntpt, double* ticklim) con
} else {
ntpt = -incr; // this one has special semantics: it means 'incr' ticks per tack
}
// for narrow ranges, overwrite tacks
if (ntack<2) {
double dtack;
int ntpt_dummy;
calc_lintacks(Tacks, ntpt_dummy, dtack);
}
}
......@@ -43,7 +43,9 @@ public:
void set_xgrid(std::vector<double>& x, int n) const;
double pc(double v) const;
double pcerr(double v, double dv) const;
void calc_ticks(std::vector<double>& Tacks, int& ntpt, double* ticklim) const;
void calc_linticks(std::vector<double>& Tacks, int& ntpt, double* ticklim) const;
void calc_logticks(std::vector<double>& Tacks, int& ntpt, double* ticklim) const;
void calc_ticks(std::vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const;
private:
void calc_linticks(std::vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const;
void calc_lintacks(std::vector<double>& Tacks, int& ntpt, double& dtack) const;
void calc_logticks(std::vector<double>& Tacks, int& ntpt, int& nt4t, double* ticklim) const;
};
......@@ -158,9 +158,10 @@ namespace {
string ps_ticktack(const CAxis* A)
{
vector<double> Tacks;
int ntpt;
int ticks_per_tack;
int ntacks4ticks;
double ticklim[2];
A->calc_ticks(Tacks, ntpt, ticklim);
A->calc_ticks(Tacks, ticks_per_tack, ntacks4ticks, ticklim);
string ret;
int ntack = Tacks.size();
......@@ -187,8 +188,8 @@ namespace {
% A->name
% (float)ticklim[1]
% A->name
% (ntack + 2)
% ntpt
% ntacks4ticks
% ticks_per_tack
% (A->logflag ? "Log" : "Lin"));
return ret;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment