! * Calculates and saves data range. */
| 2939 | * Calculates and saves data range. |
| 2940 | */ |
| 2941 | void CartesianPlot::calculateDataRange(const Dimension dim, const int index, bool completeRange) { |
| 2942 | DEBUG(Q_FUNC_INFO << ", direction = " << CartesianCoordinateSystem::dimensionToString(dim).toStdString() << ", index = " << index |
| 2943 | << ", complete range = " << completeRange) |
| 2944 | Q_D(CartesianPlot); |
| 2945 | |
| 2946 | d->dataRange(dim, index).setRange(INFINITY, -INFINITY); |
| 2947 | auto range{d->range(dim, index)}; // get reference to range from private |
| 2948 | |
| 2949 | // loop over all curves/plots and determine the maximum and minimum values |
| 2950 | for (const auto* plot : this->children<const Plot>()) { |
| 2951 | if (!plot->isVisible() || !plot->hasData()) |
| 2952 | continue; |
| 2953 | |
| 2954 | if (coordinateSystem(plot->coordinateSystemIndex())->index(dim) != index) |
| 2955 | continue; |
| 2956 | |
| 2957 | if (dynamic_cast<const XYCurve*>(plot)) { |
| 2958 | auto* curve = static_cast<const XYCurve*>(plot); |
| 2959 | DEBUG("CURVE \"" << STDSTRING(curve->name()) << "\"") |
| 2960 | auto* column = curve->column(dim); |
| 2961 | if (!column) { |
| 2962 | DEBUG(" NO column!") |
| 2963 | continue; |
| 2964 | } |
| 2965 | |
| 2966 | // range of indices |
| 2967 | Range<int> indexRange{0, 0}; |
| 2968 | if (!completeRange && d->rangeType == RangeType::Free) { |
| 2969 | Dimension dim_other = Dimension::Y; |
| 2970 | switch (dim) { |
| 2971 | case Dimension::X: |
| 2972 | break; |
| 2973 | case Dimension::Y: |
| 2974 | dim_other = Dimension::X; |
| 2975 | break; |
| 2976 | } |
| 2977 | |
| 2978 | if (curve->column(dim_other)) { // only data within y range |
| 2979 | const int index = coordinateSystem(curve->coordinateSystemIndex())->index(dim_other); |
| 2980 | DEBUG(Q_FUNC_INFO << ", free incomplete range with y column. y range = " << d->range(dim_other, index).toStdString()) |
| 2981 | curve->column(dim_other)->indicesMinMax(d->range(dim_other, index).start(), |
| 2982 | d->range(dim_other, index).end(), |
| 2983 | indexRange.start(), |
| 2984 | indexRange.end()); |
| 2985 | } |
| 2986 | } else { // all data |
| 2987 | DEBUG(Q_FUNC_INFO << ", else. range type = " << (int)d->rangeType) |
| 2988 | switch (d->rangeType) { |
| 2989 | case RangeType::Free: |
| 2990 | indexRange.setRange(0, column->rowCount() - 1); |
| 2991 | break; |
| 2992 | case RangeType::Last: |
| 2993 | indexRange.setRange(column->rowCount() - d->rangeLastValues, column->rowCount() - 1); |
| 2994 | break; |
| 2995 | case RangeType::First: |
| 2996 | indexRange.setRange(0, d->rangeFirstValues - 1); |
| 2997 | break; |
| 2998 | } |
no test coverage detected