auto scale x axis 'index' when auto scale is enabled (index == -1: all x axes)
| 2826 | |
| 2827 | // auto scale x axis 'index' when auto scale is enabled (index == -1: all x axes) |
| 2828 | bool 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 | } |