MCPcopy Create free account
hub / github.com/KDE/labplot / scaleAuto

Method scaleAuto

src/backend/worksheet/plots/cartesian/CartesianPlot.cpp:2828–2913  ·  view source on GitHub ↗

auto scale x axis 'index' when auto scale is enabled (index == -1: all x axes)

Source from the content-addressed store, hash-verified

2826
2827// auto scale x axis 'index' when auto scale is enabled (index == -1: all x axes)
2828bool CartesianPlot::scaleAuto(const Dimension dim, int index, bool fullRange, bool suppressRetransformScale) {
2829 DEBUG(Q_FUNC_INFO << ", dim = " << int(dim) << ", index = " << index << ", full range = " << fullRange)
2830 PERFTRACE(QLatin1String(Q_FUNC_INFO));
2831 Q_D(CartesianPlot);
2832 if (index == -1) { // all ranges
2833 bool updated = false;
2834 for (int i = 0; i < rangeCount(dim); i++) {
2835 if (autoScale(dim, i) && scaleAuto(dim, i, fullRange, true)) {
2836 if (!suppressRetransformScale)
2837 d->retransformScale(dim, i);
2838 updated = true; // at least one was updated
2839 }
2840 }
2841 return updated;
2842 }
2843
2844 auto& r{d->range(dim, index)};
2845 DEBUG(Q_FUNC_INFO << ", " << CartesianCoordinateSystem::dimensionToString(dim).toStdString() << " range dirty = " << rangeDirty(dim, index))
2846 if (rangeDirty(dim, index)) {
2847 calculateDataRange(dim, index, fullRange);
2848 setRangeDirty(dim, index, false);
2849
2850 if (fullRange) {
2851 // If not fullrange the y range will be used. So that means
2852 // the yrange would not change and therefore it must not be dirty
2853 for (const auto* c : m_coordinateSystems) {
2854 // All x ranges with this xIndex must be dirty
2855 const auto* cs = dynamic_cast<const CartesianCoordinateSystem*>(c);
2856 if (cs && cs->index(dim) == index) {
2857 switch (dim) {
2858 case Dimension::X:
2859 setRangeDirty(Dimension::Y, cs->index(Dimension::Y), true);
2860 break;
2861 case Dimension::Y:
2862 setRangeDirty(Dimension::X, cs->index(Dimension::X), true);
2863 break;
2864 }
2865 }
2866 }
2867 }
2868 }
2869 auto dataRange = d->dataRange(dim, index); // dataRange used for nice extend
2870 if (dataRange.finite() && d->niceExtend)
2871 dataRange.niceExtend(); // auto scale to nice range
2872
2873 // if no curve: do not reset to [0, 1]
2874
2875 DEBUG(Q_FUNC_INFO << ", range " << index << " = " << r.toStdString() << "., data range = " << d->dataRange(dim, index).toStdString())
2876 bool update = false;
2877 if (!qFuzzyCompare(dataRange.start(), r.start()) && std::isfinite(dataRange.start())) {
2878 r.start() = dataRange.start();
2879 update = true;
2880 }
2881
2882 if (!qFuzzyCompare(dataRange.end(), r.end()) && std::isfinite(dataRange.end())) {
2883 r.end() = dataRange.end();
2884 update = true;
2885 }

Callers 13

dataChangedMethod · 0.95
plotRangeChangedMethod · 0.80
autoScaleRangeMethod · 0.80
addCurvesToPlotsMethod · 0.80
redoMethod · 0.80
finalizeMethod · 0.80
retransformScaleMethod · 0.80
rangeChangedMethod · 0.80
niceExtendChangedMethod · 0.80

Calls 13

retransformScaleMethod · 0.80
rangeMethod · 0.80
toStdStringMethod · 0.80
finiteMethod · 0.80
niceExtendMethod · 0.80
isZeroMethod · 0.80
extendMethod · 0.80
indexMethod · 0.45
startMethod · 0.45
endMethod · 0.45
setRangeMethod · 0.45
sizeMethod · 0.45

Tested by 1

invalidcSystemMethod · 0.64