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

Method rescaleValueAxis

qcustomplot/qcustomplot.cpp:11047–11078  ·  view source on GitHub ↗

! Rescales the value axis of the plottable so the whole plottable is visible. If \a inKeyRange is set to true, only the data points which are in the currently visible key axis range are considered. Returns true if the axis was actually scaled. This might not be the case if this plottable has an invalid range, e.g. because it has no data points. See \ref rescaleAxes for detailed behav

Source from the content-addressed store, hash-verified

11045 See \ref rescaleAxes for detailed behaviour.
11046*/
11047void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const
11048{
11049 QCPAxis *keyAxis = mKeyAxis.data();
11050 QCPAxis *valueAxis = mValueAxis.data();
11051 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
11052
11053 QCP::SignDomain signDomain = QCP::sdBoth;
11054 if (valueAxis->scaleType() == QCPAxis::stLogarithmic)
11055 signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive);
11056
11057 bool foundRange;
11058 QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange());
11059 if (foundRange)
11060 {
11061 if (onlyEnlarge)
11062 newRange.expand(valueAxis->range());
11063 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
11064 {
11065 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
11066 if (valueAxis->scaleType() == QCPAxis::stLinear)
11067 {
11068 newRange.lower = center-valueAxis->range().size()/2.0;
11069 newRange.upper = center+valueAxis->range().size()/2.0;
11070 } else // scaleType() == stLogarithmic
11071 {
11072 newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower);
11073 newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower);
11074 }
11075 }
11076 valueAxis->setRange(newRange);
11077 }
11078}
11079
11080/*! \overload
11081

Callers

nothing calls this directly

Calls 5

dataMethod · 0.80
rangeMethod · 0.80
expandMethod · 0.80
setRangeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected