fix(plot): a degenerate range cannot strand a live axis, and the demo's follow check fails the run
This commit is contained in:
1 parent
77e861f79e
commit
7d2349555d
6 files changed
+146
-13
No files matched your search
@@ -681,8 +681,8 @@ PLOT_TEST(drag_zoom_is_logical_the_wheel_is_not_scaled) {
|
||||
const f32 drag_px = 20.0f * scale; // 20 *logical* px at both scales
|
||||
c.on_pointer({strip_x, strip_y, 0, 0, plot::input::Button::Middle, 0, true, true, false});
|
||||
PLOT_CHECK(c.drag_mode() == plot::input::DragMode::AxisZoomX);
|
||||
c.on_pointer({strip_x, strip_y + drag_px, 0, drag_px, plot::input::Button::Middle, 0, true, false,
|
||||
false});
|
||||
c.on_pointer({strip_x, strip_y + drag_px, 0, drag_px, plot::input::Button::Middle, 0, true,
|
||||
false, false});
|
||||
c.on_pointer({strip_x, strip_y + drag_px, 0, 0, plot::input::Button::Middle, 0, false, false,
|
||||
true});
|
||||
PLOT_CHECK_NEAR(p.x_range(ax).span(), 100.0 * std::pow(10.0, -20.0 / 200.0), 1e-6);
|
||||
@@ -692,3 +692,32 @@ PLOT_TEST(drag_zoom_is_logical_the_wheel_is_not_scaled) {
|
||||
PLOT_CHECK_NEAR(p.x_range(ax).span(), span_before * std::exp(-0.15), 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
/// The consequences of a degenerate range on a live axis, from the gesture side: the
|
||||
/// wheel, the pan and the axis zoom all refuse a span that is not a span, so the
|
||||
/// frozen axis a stored zero-span left behind was one no interaction could move --
|
||||
/// while `x_follow()` said `Live`. With the guard in `set_x_range` the slips a caller
|
||||
/// can actually make leave the gestures working.
|
||||
PLOT_TEST(live_gestures_survive_a_degenerate_range) {
|
||||
LiveFixture f(200, 40);
|
||||
f.live();
|
||||
const plot::Rect axes = std::as_const(f.graph).layout().axes;
|
||||
const f64 span = f.xr().span();
|
||||
const f64 newest = f.newest();
|
||||
const plot::input::WheelEvent wheel = strip_wheel(f.graph, 1.0f);
|
||||
|
||||
f.graph.set_x_range(f.ax, {newest, newest}); // the programmatic slip
|
||||
PLOT_CHECK_NEAR(f.xr().span(), span, 1e-9);
|
||||
f.graph.set_x_range(f.ax, {newest - 5.0, newest - 15.0}); // and an inverted one
|
||||
PLOT_CHECK_NEAR(f.xr().span(), 10.0, 1e-9); // normalised, not stored inverted
|
||||
|
||||
f.controller.on_wheel(wheel);
|
||||
PLOT_CHECK_NEAR(f.xr().span(), 10.0 * std::exp(-0.15), 1e-9); // the wheel still zooms
|
||||
PLOT_CHECK(f.graph.x_follow(f.ax) == plot::XFollow::Live);
|
||||
const f64 span_after_wheel = f.xr().span();
|
||||
drag(f.controller, axes, 60.0f); // a left drag: the pan gesture
|
||||
PLOT_CHECK(f.graph.x_offset(f.ax) > 0.0); // the pan still pans
|
||||
PLOT_CHECK_NEAR(f.xr().span(), span_after_wheel, 1e-9);
|
||||
PLOT_CHECK_NEAR(f.xr().max, f.newest() - f.graph.x_offset(f.ax), 1e-9);
|
||||
PLOT_CHECK(f.graph.x_follow(f.ax) == plot::XFollow::Live);
|
||||
}
|
||||
Reference in new issue
Block a user