From f332dba095e4ab70bd4fbbf4f01fad8204bc2676 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 2 Aug 2023 13:43:08 +0100 Subject: [PATCH] Try harder to prevent duplicate axis labels. --- eeschema/sim/sim_plot_tab.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/eeschema/sim/sim_plot_tab.cpp b/eeschema/sim/sim_plot_tab.cpp index 399dd07008..e37eaed937 100644 --- a/eeschema/sim/sim_plot_tab.cpp +++ b/eeschema/sim/sim_plot_tab.cpp @@ -100,7 +100,6 @@ static void getSISuffix( double x, const wxString& unit, int& power, wxString& s static int countDecimalDigits( double x, int maxDigits ) { - // avoid trying to count the decimals of NaN if( std::isnan( x ) ) return 0; @@ -151,23 +150,29 @@ private: int power = 0; int digits = 0; int constexpr MAX_DIGITS = 3; + bool duplicateLabels = false; getSISuffix( maxVis, m_unit, power, suffix ); double sf = pow( 10.0, power ); for( mpScaleBase::TickLabel& l : parent::TickLabels() ) - { - int k = countDecimalDigits( l.pos / sf, MAX_DIGITS ); + digits = std::max( digits, countDecimalDigits( l.pos / sf, MAX_DIGITS ) ); - digits = std::max( digits, k ); - } - - for( mpScaleBase::TickLabel& l : parent::TickLabels() ) + do { - l.label = formatFloat( l.pos / sf, digits ) + suffix; - l.visible = true; + for( size_t ii = 0; ii < parent::TickLabels().size(); ++ii ) + { + mpScaleBase::TickLabel& l = parent::TickLabels()[ii]; + + l.label = formatFloat( l.pos / sf, digits ) + suffix; + l.visible = true; + + if( ii > 0 && l.label == parent::TickLabels()[ii-1].label ) + duplicateLabels = true; + } } + while( duplicateLabels && ++digits <= 6 ); } private: