mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
profile: use sensible tick-intervals
The integers were simply rounded to integers, which might give ugly intervals (e.g. multiples of 3). Use the code of the statistics tab, with one modification: take care not to use intervals below the given precision. The statistics work differently: there, the precision is adjusted according to the interval size, not the other way around. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
99c4741508
commit
3e11c13100
1 changed files with 25 additions and 1 deletions
|
@ -131,6 +131,30 @@ double DiveCartesianAxis::height() const
|
|||
return labelHeight + labelSpaceVertical * dpr;
|
||||
}
|
||||
|
||||
static double sensibleInterval(double inc, int decimals)
|
||||
{
|
||||
// Use full decimal increments
|
||||
double digits = floor(log10(inc));
|
||||
int digits_int = lrint(digits);
|
||||
|
||||
// Don't do increments smaller than the displayed decimals.
|
||||
if (digits_int < -decimals) {
|
||||
digits_int = -decimals;
|
||||
digits = static_cast<double>(digits_int);
|
||||
}
|
||||
|
||||
double digits_factor = pow(10.0, digits);
|
||||
int inc_int = std::max((int)ceil(inc / digits_factor), 1);
|
||||
// Do "nice" increments of the leading digit: 1, 2, 4, 5.
|
||||
if (inc_int > 5)
|
||||
inc_int = 10;
|
||||
if (inc_int == 3)
|
||||
inc_int = 4;
|
||||
inc = inc_int * digits_factor;
|
||||
|
||||
return inc;
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::updateTicks(int animSpeed)
|
||||
{
|
||||
if (!changed && !printMode)
|
||||
|
@ -152,7 +176,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed)
|
|||
|
||||
// Round the interval to a sensible size in display units
|
||||
double intervalDisplay = interval * transform.a;
|
||||
intervalDisplay = ceil(intervalDisplay); // Currently, round to full integers, might want to improve.
|
||||
intervalDisplay = sensibleInterval(intervalDisplay, fractionalDigits);
|
||||
|
||||
// Choose full multiples of the interval as minumum and maximum values
|
||||
double minDisplay = transform.to(dataMin);
|
||||
|
|
Loading…
Reference in a new issue