MCPcopy Create free account
hub / github.com/LUX-Core/lux / rescaleValueAxis

Method rescaleValueAxis

src/qt/qcustomplot.cpp:11036–11067  ·  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

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected