+void View::calculate_tick_spacing()
+{
+ const double SpacingIncrement = 32.0f;
+ const double MinValueSpacing = 32.0f;
+
+ double min_width = SpacingIncrement, typical_width;
+
+ QFontMetrics m(QApplication::font());
+
+ do {
+ const double min_period = scale_ * min_width;
+
+ const int order = (int)floorf(log10f(min_period));
+ const double order_decimal = pow(10.0, order);
+
+ unsigned int unit = 0;
+
+ do {
+ tick_period_ = order_decimal * ScaleUnits[unit++];
+ } while (tick_period_ < min_period &&
+ unit < countof(ScaleUnits));
+
+ tick_prefix_ = (order - pv::util::FirstSIPrefixPower) / 3;
+
+ typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
+ Qt::AlignLeft | Qt::AlignTop,
+ format_time(offset_, tick_prefix_)).width() +
+ MinValueSpacing;
+
+ min_width += SpacingIncrement;
+
+ } while(typical_width > tick_period_ / scale_);
+}
+