Give the distribution chart the height it is drawn in

This commit is contained in:
Roland Geider
2026-08-07 14:22:22 +02:00
parent 0329f3fde3
commit 4f2265907e
3 changed files with 53 additions and 1 deletions

View File

@@ -296,7 +296,9 @@ class MeasurementDistributionChart extends ConsumerWidget {
watch: (ref) =>
ref.watch(measurementValueCountsProvider(category.id!, range.countCutoff, summed)),
loading: const CenteredProgressIndicator(),
builder: (context, counts) => [_histogram(counts, summed)],
// The histogram fills the height it is given; the column around it would
// otherwise offer it an unbounded one
builder: (context, counts) => [Expanded(child: _histogram(counts, summed))],
onError: (_, error) => [StreamErrorIndicator(error.toString())],
);
}

View File

@@ -224,6 +224,34 @@ void main() {
expect(find.textContaining('Blutdruck'), findsNothing);
});
testWidgets('A distribution category draws its histogram in the chart box', (
WidgetTester tester,
) async {
// The histogram fills the height it is given, and the list around it is a
// scrollable: an unbounded box reaching it is a layout error
final category = MeasurementCategory(
id: 'c1',
name: 'Bizeps',
unit: 'cm',
chartType: ChartType.distribution,
);
final entries = [
for (var day = 0; day < 30; day++)
MeasurementEntry(
id: 'e-$day',
categoryId: 'c1',
date: DateTime.now().subtract(Duration(days: day)),
value: 30 + day % 5,
notes: '',
),
];
await tester.pumpWidget(createEntriesList(category, {'c1': entries}));
await tester.pumpAndSettle();
expect(find.byType(MeasurementDistributionWidgetFl), findsOneWidget);
});
testWidgets('A free-form category keeps the name the user gave it', (
WidgetTester tester,
) async {

View File

@@ -121,6 +121,28 @@ void stubMeasurementReads(
});
});
// Counted over the whole fixture: the cutoff and the daily summing are the
// repository's own, and covered where they happen
when(
repo.watchValueCounts(any, since: anyNamed('since'), summedPerDay: anyNamed('summedPerDay')),
).thenAnswer((invocation) {
final ofCategory = entries[invocation.positionalArguments.first as String] ?? const [];
final byValue = <num, List<MeasurementEntry>>{};
for (final entry in ofCategory) {
byValue.putIfAbsent(entry.value, () => []).add(entry);
}
return Stream.value([
for (final MapEntry(:key, :value) in byValue.entries)
MeasurementValueCount(
value: key,
unit: null,
count: value.length,
newest: value.map((e) => e.date).reduce((a, b) => b.isAfter(a) ? b : a),
),
]);
});
when(repo.watchDailyBuckets()).thenAnswer(
(_) => Stream.value({
for (final id in entries.keys) id: dayBuckets(entries[id]!),