From 9e4c0378c6723f97a8518e688ddf6a2796740f34 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Thu, 24 Jul 2025 15:56:17 +0530 Subject: [PATCH] feat: Enhance attendance dashboard by filtering roles with data and improving chart series mapping --- lib/view/dashboard/dashboard_chart.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/view/dashboard/dashboard_chart.dart b/lib/view/dashboard/dashboard_chart.dart index 5741fd5..eaba8cc 100644 --- a/lib/view/dashboard/dashboard_chart.dart +++ b/lib/view/dashboard/dashboard_chart.dart @@ -36,6 +36,11 @@ class AttendanceDashboardChart extends StatelessWidget { List get filteredRoles => filteredData.map((e) => e['role'] as String).toSet().toList(); + List get rolesWithData => filteredRoles.where((role) { + return filteredData.any( + (entry) => entry['role'] == role && (entry['present'] ?? 0) > 0); + }).toList(); + final Map _roleColorMap = {}; final List flatColors = [ const Color(0xFFE57373), @@ -52,7 +57,6 @@ class AttendanceDashboardChart extends StatelessWidget { Color _getRoleColor(String role) { if (_roleColorMap.containsKey(role)) return _roleColorMap[role]!; - final index = _roleColorMap.length % flatColors.length; final color = flatColors[index]; _roleColorMap[role] = color; @@ -62,7 +66,6 @@ class AttendanceDashboardChart extends StatelessWidget { @override Widget build(BuildContext context) { return Obx(() { - // Now this observes `controller.roleWiseData`, `isLoading`, `isChartView`, etc. final isChartView = controller.isChartView.value; final selectedRange = controller.selectedRange.value; final isLoading = controller.isLoading.value; @@ -78,8 +81,7 @@ class AttendanceDashboardChart extends StatelessWidget { child: Card( color: Colors.white, elevation: 6, - shape: - RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), shadowColor: Colors.black12, child: Padding( padding: const EdgeInsets.all(10), @@ -116,10 +118,7 @@ class AttendanceDashboardChart extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ MyText.bodyMedium('Attendance Overview', fontWeight: 600), - MyText.bodySmall( - 'Role-wise present count', - color: Colors.grey, - ), + MyText.bodySmall('Role-wise present count', color: Colors.grey), ], ), ), @@ -213,7 +212,7 @@ class AttendanceDashboardChart extends StatelessWidget { interval: 1, majorGridLines: const MajorGridLines(width: 0), ), - series: filteredRoles.map((role) { + series: rolesWithData.map((role) { final data = filteredDates.map((formattedDate) { final key = '${role}_$formattedDate'; return {