Skip to content
Snippets Groups Projects
Commit da22c5c0 authored by Harry Jeffery's avatar Harry Jeffery
Browse files

Refs #11704 Handle min/max betrer in QwtWorkspaceBinData

parent 612027b6
No related branches found
No related tags found
No related merge requests found
...@@ -65,7 +65,6 @@ protected: ...@@ -65,7 +65,6 @@ protected:
QwtWorkspaceBinData& operator=(const QwtWorkspaceBinData&); // required by QwtData base class QwtWorkspaceBinData& operator=(const QwtWorkspaceBinData&); // required by QwtData base class
private: private:
/// Initialize the object /// Initialize the object
void init(const Mantid::API::MatrixWorkspace & workspace); void init(const Mantid::API::MatrixWorkspace & workspace);
...@@ -85,7 +84,14 @@ private: ...@@ -85,7 +84,14 @@ private:
/// Indicates that the data is plotted on a log y scale /// Indicates that the data is plotted on a log y scale
bool m_logScale; bool m_logScale;
/// lowest y value
double m_minY;
/// lowest positive y value /// lowest positive y value
mutable double m_minPositive; double m_minPositive;
/// highest y value
double m_maxY;
}; };
#endif #endif
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
/// Constructor /// Constructor
QwtWorkspaceBinData::QwtWorkspaceBinData(const Mantid::API::MatrixWorkspace &workspace, int binIndex, const bool logScale) QwtWorkspaceBinData::QwtWorkspaceBinData(const Mantid::API::MatrixWorkspace &workspace, int binIndex, const bool logScale)
: m_binIndex(binIndex), m_X(), m_Y(), m_E(), m_xTitle(), m_yTitle(), : m_binIndex(binIndex), m_X(), m_Y(), m_E(), m_xTitle(), m_yTitle(),
m_logScale(logScale), m_logScale(logScale)
m_minPositive(0)
{ {
init(workspace); init(workspace);
} }
...@@ -53,12 +52,11 @@ Return the y value of data point i ...@@ -53,12 +52,11 @@ Return the y value of data point i
*/ */
double QwtWorkspaceBinData::y(size_t i) const double QwtWorkspaceBinData::y(size_t i) const
{ {
double tmp = m_Y[i]; Mantid::signal_t val = m_Y[i];
if (m_logScale && tmp <= 0.) if (m_logScale && val <= 0.)
{ return m_minPositive;
tmp = m_minPositive; else
} return val;
return tmp;
} }
double QwtWorkspaceBinData::ex(size_t i) const double QwtWorkspaceBinData::ex(size_t i) const
...@@ -90,20 +88,10 @@ size_t QwtWorkspaceBinData::esize() const ...@@ -90,20 +88,10 @@ size_t QwtWorkspaceBinData::esize() const
*/ */
double QwtWorkspaceBinData::getYMin() const double QwtWorkspaceBinData::getYMin() const
{ {
double temp = m_Y[0]; if (m_logScale)
for(size_t i = 1; i < m_Y.size(); ++i) return m_minPositive;
{ else
if ((boost::math::isnan)(temp) || (boost::math::isinf)(temp)) return m_minY;
temp = m_Y[i];
else if (m_Y[i] < temp && !(boost::math::isnan)(m_Y[i]) &&
!(boost::math::isinf)(m_Y[i]))
temp = m_Y[i];
}
if (m_logScale && temp <= 0.)
{
temp = m_minPositive;
}
return temp;
} }
/** /**
...@@ -112,20 +100,10 @@ double QwtWorkspaceBinData::getYMin() const ...@@ -112,20 +100,10 @@ double QwtWorkspaceBinData::getYMin() const
*/ */
double QwtWorkspaceBinData::getYMax() const double QwtWorkspaceBinData::getYMax() const
{ {
double temp = m_Y[0]; if (m_logScale && m_maxY <= 0)
for(size_t i = 1; i < m_Y.size(); ++i) return m_minPositive;
{ else
if ((boost::math::isnan)(temp) || (boost::math::isinf)(temp)) return m_maxY;
temp = m_Y[i];
else if (m_Y[i] > temp && !(boost::math::isnan)(m_Y[i]) &&
!(boost::math::isinf)(m_Y[i]))
temp = m_Y[i];
}
if (m_logScale && temp <= 0.)
{
temp = m_minPositive;
}
return temp;
} }
/** /**
...@@ -215,4 +193,37 @@ void QwtWorkspaceBinData::init(const Mantid::API::MatrixWorkspace &workspace) ...@@ -215,4 +193,37 @@ void QwtWorkspaceBinData::init(const Mantid::API::MatrixWorkspace &workspace)
// meta data // meta data
m_xTitle = MantidQt::API::PlotAxis(workspace, 1).title(); m_xTitle = MantidQt::API::PlotAxis(workspace, 1).title();
m_yTitle = MantidQt::API::PlotAxis(false, workspace).title(); m_yTitle = MantidQt::API::PlotAxis(false, workspace).title();
// Calculate the min and max values
double curMin = m_Y[0];
double curMinPos = m_Y[0];
double curMax = m_Y[0];
for(size_t i = 1; i < m_Y.size(); ++i)
{
// skip NaNs
if ((boost::math::isnan)(m_Y[i]) || (boost::math::isinf)(m_Y[i]))
continue;
// Try and get rid any starting NaNs as soon as possible
if ((boost::math::isnan)(curMin) || (boost::math::isinf)(curMin))
curMin = m_Y[i];
if ((boost::math::isnan)(curMinPos) || (boost::math::isinf)(curMinPos))
curMinPos = m_Y[i];
if ((boost::math::isnan)(curMax) || (boost::math::isinf)(curMax))
curMax = m_Y[i];
// Update our values as appropriate
if (m_Y[i] < curMin)
curMin = m_Y[i];
if (m_Y[i] < curMinPos && m_Y[i] > 0)
curMinPos = m_Y[i];
if (m_Y[i] > curMax)
curMax = m_Y[i];
}
// Save the results
m_minY = curMin;
m_minPositive = curMinPos;
m_maxY = curMax;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment