! Rescales the key axis of the plottable so the whole plottable is visible. See \ref rescaleAxes for detailed behaviour. */
| 11003 | See \ref rescaleAxes for detailed behaviour. |
| 11004 | */ |
| 11005 | void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const |
| 11006 | { |
| 11007 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 11008 | if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } |
| 11009 | |
| 11010 | QCP::SignDomain signDomain = QCP::sdBoth; |
| 11011 | if (keyAxis->scaleType() == QCPAxis::stLogarithmic) |
| 11012 | signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); |
| 11013 | |
| 11014 | bool foundRange; |
| 11015 | QCPRange newRange = getKeyRange(foundRange, signDomain); |
| 11016 | if (foundRange) |
| 11017 | { |
| 11018 | if (onlyEnlarge) |
| 11019 | newRange.expand(keyAxis->range()); |
| 11020 | 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 |
| 11021 | { |
| 11022 | 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 |
| 11023 | if (keyAxis->scaleType() == QCPAxis::stLinear) |
| 11024 | { |
| 11025 | newRange.lower = center-keyAxis->range().size()/2.0; |
| 11026 | newRange.upper = center+keyAxis->range().size()/2.0; |
| 11027 | } else // scaleType() == stLogarithmic |
| 11028 | { |
| 11029 | newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11030 | newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11031 | } |
| 11032 | } |
| 11033 | keyAxis->setRange(newRange); |
| 11034 | } |
| 11035 | } |
| 11036 | |
| 11037 | /*! |
| 11038 | Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is |