Changed Graph Tooltip text

This commit is contained in:
2025-01-27 14:47:18 +01:00
parent 537c231253
commit c75d905dd8

View File

@@ -46,6 +46,19 @@ class ReadingGraph extends StatelessWidget {
topTitles: const AxisTitles(sideTitles: SideTitles()),
rightTitles: const AxisTitles(sideTitles: SideTitles()),
),
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
getTooltipItems: (touchedSpots) {
return touchedSpots.map((touchedSpot) {
return LineTooltipItem(
'${touchedSpot.y.toString()}\n${getLongDate(touchedSpot.x)}',
TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.bold));
}).toList();
},
),
),
),
);
}
@@ -85,4 +98,18 @@ class ReadingGraph extends StatelessWidget {
return hmFormat.format(
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt()));
}
String getLongDate(double value) {
DateTime date =
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt());
int daysDifference = (DateTime.now().weekday - date.weekday + 7) % 7;
if (daysDifference == 0) {
return 'Today ${intl.DateFormat('Hm').format(date)}';
} else if (daysDifference == 1) {
return 'Yesterday ${intl.DateFormat('Hm').format(date)}';
}
return intl.DateFormat('yyyy-MM-dd H:m').format(date);
}
}