2022-09-15 15:40:02 +00:00
|
|
|
part of '../server_details_screen.dart';
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
class _Chart extends StatelessWidget {
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
2022-11-12 17:29:06 +00:00
|
|
|
final MetricsCubit cubit = context.watch<MetricsCubit>();
|
2022-06-05 19:36:32 +00:00
|
|
|
final Period period = cubit.state.period;
|
2022-11-12 17:29:06 +00:00
|
|
|
final MetricsState state = cubit.state;
|
2021-04-10 03:04:23 +00:00
|
|
|
List<Widget> charts;
|
2022-11-12 17:29:06 +00:00
|
|
|
if (state is MetricsLoaded || state is MetricsLoading) {
|
2021-04-10 03:04:23 +00:00
|
|
|
charts = [
|
2022-09-15 16:57:26 +00:00
|
|
|
FilledCard(
|
2022-09-15 15:40:02 +00:00
|
|
|
clipped: false,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'resource_chart.cpu_title'.tr(),
|
2022-09-15 15:40:02 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2022-09-16 10:36:26 +00:00
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
2022-11-12 17:29:06 +00:00
|
|
|
if (state is MetricsLoaded) getCpuChart(state),
|
2022-09-16 10:36:26 +00:00
|
|
|
AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2022-11-12 17:29:06 +00:00
|
|
|
opacity: state is MetricsLoading ? 1 : 0,
|
2022-09-16 10:36:26 +00:00
|
|
|
child: const _GraphLoadingCardContent(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-15 15:40:02 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-16 09:44:15 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
FilledCard(
|
|
|
|
clipped: false,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'resource_chart.network_title'.tr(),
|
2022-09-16 09:44:15 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
Legend(
|
2022-09-16 10:36:26 +00:00
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2022-10-03 23:32:35 +00:00
|
|
|
text: 'resource_chart.in'.tr(),
|
2022-09-16 10:36:26 +00:00
|
|
|
),
|
2022-09-16 09:44:15 +00:00
|
|
|
const SizedBox(width: 5),
|
|
|
|
Legend(
|
2022-09-16 10:36:26 +00:00
|
|
|
color: Theme.of(context).colorScheme.tertiary,
|
2022-10-03 23:32:35 +00:00
|
|
|
text: 'resource_chart.out'.tr(),
|
2022-09-16 10:36:26 +00:00
|
|
|
),
|
2022-09-16 09:44:15 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
2022-09-16 10:36:26 +00:00
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
2022-11-12 17:29:06 +00:00
|
|
|
if (state is MetricsLoaded) getBandwidthChart(state),
|
2022-09-16 10:36:26 +00:00
|
|
|
AnimatedOpacity(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2022-11-12 17:29:06 +00:00
|
|
|
opacity: state is MetricsLoading ? 1 : 0,
|
2022-09-16 10:36:26 +00:00
|
|
|
child: const _GraphLoadingCardContent(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-16 09:44:15 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2021-04-10 03:04:23 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
throw 'wrong state';
|
|
|
|
}
|
|
|
|
|
2022-09-15 16:57:26 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
2022-09-15 21:59:37 +00:00
|
|
|
SegmentedButtons(
|
|
|
|
isSelected: [
|
|
|
|
period == Period.month,
|
|
|
|
period == Period.day,
|
|
|
|
period == Period.hour,
|
|
|
|
],
|
|
|
|
onPressed: (final index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
cubit.changePeriod(Period.month);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
cubit.changePeriod(Period.day);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cubit.changePeriod(Period.hour);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
titles: [
|
2022-10-03 23:32:35 +00:00
|
|
|
'resource_chart.month'.tr(),
|
|
|
|
'resource_chart.day'.tr(),
|
2023-11-06 13:15:38 +00:00
|
|
|
'resource_chart.hour'.tr(),
|
2022-09-15 21:59:37 +00:00
|
|
|
],
|
2022-09-15 16:57:26 +00:00
|
|
|
),
|
2022-09-16 09:44:15 +00:00
|
|
|
const SizedBox(height: 8),
|
2022-09-15 16:57:26 +00:00
|
|
|
...charts,
|
|
|
|
],
|
2021-04-10 03:04:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-12 17:29:06 +00:00
|
|
|
Widget getCpuChart(final MetricsLoaded state) {
|
|
|
|
final data = state.metrics.cpu;
|
2021-04-10 03:04:23 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
return SizedBox(
|
2021-04-10 03:04:23 +00:00
|
|
|
height: 200,
|
2022-05-25 12:21:56 +00:00
|
|
|
child: CpuChart(
|
|
|
|
data: data,
|
|
|
|
period: state.period,
|
2022-11-12 17:29:06 +00:00
|
|
|
start: state.metrics.start,
|
2022-05-25 12:21:56 +00:00
|
|
|
),
|
2021-04-10 03:04:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-12 17:29:06 +00:00
|
|
|
Widget getBandwidthChart(final MetricsLoaded state) {
|
|
|
|
final ppsIn = state.metrics.bandwidthIn;
|
|
|
|
final ppsOut = state.metrics.bandwidthOut;
|
2021-04-10 03:04:23 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
return SizedBox(
|
2021-04-10 03:04:23 +00:00
|
|
|
height: 200,
|
|
|
|
child: NetworkChart(
|
2022-05-25 12:21:56 +00:00
|
|
|
listData: [ppsIn, ppsOut],
|
|
|
|
period: state.period,
|
2022-11-12 17:29:06 +00:00
|
|
|
start: state.metrics.start,
|
2021-04-10 03:04:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:36:26 +00:00
|
|
|
class _GraphLoadingCardContent extends StatelessWidget {
|
|
|
|
const _GraphLoadingCardContent();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => const SizedBox(
|
|
|
|
height: 200,
|
|
|
|
child: Center(child: CircularProgressIndicator()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-10 03:04:23 +00:00
|
|
|
class Legend extends StatelessWidget {
|
|
|
|
const Legend({
|
|
|
|
required this.color,
|
|
|
|
required this.text,
|
2022-10-26 16:26:09 +00:00
|
|
|
super.key,
|
2022-06-05 22:40:34 +00:00
|
|
|
});
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
final String text;
|
|
|
|
final Color color;
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
_ColoredBox(color: color),
|
|
|
|
const SizedBox(width: 5),
|
2022-09-16 09:44:15 +00:00
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
);
|
2021-04-10 03:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _ColoredBox extends StatelessWidget {
|
|
|
|
const _ColoredBox({
|
|
|
|
required this.color,
|
2022-06-05 22:40:34 +00:00
|
|
|
});
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
final Color color;
|
|
|
|
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => Container(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
decoration: BoxDecoration(
|
2022-09-16 09:44:15 +00:00
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
color: color.withOpacity(0.4),
|
2021-04-10 03:04:23 +00:00
|
|
|
border: Border.all(
|
|
|
|
color: color,
|
2022-09-16 09:44:15 +00:00
|
|
|
width: 1.5,
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-04-10 03:04:23 +00:00
|
|
|
}
|