Skip to content

Commit

Permalink
Clean up plot tic close to zero
Browse files Browse the repository at this point in the history
On 8/8/2024 on this commit:
8adaf0e
I took out logic that formatted tics
close to zero as zero and instead used
the actual tic value no matter how
close to zero.

This introduced another issue
when tic values were close to zero
but actually meant to be zero.

For example if Tics={-1e-17,1e-34,1e-17},
the plot should really have
Tics={-1e-17,0,1e-17}.

This commit fixes that issue by replacing
the tic closest to zero with zero if
appropriate.
  • Loading branch information
keithvetter committed Aug 21, 2024
1 parent e25d0f6 commit c10eda1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libkoviz/bookmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,31 @@ QList<double> PlotBookModel::_calcTicSet(double aIn, double bIn,
}
}

// Clean up X by replacing single tic that is nearest zero with zero
// For example, if X={-1e-17,1e-34,1e-17}, make X={-1e-17,0,1e-17}
// Only replace tic if:
// 1. a <= 0 <= b
// 2. |X| > 1
// 3. log10(tic) is less than another tic
if ( a <= 0 && b >= 0 && X.size() > 1 ) {
int idx_nearest_zero = 0;
double xmin = DBL_MAX;
for ( int i = 0; i < X.size(); ++i ) {
double x = X.at(i);
if ( qAbs(x) < xmin ) {
xmin = qAbs(x);
idx_nearest_zero = i;
}
}
if ( xmin != 0 ) {
int i = ( idx_nearest_zero == 0 ) ? 1 : 0;
double other_tic = X.at(i);
if ( log10(qAbs(xmin)) < log10(qAbs(other_tic))-1 ) {
X.replace(idx_nearest_zero,0.0);
}
}
}

// Shrink tic set until |X| <=7
// Tics are removed in favor of keeping tics "even" in order
// to keep them the same while panning
Expand Down

0 comments on commit c10eda1

Please sign in to comment.