From bedd65e5b143516b4be3077c16ccc8d306b8318a Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 10 Oct 2023 14:05:53 +0200 Subject: [PATCH] Mucking around with interval duration --- lib/widgets/workouts/charts.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/widgets/workouts/charts.dart b/lib/widgets/workouts/charts.dart index c95dd60a5..b7a3f7ec3 100644 --- a/lib/widgets/workouts/charts.dart +++ b/lib/widgets/workouts/charts.dart @@ -18,6 +18,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:intl/intl.dart'; import 'package:wger/helpers/colors.dart'; @@ -40,8 +41,6 @@ class LogChartWidgetFl extends StatefulWidget { } class _LogChartWidgetFlState extends State { - final interval = 15 * Duration.millisecondsPerDay / 1000 / 60; - @override Widget build(BuildContext context) { return AspectRatio( @@ -61,6 +60,11 @@ class _LogChartWidgetFlState extends State { } LineChartData mainData() { + final dayDiff = DateTime.parse(widget._data['logs'].keys.last) + .difference(DateTime.parse(widget._data['logs'].keys.first)); + + final interval = dayDiff.inDays * 1.3 * Duration.millisecondsPerDay; + return LineChartData( gridData: FlGridData( show: true, @@ -92,7 +96,7 @@ class _LogChartWidgetFlState extends State { sideTitles: SideTitles( showTitles: true, getTitlesWidget: (value, meta) { - final DateTime date = DateTime.fromMillisecondsSinceEpoch(value.toInt() * 1000 * 60); + final DateTime date = DateTime.fromMillisecondsSinceEpoch(value.toInt()); return Text( DateFormat.yMd(Localizations.localeOf(context).languageCode).format(date), ); @@ -103,9 +107,9 @@ class _LogChartWidgetFlState extends State { leftTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - reservedSize: 50, + reservedSize: 70, getTitlesWidget: (value, meta) { - return Text(value.toString()); + return Text('$value ${AppLocalizations.of(context).kg}'); }, ), ), @@ -120,7 +124,7 @@ class _LogChartWidgetFlState extends State { return LineChartBarData( spots: [ ...e.map((entry) => FlSpot( - DateTime.parse(entry['date']).millisecondsSinceEpoch / 1000 / 60, + DateTime.parse(entry['date']).millisecondsSinceEpoch.toDouble(), double.parse(entry['weight']), )) ],