feat(plot): the figure crosshair marks the hovered row, and the stroke is thin, dashed and configurable
This commit is contained in:
1 parent
cae672bc99
commit
eee7c34dd5
12 files changed
+166
-12
No files matched your search
@@ -449,6 +449,22 @@ void Figure::set_crosshair(f64 x, bool active) {
|
||||
for (Plot& row : plots_) row.set_crosshair(x, active);
|
||||
}
|
||||
|
||||
void Figure::set_crosshair(f64 x, u32 hovered_row, f64 y_in_row, bool active) {
|
||||
// The shared x first, on every row -- the same state the single-coordinate overload leaves,
|
||||
// so the vertical lines and every row's readout are placed by one rule whether or not the
|
||||
// pointer's row is known. A bad x is refused by the row call, which changes nothing, so the
|
||||
// y below must not run either or the hover would be half-placed.
|
||||
if (active && !std::isfinite(x)) return;
|
||||
for (Plot& row : plots_) row.set_crosshair(x, active);
|
||||
// Then the pointer row's own y: the *only* row that gets a horizontal line, because the y is
|
||||
// a value on that row's scale and no other row's. A row that does not exist (the pointer is in
|
||||
// the gap between rows) leaves every row vertical-only, which is the honest answer -- there is
|
||||
// no row under the pointer to mark -- and a non-finite y leaves the row vertical-only rather
|
||||
// than clearing a hover the pointer still has.
|
||||
if (!active || hovered_row >= plots_.size()) return;
|
||||
plots_[hovered_row].set_crosshair(x, y_in_row, true);
|
||||
}
|
||||
|
||||
void Figure::clear_crosshair() {
|
||||
for (Plot& row : plots_) row.clear_crosshair();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user