Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/plot/heatmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ namespace plot::impl {
if constexpr (title_t::present) {
auto title = std::get<title_t::position>( tuple );
if( !title.color ) title.color = plot::attribute::color_t{ th.fg };
// place the title sensibly when the caller didn't (e.g. plot::title("…")
// inside a grid) — otherwise it would render at the {0,0} fallback.
if( !title.position ) title.position = position{ std::size_t{4}, std::size_t{10} };
canvas << title;
}
if constexpr (footnote_t::present) canvas << std::get<footnote_t::position>( tuple );
Expand Down
5 changes: 4 additions & 1 deletion include/plot/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ namespace plot {
}

void ostream( impl::canvas_t& os ) const {
os.text(txt, position->x, position->y, *this );
// `position` is optional; a title created without an explicit position
// must NOT dereference it (that reads an uninitialized variant — UB).
const auto pos = position.value_or(attribute::position_t{});
os.text(txt, pos.x, pos.y, *this );
}
const std::string txt;
};
Expand Down
Loading