! Changes the axis range such that all plottables associated with this axis are fully visible in that dimension. \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */
| 8504 | \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes |
| 8505 | */ |
| 8506 | void QCPAxis::rescale(bool onlyVisiblePlottables) |
| 8507 | { |
| 8508 | QList<QCPAbstractPlottable*> p = plottables(); |
| 8509 | QCPRange newRange; |
| 8510 | bool haveRange = false; |
| 8511 | for (int i=0; i<p.size(); ++i) |
| 8512 | { |
| 8513 | if (!p.at(i)->realVisibility() && onlyVisiblePlottables) |
| 8514 | continue; |
| 8515 | QCPRange plottableRange; |
| 8516 | bool currentFoundRange; |
| 8517 | QCP::SignDomain signDomain = QCP::sdBoth; |
| 8518 | if (mScaleType == stLogarithmic) |
| 8519 | signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); |
| 8520 | if (p.at(i)->keyAxis() == this) |
| 8521 | plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); |
| 8522 | else |
| 8523 | plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); |
| 8524 | if (currentFoundRange) |
| 8525 | { |
| 8526 | if (!haveRange) |
| 8527 | newRange = plottableRange; |
| 8528 | else |
| 8529 | newRange.expand(plottableRange); |
| 8530 | haveRange = true; |
| 8531 | } |
| 8532 | } |
| 8533 | if (haveRange) |
| 8534 | { |
| 8535 | 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 |
| 8536 | { |
| 8537 | 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 |
| 8538 | if (mScaleType == stLinear) |
| 8539 | { |
| 8540 | newRange.lower = center-mRange.size()/2.0; |
| 8541 | newRange.upper = center+mRange.size()/2.0; |
| 8542 | } else // mScaleType == stLogarithmic |
| 8543 | { |
| 8544 | newRange.lower = center/qSqrt(mRange.upper/mRange.lower); |
| 8545 | newRange.upper = center*qSqrt(mRange.upper/mRange.lower); |
| 8546 | } |
| 8547 | } |
| 8548 | setRange(newRange); |
| 8549 | } |
| 8550 | } |
| 8551 | |
| 8552 | /*! |
| 8553 | Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. |
no test coverage detected