mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Refactor TotalEnergyConsumptionBloc
to use DividedTotalEnergyConsumptionDecorator
for adjusted energy values and update chart data handling in TotalEnergyConsumptionChart
.
This commit is contained in:
@ -62,7 +62,9 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => TotalEnergyConsumptionBloc(
|
||||
RemoteTotalEnergyConsumptionService(_httpService),
|
||||
DividedTotalEnergyConsumptionDecorator(
|
||||
RemoteTotalEnergyConsumptionService(_httpService),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
@ -145,6 +147,7 @@ class _AnalyticsPageFormState extends State<AnalyticsPageForm> {
|
||||
context.read<SpaceTreeBloc>().add(InitialEvent());
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WebScaffold(
|
||||
|
@ -9,22 +9,24 @@ class TotalEnergyConsumptionChart extends StatelessWidget {
|
||||
|
||||
final List<EnergyDataModel> chartData;
|
||||
|
||||
static const _leftTitlesInterval = 5.0;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
maxY: chartData.isEmpty
|
||||
? null
|
||||
: chartData.map((e) => e.value).reduce((a, b) => a > b ? a : b) + 250,
|
||||
maxY: chartData.isNotEmpty
|
||||
? chartData.map((e) => e.value).reduce((a, b) => a > b ? a : b) +
|
||||
_leftTitlesInterval
|
||||
: null,
|
||||
clipData: const FlClipData.vertical(),
|
||||
titlesData: EnergyManagementChartsHelper.titlesData(
|
||||
context,
|
||||
leftTitlesInterval: 500,
|
||||
leftTitlesInterval: _leftTitlesInterval,
|
||||
),
|
||||
gridData: EnergyManagementChartsHelper.gridData().copyWith(
|
||||
checkToShowHorizontalLine: (value) => true,
|
||||
horizontalInterval: 500,
|
||||
horizontalInterval: _leftTitlesInterval,
|
||||
),
|
||||
borderData: EnergyManagementChartsHelper.borderData(),
|
||||
lineTouchData: EnergyManagementChartsHelper.lineTouchData(),
|
||||
|
@ -59,3 +59,23 @@ abstract final class _TotalEnergyConsumptionResponseMapper {
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
class DividedTotalEnergyConsumptionDecorator
|
||||
implements TotalEnergyConsumptionService {
|
||||
const DividedTotalEnergyConsumptionDecorator(this._decoratee);
|
||||
|
||||
final TotalEnergyConsumptionService _decoratee;
|
||||
@override
|
||||
Future<List<EnergyDataModel>> load(
|
||||
GetTotalEnergyConsumptionParam param,
|
||||
) async {
|
||||
final result = await _decoratee.load(param);
|
||||
final dividedResult = result.map((e) {
|
||||
return EnergyDataModel(
|
||||
date: e.date,
|
||||
value: e.value / 100,
|
||||
);
|
||||
});
|
||||
return dividedResult.toList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user