From: Soeren Apel Date: Sat, 15 Aug 2015 21:11:52 +0000 (+0200) Subject: View: Allow ScaleUnits[0] to actually be used X-Git-Tag: pulseview-0.3.0~142 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8a1bc0876c9d9e25719e416466a3bb983c705968;p=pulseview.git View: Allow ScaleUnits[0] to actually be used Without this patch, no major tick on the ruler will ever begin with a '1' but only with '2' or '5'. This behavior can also be observed with current sigrok git head, so it is independent of my util/view/ruler patch set. --- 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