! Rescales the key axis of the plottable so the whole plottable is visible. See \ref rescaleAxes for detailed behaviour. */
| 10992 | See \ref rescaleAxes for detailed behaviour. |
| 10993 | */ |
| 10994 | void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const |
| 10995 | { |
| 10996 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 10997 | if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } |
| 10998 | |
| 10999 | QCP::SignDomain signDomain = QCP::sdBoth; |
| 11000 | if (keyAxis->scaleType() == QCPAxis::stLogarithmic) |
| 11001 | signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); |
| 11002 | |
| 11003 | bool foundRange; |
| 11004 | QCPRange newRange = getKeyRange(foundRange, signDomain); |
| 11005 | if (foundRange) |
| 11006 | { |
| 11007 | if (onlyEnlarge) |
| 11008 | newRange.expand(keyAxis->range()); |
| 11009 | if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable |
| 11010 | { |
| 11011 | double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason |
| 11012 | if (keyAxis->scaleType() == QCPAxis::stLinear) |
| 11013 | { |
| 11014 | newRange.lower = center-keyAxis->range().size()/2.0; |
| 11015 | newRange.upper = center+keyAxis->range().size()/2.0; |
| 11016 | } else // scaleType() == stLogarithmic |
| 11017 | { |
| 11018 | newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11019 | newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11020 | } |
| 11021 | } |
| 11022 | keyAxis->setRange(newRange); |
| 11023 | } |
| 11024 | } |
| 11025 | |
| 11026 | /*! |
| 11027 | Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is |