Let a date range be stated, and draw the axis at the scale it deserves
"Limit to range" did nothing, and the reason was not visible from the button. It took its span from the timeline's zoom, which is zero until someone zooms — so `zoomed_span` returned the whole library and the filter narrowed to everything. The chip lit up and the grid did not change. The range has ends now, shown and typed as `YYYY-MM-DD`. Seeding them from the timeline is kept, because zooming to a fortnight and pressing the chip is the fast path; the fields say which fortnight it landed on and let it be corrected. Ends given backwards are swapped rather than refused — there is exactly one range between two days — and the closing day is included, since "to the 5th" means the whole of the 5th and a range ending at its midnight contains none of it. `parse_date` refuses anything that is not a date rather than guessing at an order, because the alternative is a library silently filtered to a span nobody asked for. The axis then follows the range. It used to keep drawing the full extent while a range was on, because it was the only way back out; the typed ends are the way back out now, so it is free to show what was asked about. And bucket size is chosen by how many bars it makes rather than by fixed cut-offs. Each zoom step halves the span, so under thresholds the bar count halved with it until a boundary was crossed: fifteen years went 15 bars, 8, then 46, 23, 11, and finally 6. Zooming in made the picture coarser, which is the opposite of what zooming is for. Aiming at forty bars keeps the count in the same neighbourhood at every level, and the test asserts the property directly — halving a span never coarsens the bucket. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3542,6 +3542,20 @@ fn refresh_timeline(window: &AppWindow, catalog: &Catalog, ctl: &Rc<LibraryContr
|
||||
}
|
||||
};
|
||||
|
||||
// A chosen date range is what the axis draws, when there is one.
|
||||
//
|
||||
// It used to keep drawing the full extent while a range was on, because
|
||||
// the axis was the only way back out: narrow it to the range and there
|
||||
// would be nothing left to widen from. The range now has typed ends, and
|
||||
// those are the way back out — so the axis is free to show the span the
|
||||
// user actually asked about, at the granularity that span deserves. A
|
||||
// fortnight drawn across fifteen years is one column; drawn across itself
|
||||
// it is fourteen days.
|
||||
let span = match (filter.captured_from, filter.captured_to) {
|
||||
(Some(from), Some(to)) if to > from => (from, to),
|
||||
_ => span,
|
||||
};
|
||||
|
||||
// Zoom narrows the span around wherever the view sits rather than around
|
||||
// the library's midpoint, so zooming in keeps what you were looking at.
|
||||
let zoom = *ctl.timeline_zoom.borrow();
|
||||
@@ -4652,6 +4666,52 @@ pub fn wire<F>(
|
||||
f.captured_to = None;
|
||||
}
|
||||
w.set_library_range_active(on);
|
||||
show_range(&w, &ctl);
|
||||
refilter(&w, &ctl);
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-CAT-6
|
||||
// The ends of the range, typed.
|
||||
//
|
||||
// The chip alone used to be the whole control and it read its span from
|
||||
// the timeline's zoom, which is zero until someone zooms — so "limit to
|
||||
// range" set the range to the entire library and appeared to do nothing.
|
||||
// The span is shown now, and these two fields are how it is corrected.
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_library_range_edited(move |from, to| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
|
||||
// Both ends, or neither. A range with one end parsed and the other
|
||||
// silently dropped is a filter nobody asked for, and the grid
|
||||
// going empty is a poor way to find out a date was mistyped.
|
||||
let (Some(from), Some(to)) = (
|
||||
dr_types::parse_date(from.as_str()),
|
||||
dr_types::parse_date(to.as_str()),
|
||||
) else {
|
||||
w.set_library_range_invalid(true);
|
||||
return;
|
||||
};
|
||||
|
||||
// Typed the other way round is a slip, not an error: the user has
|
||||
// said which two days they mean and there is exactly one range
|
||||
// between them.
|
||||
let (from, to) = if from <= to { (from, to) } else { (to, from) };
|
||||
|
||||
{
|
||||
let mut f = ctl.filter.borrow_mut();
|
||||
f.captured_from = Some(from);
|
||||
// Inclusive of the last day. "To the 5th" means the whole of
|
||||
// the 5th — `parse_date` returns its midnight, and a range
|
||||
// ending there would exclude every photograph taken on the day
|
||||
// the user named.
|
||||
f.captured_to = Some(to + 86_400 - 1);
|
||||
}
|
||||
w.set_library_range_invalid(false);
|
||||
w.set_library_range_active(true);
|
||||
show_range(&w, &ctl);
|
||||
refilter(&w, &ctl);
|
||||
});
|
||||
}
|
||||
@@ -5114,6 +5174,46 @@ mod tests {
|
||||
assert_eq!(y, 1969);
|
||||
}
|
||||
|
||||
/// The axis follows a chosen range, so its granularity does too.
|
||||
///
|
||||
/// The complaint this fixes: a fortnight selected out of a fifteen-year
|
||||
/// library was still drawn as one column of a year-per-bar axis, which is
|
||||
/// the least useful picture of a fortnight available.
|
||||
#[test]
|
||||
fn a_chosen_range_decides_the_granularity() {
|
||||
use dr_catalog::Granularity;
|
||||
const DAY: i64 = 86_400;
|
||||
|
||||
// Fifteen years unfiltered: a bar per year, fifteen of them.
|
||||
assert_eq!(Granularity::for_span(15 * 365 * DAY), Granularity::Year);
|
||||
|
||||
// Narrowed to a fortnight, the axis is handed the range rather than
|
||||
// the extent, and a fortnight is drawn as fourteen days.
|
||||
assert_eq!(Granularity::for_span(14 * DAY), Granularity::Day);
|
||||
|
||||
// A single day's shoot is drawn by the hour.
|
||||
assert_eq!(Granularity::for_span(DAY), Granularity::Hour);
|
||||
|
||||
// The property rather than the thresholds, because the thresholds are
|
||||
// no longer what decides it: a narrower range never produces a coarser
|
||||
// bucket than a wider one.
|
||||
let mut previous = i64::MAX;
|
||||
for days in [3650, 730, 180, 60, 14, 3, 1] {
|
||||
let g = Granularity::for_span(days * DAY);
|
||||
let bucket = match g {
|
||||
Granularity::Year => 365 * DAY,
|
||||
Granularity::Month => 30 * DAY,
|
||||
Granularity::Day => DAY,
|
||||
Granularity::Hour => 3600,
|
||||
};
|
||||
assert!(
|
||||
bucket <= previous,
|
||||
"{days} days chose a coarser bucket than the range above it"
|
||||
);
|
||||
previous = bucket;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bucket_labels_match_their_granularity() {
|
||||
use dr_catalog::Granularity;
|
||||
@@ -5554,3 +5654,21 @@ mod display_name_tests {
|
||||
assert_eq!(without_extension(""), "");
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: FR-CAT-6
|
||||
/// Show the range the filter is actually using.
|
||||
///
|
||||
/// Pushed back rather than left as the user typed it, because the filter may
|
||||
/// have adjusted it — ends given backwards are swapped, and the closing day is
|
||||
/// extended to include itself. A field showing something other than what is
|
||||
/// being filtered on is worse than one showing nothing.
|
||||
fn show_range(window: &AppWindow, ctl: &Rc<LibraryController>) {
|
||||
let f = ctl.filter.borrow();
|
||||
let text = |t: Option<i64>| -> slint::SharedString {
|
||||
t.map(dr_types::format_date).unwrap_or_default().into()
|
||||
};
|
||||
window.set_library_range_from(text(f.captured_from));
|
||||
// The stored end is the last second of the closing day; naming that day is
|
||||
// what the user typed and what they should read back.
|
||||
window.set_library_range_to(text(f.captured_to.map(|t| t - 86_400 + 1)));
|
||||
}
|
||||
|
||||
@@ -455,6 +455,11 @@ export component AppWindow inherits Window {
|
||||
/// Whether the grid is narrowed to the timeline's visible span.
|
||||
in-out property <bool> library-range-active: false;
|
||||
callback library-toggle-date-range();
|
||||
/// TRACES: FR-CAT-6
|
||||
in property <string> library-range-from;
|
||||
in property <string> library-range-to;
|
||||
in property <bool> library-range-invalid: false;
|
||||
callback library-range-edited(string, string);
|
||||
callback library-retry-connection();
|
||||
|
||||
// --- pinning a collection offline (FR-NC-6a) ---
|
||||
@@ -1314,6 +1319,10 @@ in property <bool> panel-visible: true;
|
||||
toggle-local-only() => { root.library-toggle-local-only(); }
|
||||
range-active: root.library-range-active;
|
||||
toggle-date-range() => { root.library-toggle-date-range(); }
|
||||
range-from: root.library-range-from;
|
||||
range-to: root.library-range-to;
|
||||
range-invalid: root.library-range-invalid;
|
||||
range-edited(a, b) => { root.library-range-edited(a, b); }
|
||||
|
||||
collections-visible: root.collections-visible;
|
||||
toggle-collections() => { root.toggle-collections(); }
|
||||
|
||||
@@ -1098,6 +1098,19 @@ export component LibraryGrid inherits Rectangle {
|
||||
/// Whether the grid is narrowed to the timeline's visible span.
|
||||
in property <bool> range-active: false;
|
||||
callback toggle-date-range();
|
||||
/// TRACES: FR-CAT-6
|
||||
/// The ends of the range, as `YYYY-MM-DD`, when one is set.
|
||||
///
|
||||
/// Strings rather than instants because this is what the user types and
|
||||
/// what they read back. Rust parses them and refuses what is not a date;
|
||||
/// `range-invalid` is how that refusal reaches the field, since a filter
|
||||
/// that silently ignored a typo would show an empty grid and no reason.
|
||||
in property <string> range-from;
|
||||
in property <string> range-to;
|
||||
in property <bool> range-invalid: false;
|
||||
/// Both ends at once: they are one range, and applying half of an edit
|
||||
/// would filter to a span the user never asked for.
|
||||
callback range-edited(string, string);
|
||||
|
||||
/// How many images are selected, for the header's count.
|
||||
in property <int> selected-count: 0;
|
||||
@@ -1732,6 +1745,51 @@ export component LibraryGrid inherits Rectangle {
|
||||
clicked => { root.toggle-date-range(); }
|
||||
}
|
||||
|
||||
// The ends, once there is a range to have ends.
|
||||
//
|
||||
// Turning the chip on used to be the whole control, and it
|
||||
// took its span from the timeline's zoom — which is zero until
|
||||
// you zoom, so the range came out as the entire library and
|
||||
// the button appeared to do nothing at all. The span is now
|
||||
// *shown*, and can be typed, so "limit to range" always
|
||||
// narrows to something a person chose.
|
||||
//
|
||||
// Still seeded from the timeline: zooming to a fortnight and
|
||||
// pressing the chip is the fast path, and these fields say
|
||||
// which fortnight it landed on.
|
||||
if root.range-active: HorizontalLayout {
|
||||
spacing: Theme.gap-sm;
|
||||
|
||||
Field {
|
||||
width: 108px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
text: root.range-from;
|
||||
placeholder: "YYYY-MM-DD";
|
||||
accepted(t) => { root.range-edited(t, root.range-to); }
|
||||
}
|
||||
|
||||
Caption {
|
||||
text: "to";
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Field {
|
||||
width: 108px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
text: root.range-to;
|
||||
placeholder: "YYYY-MM-DD";
|
||||
accepted(t) => { root.range-edited(root.range-from, t); }
|
||||
}
|
||||
|
||||
// Says which end is wrong is beyond a caption, but saying
|
||||
// that *something* is beats an empty grid with no reason.
|
||||
if root.range-invalid: Caption {
|
||||
text: "not a date";
|
||||
warn: true;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
|
||||
// What the filter is currently hiding. Without this a narrowed
|
||||
|
||||
Reference in New Issue
Block a user