MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / rescale

Method rescale

pj_plotting/widget/src/PlotMagnifier.cpp:29–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29void PlotMagnifier::rescale(double factor, AxisMode axis) {
30 factor = qAbs(1.0 / factor);
31
32 QwtPlot* qwt_plot = plot();
33 if (qwt_plot == nullptr || factor == 1.0) {
34 return;
35 }
36
37 bool do_replot = false;
38 const bool auto_replot = qwt_plot->autoReplot();
39 qwt_plot->setAutoReplot(false);
40
41 const int axis_list[2] = {QwtPlot::xBottom, QwtPlot::yLeft};
42 QRectF new_rect;
43
44 for (int index = 0; index < 2; ++index) {
45 double temp_factor = factor;
46 if (index == 1 && axis == kXAxis) {
47 temp_factor = 1.0;
48 }
49 if (index == 0 && axis == kYAxis) {
50 temp_factor = 1.0;
51 }
52
53 const int axis_id = axis_list[index];
54 if (!isAxisEnabled(axis_id)) {
55 continue;
56 }
57
58 const QwtScaleMap scale_map = qwt_plot->canvasMap(axis_id);
59 double v1 = scale_map.s1();
60 double v2 = scale_map.s2();
61 double center = axis_id == QwtPlot::yLeft ? mouse_position_.y() : mouse_position_.x();
62
63 if (scale_map.transformation()) {
64 v1 = scale_map.transform(v1);
65 v2 = scale_map.transform(v2);
66 }
67
68 const double width = v2 - v1;
69 const double ratio = (v2 - center) / width;
70 v1 = center - width * temp_factor * (1 - ratio);
71 v2 = center + width * temp_factor * ratio;
72
73 bool reversed_axis = false;
74 if (v1 > v2) {
75 reversed_axis = true;
76 std::swap(v1, v2);
77 }
78
79 if (scale_map.transformation()) {
80 v1 = scale_map.invTransform(v1);
81 v2 = scale_map.invTransform(v2);
82 }
83
84 v1 = std::max(v1, lower_bounds_[axis_id]);
85 v2 = std::min(v2, upper_bounds_[axis_id]);
86 qwt_plot->setAxisScale(axis_id, reversed_axis ? v2 : v1, reversed_axis ? v1 : v2);

Callers

nothing calls this directly

Calls 11

canvasMapMethod · 0.80
s1Method · 0.80
s2Method · 0.80
yMethod · 0.80
autoReplotMethod · 0.45
setAutoReplotMethod · 0.45
xMethod · 0.45
transformationMethod · 0.45
transformMethod · 0.45
invTransformMethod · 0.45
setAxisScaleMethod · 0.45

Tested by

no test coverage detected