! Rescales the key axis of the plottable so the whole plottable is visible. See \ref rescaleAxes for detailed behaviour. */
| 11719 | See \ref rescaleAxes for detailed behaviour. |
| 11720 | */ |
| 11721 | void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const |
| 11722 | { |
| 11723 | QCPAxis *keyAxis = mKeyAxis.data(); |
| 11724 | if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } |
| 11725 | |
| 11726 | QCP::SignDomain signDomain = QCP::sdBoth; |
| 11727 | if (keyAxis->scaleType() == QCPAxis::stLogarithmic) |
| 11728 | signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); |
| 11729 | |
| 11730 | bool foundRange; |
| 11731 | QCPRange newRange = getKeyRange(foundRange, signDomain); |
| 11732 | if (foundRange) |
| 11733 | { |
| 11734 | if (onlyEnlarge) |
| 11735 | newRange.expand(keyAxis->range()); |
| 11736 | 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 |
| 11737 | { |
| 11738 | 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 |
| 11739 | if (keyAxis->scaleType() == QCPAxis::stLinear) |
| 11740 | { |
| 11741 | newRange.lower = center-keyAxis->range().size()/2.0; |
| 11742 | newRange.upper = center+keyAxis->range().size()/2.0; |
| 11743 | } else // scaleType() == stLogarithmic |
| 11744 | { |
| 11745 | newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11746 | newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); |
| 11747 | } |
| 11748 | } |
| 11749 | keyAxis->setRange(newRange); |
| 11750 | } |
| 11751 | } |
| 11752 | |
| 11753 | /*! |
| 11754 | Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is |