MCPcopy Create free account
hub / github.com/collin80/SavvyCAN / rescaleDataRange

Method rescaleDataRange

qcustomplot.cpp:19635–19692  ·  view source on GitHub ↗

! Changes the data range such that all color maps associated with this color scale are fully mapped to the gradient in the data dimension. \see setDataRange */

Source from the content-addressed store, hash-verified

19633 \see setDataRange
19634*/
19635void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps)
19636{
19637 QList<QCPColorMap*> maps = colorMaps();
19638 QCPRange newRange;
19639 bool haveRange = false;
19640 QCP::SignDomain sign = QCP::sdBoth;
19641 if (mDataScaleType == QCPAxis::stLogarithmic)
19642 sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive);
19643 for (int i=0; i<maps.size(); ++i)
19644 {
19645 if (!maps.at(i)->realVisibility() && onlyVisibleMaps)
19646 continue;
19647 QCPRange mapRange;
19648 if (maps.at(i)->colorScale() == this)
19649 {
19650 bool currentFoundRange = true;
19651 mapRange = maps.at(i)->data()->dataBounds();
19652 if (sign == QCP::sdPositive)
19653 {
19654 if (mapRange.lower <= 0 && mapRange.upper > 0)
19655 mapRange.lower = mapRange.upper*1e-3;
19656 else if (mapRange.lower <= 0 && mapRange.upper <= 0)
19657 currentFoundRange = false;
19658 } else if (sign == QCP::sdNegative)
19659 {
19660 if (mapRange.upper >= 0 && mapRange.lower < 0)
19661 mapRange.upper = mapRange.lower*1e-3;
19662 else if (mapRange.upper >= 0 && mapRange.lower >= 0)
19663 currentFoundRange = false;
19664 }
19665 if (currentFoundRange)
19666 {
19667 if (!haveRange)
19668 newRange = mapRange;
19669 else
19670 newRange.expand(mapRange);
19671 haveRange = true;
19672 }
19673 }
19674 }
19675 if (haveRange)
19676 {
19677 if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data
19678 {
19679 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
19680 if (mDataScaleType == QCPAxis::stLinear)
19681 {
19682 newRange.lower = center-mDataRange.size()/2.0;
19683 newRange.upper = center+mDataRange.size()/2.0;
19684 } else // mScaleType == stLogarithmic
19685 {
19686 newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower);
19687 newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower);
19688 }
19689 }
19690 setDataRange(newRange);
19691 }
19692}

Callers 1

generateGraphMethod · 0.80

Calls 6

realVisibilityMethod · 0.80
atMethod · 0.80
expandMethod · 0.80
recalculateDataBoundsMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected