fix(plot): a figure row's strip shows labels and title independently, and the shared axis is the bottom row's strip
This commit is contained in:
1 parent
8f1e60a105
commit
770da4c2b2
9 files changed
+415
-175
No files matched your search
+43
-21
@@ -17,6 +17,34 @@
|
||||
|
||||
namespace plot {
|
||||
|
||||
/// Which parts of a plot's bottom x chrome `layout()` reserves.
|
||||
///
|
||||
/// The bottom chrome is two strips -- the *label* strip the tick labels live in and
|
||||
/// the *title* strip the axis titles live in -- and they are one enum rather than two
|
||||
/// flags because a strip means little on its own: a title with no labels needs a row
|
||||
/// of its own below where the labels would have been, and a figure's interior rows want
|
||||
/// neither. Naming the combinations keeps a caller from switching one off and silently
|
||||
/// taking the other with it, which is what a boolean would do.
|
||||
///
|
||||
/// The one caller that selects a mode is `Figure`: an interior row of a figure that
|
||||
/// draws its x labels on the bottom only reserves no x chrome at all (`None`), so its
|
||||
/// `axes` reaches its rect's bottom edge and the figure's one x axis -- the bottom row's
|
||||
/// own, whose strip the shared axis occupies -- is the figure's only one. A plot drawn
|
||||
/// on its own is `Both`, which is what it has always been; `LabelsOnly` and `TitleOnly`
|
||||
/// are for a host that wants one without the other.
|
||||
enum class XStrip { Both, LabelsOnly, TitleOnly, None };
|
||||
|
||||
/// Whether a strip mode reserves the label strip. One rule, read by `Plot::layout()`
|
||||
/// when it sizes the strip and by the renderer when it decides whether to stage the
|
||||
/// labels -- a row that reserves none would otherwise stage them over its own data.
|
||||
constexpr bool x_strip_has_labels(XStrip mode) noexcept {
|
||||
return mode == XStrip::Both || mode == XStrip::LabelsOnly;
|
||||
}
|
||||
/// Whether a strip mode reserves the title strip, the same one rule for the title.
|
||||
constexpr bool x_strip_has_title(XStrip mode) noexcept {
|
||||
return mode == XStrip::Both || mode == XStrip::TitleOnly;
|
||||
}
|
||||
|
||||
/// Pixel geometry of a plot's chrome, all of it in the same pixel space as
|
||||
/// `Rect` (origin top-left) and therefore in **device** pixels: everything here is
|
||||
/// what the renderer draws with, already converted from the logical metrics in
|
||||
@@ -43,9 +71,8 @@ struct PlotLayout {
|
||||
/// Left strip width. The default is used when no text backend has been set.
|
||||
f32 y_axis_width = 56.0f;
|
||||
/// Bottom strip height. The default is used when no text backend has been set, and
|
||||
/// it is 0.0f when the strip is not reserved at all -- see
|
||||
/// `Plot::set_x_label_strip()`, which is how a row of a `Figure` hands the band to
|
||||
/// the figure's one shared axis.
|
||||
/// it is 0.0f when the label strip is not reserved at all -- see `XStrip`, which is
|
||||
/// how a row of a `Figure` hands the band to the figure's one shared x axis.
|
||||
f32 x_axis_height = 22.0f;
|
||||
/// Width of `y_title_area` and height of `x_title_area`, both 0.0f when nothing
|
||||
/// is reserved. Every titled axis of a direction gets its own text line inside
|
||||
@@ -134,23 +161,18 @@ class Plot {
|
||||
/// The scale the last layout was computed at. 1.0 until a host says otherwise.
|
||||
f32 ui_scale() const noexcept { return style_.ui_scale; }
|
||||
|
||||
/// Whether `layout()` reserves the bottom x label strip -- and, with it, the x
|
||||
/// title strip: a title is the labels' caption and goes where they do.
|
||||
/// Which parts of the bottom x chrome `layout()` reserves; `XStrip::Both` by
|
||||
/// default, which is what a plot drawn on its own has always been.
|
||||
///
|
||||
/// True by default, which is what a plot drawn on its own has always been. A
|
||||
/// `Figure` turns it off on every row while it draws one shared x axis under its
|
||||
/// last row (see `Figure::set_x_labels_only_on_bottom()`): the strip is not
|
||||
/// merely left blank, it is not reserved at all, so such a row's `axes` reaches
|
||||
/// the row rect's bottom edge and the row gives the band to the figure's shared
|
||||
/// axis instead of growing a second, duplicate one. Nothing else about the row
|
||||
/// changes -- its ticks still refresh and its grid still builds, because the
|
||||
/// tick list is what the shared axis and the grid are drawn from, not the strip.
|
||||
///
|
||||
/// The plot it belongs to draws no x tick labels while it is off (their strip
|
||||
/// has no height left to hold them); whoever turned it off is the one that puts
|
||||
/// them somewhere -- `Renderer::draw(Figure&)` draws them in the figure's strip.
|
||||
void set_x_label_strip(bool on) noexcept { x_label_strip_ = on; }
|
||||
bool x_label_strip() const noexcept { return x_label_strip_; }
|
||||
/// A part that is not reserved costs nothing: the strip has no height (or the title
|
||||
/// no row), `axes` grows into the band, and the renderer stages no run for it. A
|
||||
/// figure's interior rows are the case that asked for it -- they sit under one shared
|
||||
/// x axis, so they reserve no x chrome at all -- and `Figure::set_x_labels_only_on_bottom()`
|
||||
/// is what selects their mode. Nothing else about such a row changes: its ticks still
|
||||
/// refresh and its grid still builds, because the tick list is what a grid and a
|
||||
/// shared axis are drawn from, not the strip.
|
||||
void set_x_strip_mode(XStrip mode) noexcept { x_strip_ = mode; }
|
||||
XStrip x_strip_mode() const noexcept { return x_strip_; }
|
||||
|
||||
/// The font layout() measures tick labels with. Borrowed, not owned, and may be
|
||||
/// null -- then the label areas fall back to PlotLayout's defaults and no string
|
||||
@@ -555,8 +577,8 @@ class Plot {
|
||||
render::Style style_{};
|
||||
const render::TextBackend* text_ = nullptr;
|
||||
Legend legend_{};
|
||||
/// Whether the bottom x label strip is reserved at all; see set_x_label_strip().
|
||||
bool x_label_strip_ = true;
|
||||
/// Which parts of the bottom x chrome are reserved at all; see set_x_strip_mode().
|
||||
XStrip x_strip_ = XStrip::Both;
|
||||
/// Which handles a pointer is on, published by the input layer (see HotHandles).
|
||||
HotHandles hot_{};
|
||||
|
||||
|
||||
Reference in new issue
Block a user