MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / rescale

Method rescale

qcustomplot/qcustomplot.cpp:8517–8561  ·  view source on GitHub ↗

! Changes the axis range such that all plottables associated with this axis are fully visible in that dimension. \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */

Source from the content-addressed store, hash-verified

8515 \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes
8516*/
8517void QCPAxis::rescale(bool onlyVisiblePlottables)
8518{
8519 QList<QCPAbstractPlottable*> p = plottables();
8520 QCPRange newRange;
8521 bool haveRange = false;
8522 for (int i=0; i<p.size(); ++i)
8523 {
8524 if (!p.at(i)->realVisibility() && onlyVisiblePlottables)
8525 continue;
8526 QCPRange plottableRange;
8527 bool currentFoundRange;
8528 QCP::SignDomain signDomain = QCP::sdBoth;
8529 if (mScaleType == stLogarithmic)
8530 signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive);
8531 if (p.at(i)->keyAxis() == this)
8532 plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain);
8533 else
8534 plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain);
8535 if (currentFoundRange)
8536 {
8537 if (!haveRange)
8538 newRange = plottableRange;
8539 else
8540 newRange.expand(plottableRange);
8541 haveRange = true;
8542 }
8543 }
8544 if (haveRange)
8545 {
8546 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
8547 {
8548 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
8549 if (mScaleType == stLinear)
8550 {
8551 newRange.lower = center-mRange.size()/2.0;
8552 newRange.upper = center+mRange.size()/2.0;
8553 } else // mScaleType == stLogarithmic
8554 {
8555 newRange.lower = center/qSqrt(mRange.upper/mRange.lower);
8556 newRange.upper = center*qSqrt(mRange.upper/mRange.lower);
8557 }
8558 }
8559 setRange(newRange);
8560 }
8561}
8562
8563/*!
8564 Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates.

Callers 2

rescaleAxesMethod · 0.80

Calls 6

realVisibilityMethod · 0.80
atMethod · 0.80
getKeyRangeMethod · 0.80
getValueRangeMethod · 0.80
expandMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected