figure: cells of a row can share one y range
This commit is contained in:
1 parent
73f610b136
commit
25c3381551
6 files changed
+214
-7
No files matched your search
@@ -1275,3 +1275,69 @@ PLOT_TEST(figure_cells_common_y_gutter) {
|
||||
PLOT_CHECK(g0 > 0.0);
|
||||
PLOT_CHECK_NEAR(g0, g1, 0.01);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_cells_share_a_range_after_a_gesture) {
|
||||
plot::Figure figure = split_figure({2, 1});
|
||||
figure.set_share_row_y(true);
|
||||
figure.layout();
|
||||
figure.plot(1u).set_y_range(0u, {-3.0, 7.0}); // what a wheel / drag / pan ends in
|
||||
figure.layout();
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).min, -3.0, 1e-9);
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).max, 7.0, 1e-9);
|
||||
PLOT_CHECK_NEAR(figure.plot(1u).y_range(0u).min, -3.0, 1e-9);
|
||||
PLOT_CHECK_NEAR(figure.plot(1u).y_range(0u).max, 7.0, 1e-9);
|
||||
// The unsplit row is its own thing.
|
||||
PLOT_CHECK_NEAR(figure.plot(2u).y_range(0u).min, -1.0, 1e-9);
|
||||
PLOT_CHECK(!figure.row_y_auto(0u));
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_auto_fits_the_union_and_ignores_empty_cells) {
|
||||
plot::Figure figure = split_figure({3});
|
||||
for (plot::u32 i = 0; i < 3u; ++i) figure.plot(i).set_y_auto_scale(0u, true);
|
||||
plot::data::ArraySeries a(std::vector<plot::f32>{0.0f, 10.0f, 5.0f}, 0.0, 1.0);
|
||||
plot::data::ArraySeries b(std::vector<plot::f32>{-20.0f, 5.0f, 0.0f}, 0.0, 1.0);
|
||||
figure.plot(0u).add_trace({&a, plot::Color::hex(0x40C0FF), 1.5f, 0u, 0u});
|
||||
figure.plot(1u).add_trace({&b, plot::Color::hex(0xFF8080), 1.5f, 0u, 0u});
|
||||
figure.set_share_row_y(true); // cell 2 has no trace
|
||||
figure.layout();
|
||||
PLOT_CHECK(figure.row_y_auto(0u));
|
||||
const plot::Range r0 = figure.plot(0u).y_range(0u);
|
||||
PLOT_CHECK(r0.min <= -20.0 && r0.max >= 10.0);
|
||||
PLOT_CHECK(r0.max - r0.min < 40.0); // padded, not blown up
|
||||
for (plot::u32 i = 1; i < 3u; ++i) {
|
||||
PLOT_CHECK_NEAR(figure.plot(i).y_range(0u).min, r0.min, 1e-9);
|
||||
PLOT_CHECK_NEAR(figure.plot(i).y_range(0u).max, r0.max, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_manual_then_fit_returns_to_auto) {
|
||||
plot::Figure figure = split_figure({2});
|
||||
for (plot::u32 i = 0; i < 2u; ++i) figure.plot(i).set_y_auto_scale(0u, true);
|
||||
plot::data::ArraySeries a(std::vector<plot::f32>{0.0f, 10.0f}, 0.0, 1.0);
|
||||
plot::data::ArraySeries b(std::vector<plot::f32>{-4.0f, 4.0f}, 0.0, 1.0);
|
||||
figure.plot(0u).add_trace({&a, plot::Color::hex(0x40C0FF), 1.5f, 0u, 0u});
|
||||
figure.plot(1u).add_trace({&b, plot::Color::hex(0xFF8080), 1.5f, 0u, 0u});
|
||||
figure.set_share_row_y(true);
|
||||
figure.layout();
|
||||
figure.plot(1u).set_y_range(0u, {1.0, 2.0});
|
||||
figure.layout();
|
||||
PLOT_CHECK(!figure.row_y_auto(0u));
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).min, 1.0, 1e-9);
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).max, 2.0, 1e-9);
|
||||
figure.layout(); // manual holds: no fight with the plots' own autoscale
|
||||
PLOT_CHECK_NEAR(figure.plot(1u).y_range(0u).max, 2.0, 1e-9);
|
||||
figure.plot(0u).auto_fit_y(0u); // what fit-all / double-click does to one cell
|
||||
figure.layout();
|
||||
PLOT_CHECK(figure.row_y_auto(0u));
|
||||
PLOT_CHECK(figure.plot(1u).y_range(0u).min <= -4.0 && figure.plot(1u).y_range(0u).max >= 10.0);
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).min, figure.plot(1u).y_range(0u).min, 1e-9);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_sharing_off_keeps_cells_independent) {
|
||||
plot::Figure figure = split_figure({2});
|
||||
figure.layout();
|
||||
figure.plot(1u).set_y_range(0u, {-3.0, 7.0});
|
||||
figure.layout();
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).max, 1.0, 1e-9);
|
||||
PLOT_CHECK(!figure.share_row_y());
|
||||
}
|
||||
Reference in new issue
Block a user