feat(plot): vertical y-axis label via a rotated text run

This commit is contained in:
Martino Ferrari committed 2026-09-28 11:14:36 +02:00
1 parent 1cb5970757
commit daeb31b1ea
6 files changed
+453 -80

No files matched your search

+12 -9
View File
@@ -336,9 +336,10 @@ const PlotLayout& Plot::layout() {
// tick label can change that. Nothing at all is reserved without a text backend
// -- there is then no title to measure, which is what keeps the two defaults
// above meaningful for the no-text-backend case. The x strip is one text line
// per titled x axis tall (they are stacked in it); the y strip is as wide as the
// widest y title, since a y title is a horizontal run that stacks down the strip
// and so needs width rather than another row of it (see y_title_strip_width).
// per titled x axis tall (they are stacked in it); the y strip is one text line
// per titled y axis *wide*, because the y title is drawn rotated and so spends
// its length along the axes' height and takes a column, not a row, per titled
// axis (see y_title_strip_width).
const u32 x_titles = titled_x_axis_count();
const f32 y_title_w = text_ != nullptr ? y_title_strip_width() : 0.0f;
const f32 x_title_h = text_ != nullptr && x_titles != 0u
@@ -437,13 +438,15 @@ u32 Plot::titled_y_axis_count() const noexcept {
}
f32 Plot::y_title_strip_width() const {
// One text line per titled y axis, not the widest title's own width: the title
// is drawn rotated to read bottom-to-top, so it spends the axes' height and
// each titled axis needs a column of its own -- which is what keeps a Left/Right
// pair of titles from being drawn over each other now that they no longer stack
// down a taller strip.
if (text_ == nullptr) return 0.0f;
f32 widest = 0.0f;
for (const Axis& a : y_axes_) {
if (a.label.empty()) continue;
widest = std::max(widest, text_->measure(a.label.c_str()));
}
return widest > 0.0f ? widest + 2.0f * style_.grid_label_pad : 0.0f;
const u32 titles = titled_y_axis_count();
if (titles == 0u) return 0.0f;
return static_cast<f32>(titles) * text_->height() + 2.0f * style_.grid_label_pad;
}
f32 Plot::y_label_width() const {