feat(graphs): add pie chart and category colors #19

Merged
hernik merged 5 commits from dev-graph into dev 2024-01-08 15:38:32 +01:00
Showing only changes of commit 1ce1342644 - Show all commits

View file

@ -4,6 +4,8 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/walletentry.dart';
/// Monthly/Yearly expense/income [LineChart] /// Monthly/Yearly expense/income [LineChart]
class ExpensesLineChart extends StatelessWidget { class ExpensesLineChart extends StatelessWidget {
@ -295,3 +297,30 @@ class ExpensesBarChart extends StatelessWidget {
), ),
); );
} }
class CategoriesPieChart extends StatelessWidget {
const CategoriesPieChart(
{super.key, required this.entries, required this.categories});
final List<WalletSingleEntry> entries;
final List<WalletCategory> categories;
@override
Widget build(BuildContext context) => PieChart(
PieChartData(
sections: List<PieChartSectionData>.generate(
categories.length,
(index) => PieChartSectionData(
value: entries
.where(
(element) => element.category.id == categories[index].id)
.fold<double>(
0,
(previousValue, element) =>
previousValue + element.data.amount,
),
),
),
),
);
}