double QwtPlotRescaler::pixelDist(int axis, const QSize &size) const { const QwtDoubleInterval intv = intervalHint(axis); double dist = 0.0; if ( !intv.isNull() ) { if ( axis == referenceAxis() ) dist = intv.width(); else { const double r = aspectRatio(axis); if ( r > 0.0 ) dist = intv.width() * r; } } if ( dist > 0.0 ) { if ( orientation(axis) == Qt::Horizontal ) dist /= size.width(); else dist /= size.height(); } return dist; }
/** * Normalize the value to the range[0,1] * @param interval :: The data range * @param value :: The data value * @returns The fraction along the given interval using the current scale type */ double MantidColorMap::normalize(const QwtDoubleInterval &interval, double value) const { // nan numbers have the property that nan != nan, treat nan as being invalid if (interval.isNull() || m_num_colors == 0 || boost::math::isnan(value)) return m_nan; const double width = interval.width(); if (width <= 0.0 || value <= interval.minValue()) return 0.0; if (value >= interval.maxValue()) return 1.0; double ratio(0.0); if (m_scale_type == GraphOptions::Linear) { ratio = (value - interval.minValue()) / width; } else if (m_scale_type == GraphOptions::Power) { ratio = (pow(value, m_nth_power) - pow(interval.minValue(), m_nth_power)) / (pow(interval.maxValue(), m_nth_power) - pow(interval.minValue(), m_nth_power)); } else { // Assume log10 type // Have to deal with the possibility that a user has entered 0 as a minimum double minValue = interval.minValue(); if (minValue < LOG_ZERO_CUTOFF) { minValue = 1.0; } ratio = std::log10(value / minValue) / std::log10(interval.maxValue() / minValue); } return ratio; }
//! Adjust the plot axes scales void QwtPlotRescaler::rescale() const { #if 0 const int axis = referenceAxis(); if ( axis < 0 || axis >= QwtPlot::axisCnt ) return; const QwtDoubleInterval hint = intervalHint(axis); if ( !hint.isNull() ) { QwtPlot *plt = (QwtPlot *)plot(); const bool doReplot = plt->autoReplot(); plt->setAutoReplot(false); plt->setAxisScale(axis, hint.minValue(), hint.maxValue()); plt->setAutoReplot(doReplot); plt->updateAxes(); } #endif const QSize size = canvas()->contentsRect().size(); rescale(size, size); }