Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_design.dart';
5 : import 'package:app_finance/_classes/herald/app_locale.dart';
6 : import 'package:app_finance/_classes/storage/app_data.dart';
7 : import 'package:app_finance/_classes/structure/account_app_data.dart';
8 : import 'package:app_finance/_configs/theme_helper.dart';
9 : import 'package:app_finance/_ext/build_context_ext.dart';
10 : import 'package:app_finance/charts/gauge_linear_chart.dart';
11 : import 'package:app_finance/charts/interface/ohlc_data.dart';
12 : import 'package:app_finance/components/widgets/account_flow_chart.dart';
13 : import 'package:app_finance/design/wrapper/text_wrapper.dart';
14 : import 'package:material_ui/material_ui.dart';
15 : import 'package:provider/provider.dart';
16 :
17 : class AccountHealthChart extends AccountFlowChart {
18 2 : const AccountHealthChart({super.key});
19 :
20 0 : double getHealthData(List<OhlcData> data) {
21 : double health = 0;
22 0 : if (data.isNotEmpty && data.first.high > 0) {
23 0 : health = 100 * (data.last.close - data.first.high) / data.first.high;
24 : }
25 : return health;
26 : }
27 :
28 0 : @override
29 : Widget build(BuildContext context) {
30 0 : double indent = ThemeHelper.getIndent();
31 0 : return Consumer<AppData>(builder: (context, appState, _) {
32 0 : final accountList = appState.getList(AppDataType.accounts).cast<AccountAppData>();
33 0 : final data = getData(appState, accountList, getMin());
34 0 : return LayoutBuilder(builder: (context, constraints) {
35 0 : final width = constraints.maxWidth - indent * 2;
36 0 : return Column(
37 0 : crossAxisAlignment: AppDesign.getAlignment(),
38 0 : children: [
39 0 : TextWrapper(AppLocale.labels.incomeHealth, style: context.textTheme.bodyLarge),
40 0 : GaugeLinearChart(
41 0 : value: getHealthData(data),
42 : valueMin: 0,
43 : valueMax: 100,
44 : width: width,
45 : height: 20,
46 : ),
47 : ],
48 : );
49 : });
50 : });
51 : }
52 : }
|