Skip to content

Commit

Permalink
Fix "log-y" scale for decay chart.
Browse files Browse the repository at this point in the history
Before lines would disappear if log-y was selected (probably due to a `std::log(0)` call), and they wouldnt come back.  Now reasonable y-limits are chosen so this doenst happen.
  • Loading branch information
wcjohns committed Jan 15, 2024
1 parent 0978c42 commit dc3da73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
49 changes: 38 additions & 11 deletions src/DecayActivityDiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include <memory>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <exception>
Expand Down Expand Up @@ -2661,10 +2662,11 @@ double DecayActivityDiv::findTimeForActivityFrac(

void DecayActivityDiv::updateYScale()
{
if( m_logYScale->isChecked() )
m_decayChart->axis(Chart::YAxis).setScale( Chart::LogScale );
else
m_decayChart->axis(Chart::YAxis).setScale( Chart::LinearScale );
const Chart::AxisScale scale = m_logYScale->isChecked() ? Chart::LogScale : Chart::LinearScale;
m_decayChart->axis(Chart::YAxis).setScale( scale );

// If we dont do a full refresh, for some reason sometimes the lines wont show up
refreshDecayDisplay( true );
}//void updateYScale()


Expand Down Expand Up @@ -3411,7 +3413,7 @@ void DecayActivityDiv::updateYAxisRange()
// manually
// m_decayChart->axis(Chart::YAxis).setAutoLimits( Chart::MinimumValue | Chart::MaximumValue );

double miny = 0.0, maxy = 0.0;
double miny = std::numeric_limits<double>::max(), maxy = 0.0;

for( int row = 0; row < m_decayModel->rowCount(); ++row )
{
Expand All @@ -3426,16 +3428,41 @@ void DecayActivityDiv::updateYAxisRange()
{
miny = std::min( miny, yval );
maxy = std::max( maxy, yval );
}
}
}
}//if( we are showing this value )
}//for( loop over columns )
}//for( loop over rows )

if( maxy <= 0.0 )
maxy = 1.0;

//If it wont change the dynamic range of the chart much anyways, might as well
// anchor the y-axis to zero
m_decayChart->axis(Chart::YAxis).setRange( 0.0, 1.1*maxy );
if( miny > maxy )
miny = 0.0;

double min_disp_act = 0.0, max_disp_act = 1.1*maxy;
switch( m_decayChart->axis(Chart::YAxis).scale() )
{
case Wt::Chart::LogScale:
if( miny < 0.000001*maxy )
min_disp_act = 0.00001*maxy;
else
min_disp_act = 0.75*miny;
max_disp_act = 1.5*maxy;
break;

case Wt::Chart::LinearScale:
//If it wont change the dynamic range of the chart much anyways, might as well
// anchor the y-axis to zero
break;

case Wt::Chart::CategoryScale:
case Wt::Chart::DateScale:
case Wt::Chart::DateTimeScale:
assert( 0 );
break;
}//switch( m_decayChart->axis(Chart::YAxis).scale() )


m_decayChart->axis(Chart::YAxis).setRange( min_disp_act, max_disp_act );
}//void updateYAxisRange();


Expand Down
2 changes: 1 addition & 1 deletion src/PhysicalUnits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ std::string printValueWithUncertainty( double value, double uncert, size_t unsig
rounduncert /= uncertnorm;

char buffer[64] = {'\0'};
snprintf( buffer, sizeof(buffer), "%.*g &plusmn; %.*g", nsigfig, roundedval, nsigfig, rounduncert );
snprintf( buffer, sizeof(buffer), "%.*g \xC2\xB1 %.*g", nsigfig, roundedval, nsigfig, rounduncert );

// Incase "%.*g" isnt supprted somewhere, could instead do
//char formatflag[64] = {'\0'}, buffer[64] = {'\0'};
Expand Down

0 comments on commit dc3da73

Please sign in to comment.