X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fview.cpp;h=f146470d314f72443c9b90063f20e42da9575abd;hp=e6be30e0680b48670a885fb0630d25209b9953b7;hb=8a1bc0876c9d9e25719e416466a3bb983c705968;hpb=1e124d4b75b7b6b6a87b93a4e175d669909c2e04 diff --git a/pv/view/view.cpp b/pv/view/view.cpp index e6be30e0..f146470d 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -493,8 +493,8 @@ void View::set_zoom(double scale, int offset) void View::calculate_tick_spacing() { - const double SpacingIncrement = 32.0f; - const double MinValueSpacing = 32.0f; + const double SpacingIncrement = 10.0f; + const double MinValueSpacing = 25.0f; // Figure out the highest numeric value visible on a label const QSize areaSize = viewport_->size(); @@ -512,13 +512,19 @@ void View::calculate_tick_spacing() const int order = (int)floorf(log10f(min_period)); const double order_decimal = pow(10.0, order); + // Allow for a margin of error so that a scale unit of 1 can be used. + // Otherwise, for a SU of 1 the tick period will almost always be below + // the min_period by a small amount - and thus skipped in favor of 2. + // Note: margin assumes that SU[0] and SU[1] contain the smallest values + double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0; + double tp_with_margin; unsigned int unit = 0; do { - tick_period_ = order_decimal * ScaleUnits[unit++]; - } while (tick_period_ < min_period && - unit < countof(ScaleUnits)); + tp_with_margin = order_decimal * (ScaleUnits[unit++] + tp_margin); + } while (tp_with_margin < min_period && unit < countof(ScaleUnits)); + tick_period_ = order_decimal * ScaleUnits[unit - 1]; tick_prefix_ = (order - pv::util::FirstSIPrefixPower) / 3; // Precision is the number of fractional digits required, not