From ca42f46565d9d2869937ffd7a8bb6e7a4c438b04 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 14 Nov 2024 14:56:29 +0100 Subject: [PATCH] Handle special case in sparkline chart where all values are 0 (#8287) --- pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart b/pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart index 7d2c43680..c63c8b16b 100644 --- a/pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart +++ b/pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart @@ -53,7 +53,9 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText, final firstDay = firstDate.copyWith(day: firstDate.day - 7); final xAxisSpan = lastDate.difference(firstDate); - final maxDownloads = data.fold(0, (a, b) => max(a, b.downloads)); + // We start with 1 as initial value. In the special case where all downloads + // are 0 we want a straight line in the bottom of the chart. + final maxDownloads = data.fold(1, (a, b) => max(a, b.downloads)); final toolTipOffsetFromMouse = 15;