Skip to content

Commit

Permalink
complete the points used for history rating
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Mar 3, 2024
1 parent 4dad865 commit 8099584
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions lib/src/view/user/perf_stats_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,33 @@ class _EloChartState extends State<_EloChart> {
@override
void initState() {
super.initState();
_allPoints = widget.value.points

// We need to fill in the missing days in the rating history

final List<UserRatingHistoryPoint> pointsHistoryRatingCompleted = [];
final pointsHistoryRating = widget.value.points;
final numberOfDays = pointsHistoryRating.last.date
.difference(pointsHistoryRating.first.date)
.inDays +
1;

int j = 0;
for (int i = 0; i < numberOfDays; i++) {
final currentDate = pointsHistoryRating.first.date.add(Duration(days: i));
if (pointsHistoryRating[j].date == currentDate) {
pointsHistoryRatingCompleted.add(pointsHistoryRating[j]);
j += 1;
} else {
pointsHistoryRatingCompleted.add(
UserRatingHistoryPoint(
date: currentDate,
elo: pointsHistoryRating[j - 1].elo,
),
);
}
}

_allPoints = pointsHistoryRatingCompleted
.map(
(element) => FlSpot(
element.date.millisecondsSinceEpoch.toDouble(),
Expand Down Expand Up @@ -753,6 +779,7 @@ class _EloChartState extends State<_EloChart> {
),
),
lineTouchData: LineTouchData(
touchSpotThreshold: double.infinity,
touchTooltipData: LineTouchTooltipData(
tooltipBgColor:
Theme.of(context).platform == TargetPlatform.iOS
Expand Down Expand Up @@ -788,19 +815,20 @@ class _EloChartState extends State<_EloChart> {
),
),
RangeSlider(
divisions:
(_allPoints.last.x - _allPoints.first.y) ~/ millisecondsInDay,
divisions: _allPoints.length - 1,
min: _allPoints.first.x,
max: _allPoints.last.x,
labels: RangeLabels(
_formatDateFromTimestamp(_startDate),
_formatDateFromTimestamp(_endDate),
),
onChanged: (value) {
setState(() {
_startDate = value.start;
_endDate = value.end;
});
if (value.end - value.start >= millisecondsInDay) {
setState(() {
_startDate = value.start;
_endDate = value.end;
});
}
},
values: RangeValues(
_startDate,
Expand Down

0 comments on commit 8099584

Please sign in to comment.