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

Method shift

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

! * helper function called in other shift*() functions * and doing the actual change of the data ranges. * @param x if set to \true the x-range is modified, the y-range for \c false * @param leftOrDown the "shift left" for x or "shift dows" for y is performed if set to \c \true, * "shift right" or "shift up" for \c false */

Source from the content-addressed store, hash-verified

3173 * "shift right" or "shift up" for \c false
3174 */
3175void CartesianPlot::shift(int index, const Dimension dim, bool leftOrDown) {
3176 setUndoAware(false);
3177 enableAutoScale(dim, index, false);
3178 setUndoAware(true);
3179 Q_D(CartesianPlot);
3180
3181 Range<double> range;
3182 if (index == -1) {
3183 QVector<int> shiftedIndices;
3184 for (int i = 0; i < m_coordinateSystems.count(); i++) {
3185 int idx = coordinateSystem(i)->index(dim);
3186 if (shiftedIndices.contains(idx))
3187 continue;
3188 shift(idx, dim, leftOrDown);
3189 shiftedIndices.append(idx);
3190 }
3191 return;
3192 }
3193 range = d->range(dim, index);
3194
3195 double offset = 0.0, factor = 0.1;
3196
3197 if (!leftOrDown)
3198 factor *= -1.;
3199
3200 const double start{range.start()}, end{range.end()};
3201 switch (range.scale()) {
3202 case RangeT::Scale::Linear: {
3203 offset = range.size() * factor;
3204 range += offset;
3205 break;
3206 }
3207 case RangeT::Scale::Log10: {
3208 if (start == 0 || end / start <= 0)
3209 break;
3210 offset = log10(end / start) * factor;
3211 range *= pow(10, offset);
3212 break;
3213 }
3214 case RangeT::Scale::Log2: {
3215 if (start == 0 || end / start <= 0)
3216 break;
3217 offset = log2(end / start) * factor;
3218 range *= exp2(offset);
3219 break;
3220 }
3221 case RangeT::Scale::Ln: {
3222 if (start == 0 || end / start <= 0)
3223 break;
3224 offset = log(end / start) * factor;
3225 range *= exp(offset);
3226 break;
3227 }
3228 case RangeT::Scale::Sqrt:
3229 if (start < 0 || end < 0)
3230 break;
3231 offset = (sqrt(end) - sqrt(start)) * factor;
3232 range += offset * offset;

Callers 1

Calls 12

appendMethod · 0.80
rangeMethod · 0.80
finiteMethod · 0.80
retransformScaleMethod · 0.80
countMethod · 0.45
indexMethod · 0.45
containsMethod · 0.45
startMethod · 0.45
endMethod · 0.45
scaleMethod · 0.45
sizeMethod · 0.45
setRangeMethod · 0.45

Tested by

no test coverage detected