figure: shared-y rows draw one y axis, on the first cell
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
25c3381551
commit
2b4b316ad8
6 files changed
+172
-5
No files matched your search
@@ -1341,3 +1341,70 @@ PLOT_TEST(figure_row_y_sharing_off_keeps_cells_independent) {
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).y_range(0u).max, 1.0, 1e-9);
|
||||
PLOT_CHECK(!figure.share_row_y());
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_only_the_first_cell_has_a_gutter) {
|
||||
plot::Figure figure = split_figure({1, 3}, false);
|
||||
for (plot::u32 i = 0; i < figure.plot_count(); ++i) give_magnitude_row(figure.plot(i), 0u);
|
||||
figure.set_share_row_y(true);
|
||||
figure.layout();
|
||||
PLOT_CHECK(figure.plot(0u).layout().y_axis_width > 0.0f); // unsplit row keeps its axis
|
||||
PLOT_CHECK(figure.plot(1u).layout().y_axis_width > 0.0f); // first cell of the split row
|
||||
for (plot::u32 i = 2; i < 4u; ++i) {
|
||||
const plot::PlotLayout& l = figure.plot(i).layout();
|
||||
PLOT_CHECK(l.y_axis_width == 0.0f && l.y_title_width == 0.0f && l.y_label_area.w == 0.0f);
|
||||
PLOT_CHECK(l.axes.w > 0.0f);
|
||||
}
|
||||
// The gutter is one figure-wide value: the unsplit row and the split row's first cell agree.
|
||||
PLOT_CHECK_NEAR(figure.plot(0u).layout().axes.x - figure.layout().cells[0].x,
|
||||
figure.plot(1u).layout().axes.x - figure.layout().cells[1].x, 0.01);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_equal_weights_give_equal_plot_widths_and_cells_tile) {
|
||||
plot::Figure figure = split_figure({3}, false);
|
||||
for (plot::u32 i = 0; i < 3u; ++i) give_magnitude_row(figure.plot(i), 0u);
|
||||
figure.set_col_gap(8.0f);
|
||||
figure.set_share_row_y(true);
|
||||
const plot::FigureLayout& fl = figure.layout();
|
||||
const double w0 = figure.plot(0u).layout().axes.w;
|
||||
PLOT_CHECK_NEAR(figure.plot(1u).layout().axes.w, w0, 0.6);
|
||||
PLOT_CHECK_NEAR(figure.plot(2u).layout().axes.w, w0, 0.6);
|
||||
PLOT_CHECK_NEAR(fl.cells[0].x, fl.rows[0].x, 0.001);
|
||||
PLOT_CHECK_NEAR(fl.cells[2].right(), fl.rows[0].right(), 0.001);
|
||||
PLOT_CHECK_NEAR(fl.cells[1].x - fl.cells[0].right(), 8.0, 0.01);
|
||||
PLOT_CHECK_NEAR(fl.cells[2].x - fl.cells[1].right(), 8.0, 0.01);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_weights_apply_to_plot_widths) {
|
||||
plot::Figure figure = split_figure({2}, false);
|
||||
for (plot::u32 i = 0; i < 2u; ++i) give_magnitude_row(figure.plot(i), 0u);
|
||||
figure.set_col_gap(0.0f);
|
||||
figure.set_share_row_y(true);
|
||||
const std::vector<plot::f32> w{3.0f, 1.0f};
|
||||
PLOT_CHECK(figure.set_cell_weights(0u, w));
|
||||
figure.layout();
|
||||
const double a0 = figure.plot(0u).layout().axes.w;
|
||||
const double a1 = figure.plot(1u).layout().axes.w;
|
||||
PLOT_CHECK_NEAR(a0 - 64.0, (a1 - 64.0) * 3.0, 1.0);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_narrow_row_degrades_without_negative_rects) {
|
||||
plot::Figure figure = split_figure({4}, false);
|
||||
figure.set_viewport(plot::Rect{0.0f, 0.0f, 30.0f, 100.0f});
|
||||
for (plot::u32 i = 0; i < 4u; ++i) give_magnitude_row(figure.plot(i), 0u);
|
||||
figure.set_col_gap(10.0f);
|
||||
figure.set_share_row_y(true);
|
||||
double sum = 0.0;
|
||||
for (const plot::Rect& c : figure.layout().cells) {
|
||||
PLOT_CHECK(c.w >= 0.0f && c.h >= 0.0f);
|
||||
sum += c.w;
|
||||
}
|
||||
PLOT_CHECK_NEAR(sum, 30.0, 0.05);
|
||||
}
|
||||
|
||||
PLOT_TEST(figure_row_y_sharing_off_still_gives_every_cell_a_gutter) {
|
||||
plot::Figure figure = split_figure({2}, false);
|
||||
give_magnitude_row(figure.plot(0u), 0u);
|
||||
give_magnitude_row(figure.plot(1u), 1u);
|
||||
figure.layout();
|
||||
PLOT_CHECK(figure.plot(1u).layout().y_axis_width > 0.0f);
|
||||
}
|
||||
@@ -5059,6 +5059,52 @@ PLOT_TEST(figure_x_title_is_drawn_on_the_bottom_row_only) {
|
||||
|
||||
ctx.destroy();
|
||||
}
|
||||
/// A split row that shares one y axis draws it once, on its first cell: every later cell is
|
||||
/// `YStrip::None`, reserves no y strip, and the renderer must stage no y tick labels for it.
|
||||
/// Staged text is not observable through `FrameStats`, so this reads the pixels. The column gap
|
||||
/// is wide and empty chrome, and a label staged for the second cell would be right-aligned
|
||||
/// against that cell's (zero-width) label area, i.e. land in the gap: the gap holds no ink.
|
||||
PLOT_TEST(figure_shared_y_second_cell_stages_no_y_labels) {
|
||||
plottest::HeadlessContext ctx(kW, kH);
|
||||
plot::Status st;
|
||||
PLOT_CHECK(ctx.create(&st));
|
||||
PLOT_CHECK(plot::gl::load(nullptr));
|
||||
plot::Renderer r;
|
||||
PLOT_CHECK(r.init(&st));
|
||||
|
||||
const std::vector<plot::u32> cells{2u};
|
||||
plot::Figure figure{std::span<const plot::u32>(cells)};
|
||||
figure.set_viewport({0, 0, static_cast<plot::f32>(kW), static_cast<plot::f32>(kH)});
|
||||
for (plot::u32 i = 0; i < 2u; ++i) {
|
||||
plot::Plot& p = figure.plot(i);
|
||||
p.add_x_axis({"t", {0.0, 100.0}, false, plot::AxisPlace::Bottom, false});
|
||||
p.add_y_axis({"", {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
}
|
||||
figure.set_col_gap(80.0f);
|
||||
figure.set_share_row_y(true);
|
||||
|
||||
r.begin_frame(kW, kH, {0, 0, static_cast<plot::f32>(kW), static_cast<plot::f32>(kH)});
|
||||
r.draw(figure);
|
||||
r.end_frame();
|
||||
PLOT_CHECK(!r.last_frame_had_gl_error());
|
||||
const plot::FigureLayout layout = figure.layout();
|
||||
const plot::Color ink = r.style().axis_text;
|
||||
|
||||
const plot::PlotLayout& first = figure.plot(0u).layout();
|
||||
const plot::PlotLayout& second = figure.plot(1u).layout();
|
||||
PLOT_CHECK(second.y_label_area.w == 0.0f);
|
||||
PLOT_CHECK(layout.cells[1].x - layout.cells[0].right() > 70.0f);
|
||||
// The first cell still draws the row's one axis ...
|
||||
PLOT_CHECK(scan_rect_ink(ctx, first.y_label_area, ink).pixels > 0u);
|
||||
// ... and nothing is staged in the gap on the second cell's left.
|
||||
// Inset a few pixels each side: the cells' own frame lines sit on the gap's two edges.
|
||||
const plot::Rect gap{layout.cells[0].right() + 4.0f, first.axes.y,
|
||||
layout.cells[1].x - layout.cells[0].right() - 8.0f, first.axes.h};
|
||||
PLOT_CHECK(scan_rect_ink(ctx, gap, ink).pixels == 0u);
|
||||
|
||||
ctx.destroy();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------- the axes clip (spec §13)
|
||||
|
||||
// The reported defect this section is about: a trace is staged in *data* space and
|
||||
|
||||
Reference in new issue
Block a user