2024-08-06 19:04:34 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-01-31 05:14:23 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-12-12 14:04:01 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/server_details/charts/generic_chart.dart';
|
2022-09-15 15:40:02 +00:00
|
|
|
|
2024-12-12 14:04:01 +00:00
|
|
|
class CpuChart extends GenericLineChart {
|
2022-09-15 15:40:02 +00:00
|
|
|
const CpuChart({
|
2024-12-12 14:04:01 +00:00
|
|
|
required super.data,
|
|
|
|
required super.period,
|
|
|
|
required super.start,
|
2022-10-26 16:26:09 +00:00
|
|
|
super.key,
|
2022-09-15 15:40:02 +00:00
|
|
|
});
|
|
|
|
|
2024-12-12 14:04:01 +00:00
|
|
|
@override
|
2024-08-06 19:04:34 +00:00
|
|
|
String screenReaderDescription(final BuildContext context) {
|
2024-12-12 14:04:01 +00:00
|
|
|
final lastData = data.first.last;
|
2024-08-06 19:04:34 +00:00
|
|
|
final lastValue = lastData.value;
|
|
|
|
|
2024-12-12 14:04:01 +00:00
|
|
|
final averageUsage = data.first
|
|
|
|
.map((final e) => e.value)
|
|
|
|
.reduce((final a, final b) => a + b) /
|
|
|
|
data.length;
|
|
|
|
final maxUsage = data.first
|
2024-08-06 19:04:34 +00:00
|
|
|
.map((final e) => e.value)
|
|
|
|
.reduce((final a, final b) => a > b ? a : b);
|
2024-12-12 14:04:01 +00:00
|
|
|
final maxUsageTime =
|
|
|
|
data.first.firstWhere((final e) => e.value == maxUsage).time;
|
2024-08-06 19:04:34 +00:00
|
|
|
|
|
|
|
final label = 'resource_chart.cpu_chart_screen_reader_explanation'.tr(
|
|
|
|
namedArgs: {
|
|
|
|
'period': 'resource_chart.${period.name}'.tr(),
|
|
|
|
'lastValue': lastValue.toStringAsFixed(1),
|
|
|
|
'averageUsage': averageUsage.toStringAsFixed(1),
|
|
|
|
'maxUsage': maxUsage.toStringAsFixed(1),
|
|
|
|
'maxUsageTime': DateFormat('HH:mm dd MMMM', context.locale.languageCode)
|
|
|
|
.format(maxUsageTime),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
2022-09-15 15:40:02 +00:00
|
|
|
}
|